diff --git a/SConstruct b/SConstruct index ca458d1b1..988125fc2 100644 --- a/SConstruct +++ b/SConstruct @@ -352,11 +352,11 @@ ns3.add(sample_sp2p) sample_sp2p.add_deps(['core', 'simulator', 'node', 'p2p']) sample_sp2p.add_source('main-simple-p2p.cc') -sample_simple_tcl = build.Ns3Module('sample-simple.tcl', 'samples') -sample_simple_tcl.set_executable() -ns3.add(sample_simple_tcl) -sample_simple_tcl.add_deps(['core', 'simulator', 'node', 'serial']) -sample_simple_tcl.add_source('ns-2/simple.tcl.cc') +sample_ns2_simple = build.Ns3Module('sample-ns2-simple', 'samples') +sample_ns2_simple.set_executable() +ns3.add(sample_ns2_simple) +sample_ns2_simple.add_deps(['core', 'simulator', 'node', 'serial']) +sample_ns2_simple.add_source('ns-2/simple.cc') sample_channel = build.Ns3Module('sample-channel', 'samples') sample_channel.set_executable() diff --git a/samples/ns-2/simple.tcl.cc b/samples/ns-2/simple.cc similarity index 79% rename from samples/ns-2/simple.tcl.cc rename to samples/ns-2/simple.cc index e6c691f77..003dc698f 100644 --- a/samples/ns-2/simple.tcl.cc +++ b/samples/ns-2/simple.cc @@ -18,8 +18,23 @@ */ // Port of ns-2/tcl/ex/simple.tcl to ns-3 -// Corresponding ns-2 otcl commands are commented out above the -// replacement ns-3 code, to highlight the change in design +// +// Network topology +// +// n0 +// \ 5 Mb/s, 2ms +// \ 1.5Mb/s, 10ms +// n2 -------------------------n3 +// / +// / 5 Mb/s, 2ms +// n1 +// +// - all links are serial links with indicated one-way BW/delay +// - CBR/UDP flows from n0 to n3, and from n3 to n1 +// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. +// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. +// - DropTail queues +// - Tracing of queues and packet receptions to file out.tr #include #include @@ -261,14 +276,6 @@ SetupTrace (TraceContainer &container, Tracer &tracer) int main (int argc, char *argv[]) { - // 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] - // ** Here, some kind of factory or topology object will instantiates // ** four identical nodes; for now, we just explicitly create them InternetNode *n0 = new InternetNode(); @@ -283,18 +290,8 @@ int main (int argc, char *argv[]) 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"); - // $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"; @@ -318,95 +315,28 @@ int main (int argc, char *argv[]) traceContainer, channelName); 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); - - // 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 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); + source0->SetDefaultDestination (Ipv4Address ("10.1.3.2"), 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); - //PrintRoutingTable (n0, "n0"); - //PrintRoutingTable (n1, "n1"); - //PrintRoutingTable (n2, "n2"); - //PrintRoutingTable (n3, "n3"); - - // $ns at 1.0 "$cbr0 start" - // $ns at 1.1 "$cbr1 start" - - PrintTraffic (sink3); GenerateTraffic (source0, 100); PrintTraffic (sink1); GenerateTraffic (source3, 100); - // - // 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