43 #include <cassert> |
43 #include <cassert> |
44 |
44 |
45 #include "ns3/core-module.h" |
45 #include "ns3/core-module.h" |
46 #include "ns3/simulator-module.h" |
46 #include "ns3/simulator-module.h" |
47 #include "ns3/helper-module.h" |
47 #include "ns3/helper-module.h" |
48 #include "ns3/ascii-trace.h" |
|
49 #include "ns3/pcap-trace.h" |
|
50 #include "ns3/global-route-manager.h" |
48 #include "ns3/global-route-manager.h" |
51 |
49 |
52 using namespace ns3; |
50 using namespace ns3; |
53 |
51 |
54 NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample"); |
52 NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample"); |
93 // Allow the user to override any of the defaults and the above |
91 // Allow the user to override any of the defaults and the above |
94 // DefaultValue::Bind ()s at run-time, via command-line arguments |
92 // DefaultValue::Bind ()s at run-time, via command-line arguments |
95 CommandLine cmd; |
93 CommandLine cmd; |
96 cmd.Parse (argc, argv); |
94 cmd.Parse (argc, argv); |
97 |
95 |
|
96 std::ofstream ascii; |
|
97 ascii.open ("simple-global-routing.tr"); |
|
98 |
98 // Here, we will explicitly create four nodes. In more sophisticated |
99 // Here, we will explicitly create four nodes. In more sophisticated |
99 // topologies, we could configure a node factory. |
100 // topologies, we could configure a node factory. |
100 NS_LOG_INFO ("Create nodes."); |
101 NS_LOG_INFO ("Create nodes."); |
101 NodeContainer c; |
102 NodeContainer c; |
102 c.Create (4); |
103 c.Create (4); |
108 internet.Build (c); |
109 internet.Build (c); |
109 |
110 |
110 // We create the channels first without any IP addressing information |
111 // We create the channels first without any IP addressing information |
111 NS_LOG_INFO ("Create channels."); |
112 NS_LOG_INFO ("Create channels."); |
112 PointToPointHelper p2p; |
113 PointToPointHelper p2p; |
|
114 p2p.EnablePcap ("simple-global-routing.pcap"); |
|
115 p2p.EnableAscii (ascii); |
113 p2p.SetChannelParameter ("BitRate", DataRate (5000000)); |
116 p2p.SetChannelParameter ("BitRate", DataRate (5000000)); |
114 p2p.SetChannelParameter ("Delay", MilliSeconds (2)); |
117 p2p.SetChannelParameter ("Delay", MilliSeconds (2)); |
115 NetDeviceContainer d0d2 = p2p.Build (n0n2); |
118 NetDeviceContainer d0d2 = p2p.Build (n0n2); |
116 |
119 |
117 NetDeviceContainer d1d2 = p2p.Build (n1n2); |
120 NetDeviceContainer d1d2 = p2p.Build (n1n2); |
165 // Create a packet sink to receive these packets |
168 // Create a packet sink to receive these packets |
166 apps = sink.Build (c.Get (1)); |
169 apps = sink.Build (c.Get (1)); |
167 apps.Start (Seconds (1.1)); |
170 apps.Start (Seconds (1.1)); |
168 apps.Stop (Seconds (10.0)); |
171 apps.Stop (Seconds (10.0)); |
169 |
172 |
170 // Configure tracing of all enqueue, dequeue, and NetDevice receive events |
|
171 // Trace output will be sent to the simple-global-routing.tr file |
|
172 NS_LOG_INFO ("Configure Tracing."); |
|
173 AsciiTrace asciitrace ("simple-global-routing.tr"); |
|
174 asciitrace.TraceAllQueues (); |
|
175 asciitrace.TraceAllNetDeviceRx (); |
|
176 |
|
177 // Also configure some tcpdump traces; each interface will be traced |
|
178 // The output files will be named simple-p2p.pcap-<nodeId>-<interfaceId> |
|
179 // and can be read by the "tcpdump -r" command (use "-tt" option to |
|
180 // display timestamps correctly) |
|
181 PcapTrace pcaptrace ("simple-global-routing.pcap"); |
|
182 pcaptrace.TraceAllIp (); |
|
183 |
173 |
184 NS_LOG_INFO ("Run Simulation."); |
174 NS_LOG_INFO ("Run Simulation."); |
185 Simulator::Run (); |
175 Simulator::Run (); |
186 Simulator::Destroy (); |
176 Simulator::Destroy (); |
187 NS_LOG_INFO ("Done."); |
177 NS_LOG_INFO ("Done."); |