From 62ff2e87b3dc74974fbe4de1c6f2dab58c69574f Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 21 Feb 2007 17:58:14 +0100 Subject: [PATCH] fix coding style --- samples/ns-2/simple.tcl.cc | 344 +++++++++++++++++++------------------ 1 file changed, 174 insertions(+), 170 deletions(-) diff --git a/samples/ns-2/simple.tcl.cc b/samples/ns-2/simple.tcl.cc index 33a20d52e..f92259e63 100644 --- a/samples/ns-2/simple.tcl.cc +++ b/samples/ns-2/simple.tcl.cc @@ -80,7 +80,9 @@ protected: static void GenerateTraffic (UdpSocket *socket, uint32_t size) { - std::cout << "Node: " << socket->GetNode()->GetId () << " at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl; + std::cout << "Node: " << socket->GetNode()->GetId () + << " at=" << Simulator::Now ().GetSeconds () << "s," + << " tx bytes=" << size << std::endl; socket->SendDummy (size); if (size > 50) { @@ -91,7 +93,9 @@ GenerateTraffic (UdpSocket *socket, uint32_t size) static void UdpSocketPrinter (UdpSocket *socket, uint32_t size, Ipv4Address from, uint16_t fromPort) { - std::cout << "Node: " << socket->GetNode()->GetId () << " at=" << Simulator::Now ().GetSeconds () << "s, rx bytes=" << size << std::endl; + std::cout << "Node: " << socket->GetNode()->GetId () + << " at=" << Simulator::Now ().GetSeconds () << "s," + << " rx bytes=" << size << std::endl; } static void @@ -138,49 +142,49 @@ AddDuplexLink( TraceContainer &traceContainer, std::string &name) { - std::string qName; - SerialChannel* channel = new SerialChannel(); + std::string qName; + SerialChannel* channel = new SerialChannel(); - qName = name + "::Queue A"; - DropTailQueue* dtqa = new DropTailQueue(qName); - dtqa->RegisterTraces (traceContainer); + qName = name + "::Queue A"; + DropTailQueue* dtqa = new DropTailQueue(qName); + dtqa->RegisterTraces (traceContainer); - SerialNetDevice* neta = new SerialNetDevice(a, macaddra); - neta->AddQueue(dtqa); - Ipv4Interface *interfA = new ArpIpv4Interface (a, neta); - uint32_t indexA = a->GetIpv4 ()->AddInterface (interfA); - channel->Attach (neta); - neta->Attach (channel); + SerialNetDevice* neta = new SerialNetDevice(a, macaddra); + neta->AddQueue(dtqa); + Ipv4Interface *interfA = new ArpIpv4Interface (a, neta); + uint32_t indexA = a->GetIpv4 ()->AddInterface (interfA); + channel->Attach (neta); + neta->Attach (channel); + + interfA->SetAddress (addra); + interfA->SetNetworkMask (netmask); + interfA->SetUp (); - interfA->SetAddress (addra); - interfA->SetNetworkMask (netmask); - interfA->SetUp (); + qName = name + "::Queue B"; + DropTailQueue* dtqb = new DropTailQueue(qName); + dtqb->RegisterTraces (traceContainer); - qName = name + "::Queue B"; - DropTailQueue* dtqb = new DropTailQueue(qName); - dtqb->RegisterTraces (traceContainer); + SerialNetDevice* netb = new SerialNetDevice(b, macaddrb); + netb->AddQueue(dtqb); + Ipv4Interface *interfB = new ArpIpv4Interface (b, netb); + uint32_t indexB = b->GetIpv4 ()->AddInterface (interfB); + channel->Attach (netb); + netb->Attach (channel); - SerialNetDevice* netb = new SerialNetDevice(b, macaddrb); - netb->AddQueue(dtqb); - Ipv4Interface *interfB = new ArpIpv4Interface (b, netb); - uint32_t indexB = b->GetIpv4 ()->AddInterface (interfB); - channel->Attach (netb); - netb->Attach (channel); + interfB->SetAddress (addrb); + interfB->SetNetworkMask (netmask); + interfB->SetUp (); - interfB->SetAddress (addrb); - interfB->SetNetworkMask (netmask); - interfB->SetUp (); + a->GetIpv4 ()->AddHostRouteTo (addrb, indexA); + b->GetIpv4 ()->AddHostRouteTo (addra, indexB); - a->GetIpv4 ()->AddHostRouteTo (addrb, indexA); - b->GetIpv4 ()->AddHostRouteTo (addra, indexB); + NS_DEBUG_UNCOND("Adding interface " << indexA << " to node " << a->GetId()); + NS_DEBUG_UNCOND("Adding interface " << indexB << " to node " << b->GetId()); - NS_DEBUG_UNCOND("Adding interface " << indexA << " to node " << a->GetId()) - NS_DEBUG_UNCOND("Adding interface " << indexB << " to node " << b->GetId()) + //PrintRoutingTable (a, "a"); + //PrintRoutingTable (b, "b"); - //PrintRoutingTable (a, "a"); - //PrintRoutingTable (b, "b"); - - return channel; + return channel; } static void @@ -199,170 +203,170 @@ SetupTrace (TraceContainer &container, Tracer &tracer) int main (int argc, char *argv[]) { - // set ns [new Simulator] - // ** not needed, Simulator is static object + // set ns [new Simulator] + // ** not needed, Simulator is static object - // set n0 [$ns node] - // set n1 [$ns node] - // set n2 [$ns node] - // set n3 [$ns node] + // set n0 [$ns node] + // set n1 [$ns node] + // set n2 [$ns node] + // set n3 [$ns node] - // ** Here, some kind of factory or topology object will instantiates - // ** four identical nodes; for now, we just explicitly create them - InternetNode *n0 = new InternetNode(); - InternetNode *n1 = new InternetNode(); - InternetNode *n2 = new InternetNode(); - InternetNode *n3 = new InternetNode(); + // ** Here, some kind of factory or topology object will instantiates + // ** four identical nodes; for now, we just explicitly create them + InternetNode *n0 = new InternetNode(); + InternetNode *n1 = new InternetNode(); + InternetNode *n2 = new InternetNode(); + InternetNode *n3 = new InternetNode(); - TraceContainer traceContainer; + TraceContainer traceContainer; - n0->SetName(std::string("Node 0")); - n1->SetName(std::string("Node 1")); - n2->SetName(std::string("Node 2")); - n3->SetName(std::string("Node 3")); - - // set f [open out.tr w] - // $ns trace-all $f - // set nf [open out.nam w] - // $ns namtrace-all $nf - // ** tracing configuration occurs later ** + n0->SetName(std::string("Node 0")); + n1->SetName(std::string("Node 1")); + n2->SetName(std::string("Node 2")); + n3->SetName(std::string("Node 3")); + + // set f [open out.tr w] + // $ns trace-all $f + // set nf [open out.nam w] + // $ns namtrace-all $nf + // ** tracing configuration occurs later ** - Tracer tracer("serial-net-test.log"); + Tracer tracer("serial-net-test.log"); - // $ns duplex-link $n0 $n2 5Mb 2ms DropTail - // $ns duplex-link $n1 $n2 5Mb 2ms DropTail - // $ns duplex-link $n2 $n3 1.5Mb 10ms DropTail - // ** part of topology creation object? ** - std::string channelName; - - channelName = "Channel 1"; - SerialChannel* ch1 = AddDuplexLink ( + // $ns duplex-link $n0 $n2 5Mb 2ms DropTail + // $ns duplex-link $n1 $n2 5Mb 2ms DropTail + // $ns duplex-link $n2 $n3 1.5Mb 10ms DropTail + // ** part of topology creation object? ** + std::string channelName; + + channelName = "Channel 1"; + SerialChannel* ch1 = AddDuplexLink ( n0, Ipv4Address("10.1.1.1"), MacAddress("00:00:00:00:00:01"), n2, Ipv4Address("10.1.1.2"), MacAddress("00:00:00:00:00:02"), Ipv4Mask("255.255.255.0"), traceContainer, channelName); - SetupTrace (traceContainer, tracer); + SetupTrace (traceContainer, tracer); - channelName = "Channel 2"; - SerialChannel* ch2 = AddDuplexLink ( + channelName = "Channel 2"; + SerialChannel* ch2 = AddDuplexLink ( n1, Ipv4Address("10.1.2.1"), MacAddress("00:00:00:00:00:03"), n2, Ipv4Address("10.1.2.2"), MacAddress("00:00:00:00:00:04"), Ipv4Mask("255.255.255.0"), traceContainer, channelName); - SetupTrace (traceContainer, tracer); + SetupTrace (traceContainer, tracer); - channelName = "Channel 3"; - SerialChannel* ch3 = AddDuplexLink ( + channelName = "Channel 3"; + SerialChannel* ch3 = AddDuplexLink ( n2, Ipv4Address("10.1.3.1"), MacAddress("00:00:00:00:00:05"), n3, Ipv4Address("10.1.3.2"), MacAddress("00:00:00:00:00:06"), Ipv4Mask("255.255.255.0"), traceContainer, channelName); - SetupTrace (traceContainer, tracer); + SetupTrace (traceContainer, tracer); + + // $ns duplex-link-op $n0 $n2 orient right-up + // $ns duplex-link-op $n1 $n2 orient right-down + // $ns duplex-link-op $n2 $n3 orient right + // $ns duplex-link-op $n2 $n3 queuePos 0.5 + // ** nam commands-- not supported ** + + // set udp0 [new Agent/UDP] + // $ns attach-agent $n0 $udp0 + UdpSocket *source0 = new UdpSocket (n0); - // $ns duplex-link-op $n0 $n2 orient right-up - // $ns duplex-link-op $n1 $n2 orient right-down - // $ns duplex-link-op $n2 $n3 orient right - // $ns duplex-link-op $n2 $n3 queuePos 0.5 - // ** nam commands-- not supported ** + // set cbr0 [new Application/Traffic/CBR] + // $cbr0 attach-agent $udp0 + + // set udp1 [new Agent/UDP] + // $ns attach-agent $n3 $udp1 + UdpSocket *source3 = new UdpSocket (n3); - // set udp0 [new Agent/UDP] - // $ns attach-agent $n0 $udp0 - UdpSocket *source0 = new UdpSocket (n0); + // $udp1 set class_ 1 + // ** class_ is for nam ** - // set cbr0 [new Application/Traffic/CBR] - // $cbr0 attach-agent $udp0 - - // set udp1 [new Agent/UDP] - // $ns attach-agent $n3 $udp1 - UdpSocket *source3 = new UdpSocket (n3); - - // $udp1 set class_ 1 - // ** class_ is for nam ** - - // set cbr1 [new Application/Traffic/CBR] - // $cbr1 attach-agent $udp1 - // - // set null0 [new Agent/Null] - // $ns attach-agent $n3 $null0 - UdpSocket *sink3 = new UdpSocket(n3); - sink3->Bind (80); + // set cbr1 [new Application/Traffic/CBR] + // $cbr1 attach-agent $udp1 + // + // set null0 [new Agent/Null] + // $ns attach-agent $n3 $null0 + UdpSocket *sink3 = new UdpSocket(n3); + sink3->Bind (80); - // set null1 [new Agent/Null] - // $ns attach-agent $n1 $null1 - UdpSocket *sink1 = new UdpSocket(n1); - sink1->Bind (80); + // set null1 [new Agent/Null] + // $ns attach-agent $n1 $null1 + UdpSocket *sink1 = new UdpSocket(n1); + sink1->Bind (80); - // $ns connect $udp0 $null0 - source0->SetDefaultDestination (Ipv4Address ("10.1.3.2"), 80); - // $ns connect $udp1 $null1 - source3->SetDefaultDestination (Ipv4Address ("10.1.2.1"), 80); + // $ns connect $udp0 $null0 + source0->SetDefaultDestination (Ipv4Address ("10.1.3.2"), 80); + // $ns connect $udp1 $null1 + source3->SetDefaultDestination (Ipv4Address ("10.1.2.1"), 80); - // Here, finish off packet routing configuration - n0->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); - n3->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); + // Here, finish off packet routing configuration + n0->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); + n3->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); - //PrintRoutingTable (n0, "n0"); - //PrintRoutingTable (n1, "n1"); - //PrintRoutingTable (n2, "n2"); - //PrintRoutingTable (n3, "n3"); - - // $ns at 1.0 "$cbr0 start" - // $ns at 1.1 "$cbr1 start" + //PrintRoutingTable (n0, "n0"); + //PrintRoutingTable (n1, "n1"); + //PrintRoutingTable (n2, "n2"); + //PrintRoutingTable (n3, "n3"); + + // $ns at 1.0 "$cbr0 start" + // $ns at 1.1 "$cbr1 start" - GenerateTraffic (source0, 100); - PrintTraffic (sink3); + GenerateTraffic (source0, 100); + PrintTraffic (sink3); - GenerateTraffic (source3, 100); - PrintTraffic (sink1); - // - // set tcp [new Agent/TCP] - // $tcp set class_ 2 - // set sink [new Agent/TCPSink] - // $ns attach-agent $n0 $tcp - // $ns attach-agent $n3 $sink - // $ns connect $tcp $sink - // set ftp [new Application/FTP] - // $ftp attach-agent $tcp - // $ns at 1.2 "$ftp start" - // - // $ns at 1.35 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink" - // ** TCP may not be in this snapshot ** - // - // puts [$cbr0 set packetSize_] - // puts [$cbr0 set interval_] - // - // $ns at 3.0 "finish" - Simulator::StopAt (Seconds(3.0)); - // - // proc finish {} { - // global ns f nf - // $ns flush-trace - // close $f - // close $nf - // - // puts "running nam..." - // exec nam out.nam & - // exit 0 - // } - // ** this finish proc not needed? ** - // - // $ns run - Simulator::Run (); + GenerateTraffic (source3, 100); + PrintTraffic (sink1); + // + // set tcp [new Agent/TCP] + // $tcp set class_ 2 + // set sink [new Agent/TCPSink] + // $ns attach-agent $n0 $tcp + // $ns attach-agent $n3 $sink + // $ns connect $tcp $sink + // set ftp [new Application/FTP] + // $ftp attach-agent $tcp + // $ns at 1.2 "$ftp start" + // + // $ns at 1.35 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink" + // ** TCP may not be in this snapshot ** + // + // puts [$cbr0 set packetSize_] + // puts [$cbr0 set interval_] + // + // $ns at 3.0 "finish" + Simulator::StopAt (Seconds(3.0)); + // + // proc finish {} { + // global ns f nf + // $ns flush-trace + // close $f + // close $nf + // + // puts "running nam..." + // exec nam out.nam & + // exit 0 + // } + // ** this finish proc not needed? ** + // + // $ns run + Simulator::Run (); - // The below deletes will be managed by future topology objects - // or containers or smart pointers - delete n0; - delete n1; - delete n2; - delete n3; - delete ch1; - delete ch2; - delete ch3; - delete source3; - delete source0; - delete sink3; - delete sink1; + // The below deletes will be managed by future topology objects + // or containers or smart pointers + delete n0; + delete n1; + delete n2; + delete n3; + delete ch1; + delete ch2; + delete ch3; + delete source3; + delete source0; + delete sink3; + delete sink1; - Simulator::Destroy (); + Simulator::Destroy (); }