42 #include "ns3/core-module.h" 43 #include "ns3/internet-module.h" 44 #include "ns3/network-module.h" 45 #include "ns3/on-off-helper.h" 46 #include "ns3/packet-sink-helper.h" 47 #include "ns3/point-to-point-helper.h" 48 #include "ns3/mpi-interface.h" 49 #include "ns3/ipv4-nix-vector-helper.h" 54 #define TIMER_NOW(_t) gettimeofday (&_t,NULL); 55 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec * 1e-6) 56 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1) - TIMER_SECONDS (_t2)) 61 main (
int argc,
char *argv[])
63 typedef std::vector<NodeContainer> vectorOfNodeContainer;
64 typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
65 typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
67 typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
68 typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
69 typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
71 typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
72 typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
79 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
87 uint32_t nCN = 2, nLANClients = 42;
93 cmd.AddValue (
"CN",
"Number of total CNs [2]", nCN);
94 cmd.AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
95 cmd.AddValue (
"single",
"1 if use single flow", single);
96 cmd.AddValue (
"nBytes",
"Number of bytes for each on/off app", nBytes);
97 cmd.AddValue (
"nix",
"Toggle the use of nix-vector or global routing", nix);
98 cmd.Parse (argc,argv);
102 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2" 106 if (systemCount > nCN)
108 std::cout <<
"Number of total CNs (" << nCN <<
") should be >= systemCount (" 109 << systemCount <<
")." << std::endl;
113 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
117 vectorOfNodeContainer nodes_netLR(nCN);
118 vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
119 vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
120 vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
121 vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
123 vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
124 vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
131 vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
132 vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
133 vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
134 vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
135 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
136 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
139 std::ostringstream oss;
150 stack.SetRoutingHelper (nixRouting);
154 for (uint32_t z = 0; z < nCN; ++z)
156 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
158 std::cout <<
" SubNet [ 0";
159 for (
int i = 0; i < 3; ++i)
161 Ptr<Node> node = CreateObject<Node> (z % systemCount);
162 nodes_net0[z][i].Add (node);
163 stack.Install (nodes_net0[z][i]);
165 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
166 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
167 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
169 for (
int i = 0; i < 3; ++i)
171 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
175 for (
int i = 0; i < 6; ++i)
177 Ptr<Node> node = CreateObject<Node> (z % systemCount);
178 nodes_net1[z][i].Add (node);
179 stack.Install (nodes_net1[z][i]);
181 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
182 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
183 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
184 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
185 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
187 for (
int i = 0; i < 6; ++i)
193 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
197 net0_1.
Add (nodes_net0[z][2].Get (0));
198 net0_1.
Add (nodes_net1[z][0].Get (0));
200 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
202 oss << 10 + z <<
".1.252.0";
203 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
207 for (
int i = 0; i < 14; ++i)
209 Ptr<Node> node = CreateObject<Node> (z % systemCount);
210 nodes_net2[z][i].Add (node);
211 stack.Install (nodes_net2[z][i]);
213 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
214 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
215 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
216 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
217 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
218 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
219 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
220 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
221 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
222 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
223 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
224 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
225 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
226 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
228 for (
int i = 0; i < 14; ++i)
230 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
232 vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
233 for (
int i = 0; i < 7; ++i)
236 oss << 10 + z <<
".4." << 15 + i <<
".0";
237 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
238 for (uint32_t j = 0; j < nLANClients; ++j)
240 Ptr<Node> node = CreateObject<Node> (z % systemCount);
241 nodes_net2LAN[z][i][j].Add (node);
242 stack.Install (nodes_net2LAN[z][i][j]);
243 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
244 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
245 ifs2LAN[z][i][j] =
address.Assign (ndc2LAN[i][j]);
249 std::cout <<
" 3 ]" << std::endl;
250 for (
int i = 0; i < 9; ++i)
252 Ptr<Node> node = CreateObject<Node> (z % systemCount);
253 nodes_net3[z][i].Add (node);
254 stack.Install (nodes_net3[z][i]);
256 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
257 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
258 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
259 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
260 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
261 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
262 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
263 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
264 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
266 for (
int i = 0; i < 9; ++i)
268 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
270 vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
271 for (
int i = 0; i < 5; ++i)
274 oss << 10 + z <<
".5." << 10 + i <<
".0";
275 address.SetBase (oss.str ().c_str (),
"255.255.255.255");
276 for (uint32_t j = 0; j < nLANClients; ++j)
278 Ptr<Node> node = CreateObject<Node> (z % systemCount);
279 nodes_net3LAN[z][i][j].Add (node);
280 stack.Install (nodes_net3LAN[z][i][j]);
281 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
282 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
283 ifs3LAN[z][i][j] =
address.Assign (ndc3LAN[i][j]);
286 std::cout <<
" Connecting Subnets..." << std::endl;
288 Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
289 Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
290 nodes_netLR[z].Add (node1);
291 nodes_netLR[z].Add (node2);
292 stack.Install (nodes_netLR[z]);
294 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
296 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
297 net0_4.
Add (nodes_netLR[z].Get (0));
298 net0_4.
Add (nodes_net0[z][0].Get (0));
299 net0_5.
Add (nodes_netLR[z].Get (1));
300 net0_5.
Add (nodes_net0[z][1].Get (0));
301 net2_4a.
Add (nodes_netLR[z].Get (0));
302 net2_4a.
Add (nodes_net2[z][0].Get (0));
303 net2_4b.
Add (nodes_netLR[z].Get (1));
304 net2_4b.
Add (nodes_net2[z][1].Get (0));
305 net3_5a.
Add (nodes_netLR[z].Get (1));
306 net3_5a.
Add (nodes_net3[z][0].Get (0));
307 net3_5b.
Add (nodes_netLR[z].Get (1));
308 net3_5b.
Add (nodes_net3[z][1].Get (0));
310 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
312 oss << 10 + z <<
".1.253.0";
313 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
315 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
317 oss << 10 + z <<
".1.254.0";
318 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
320 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
322 oss << 10 + z <<
".4.253.0";
323 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
324 ifs =
address.Assign (ndc2_4a);
325 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
327 oss << 10 + z <<
".4.254.0";
328 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
329 ifs =
address.Assign (ndc2_4b);
330 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
332 oss << 10 + z <<
".5.253.0";
333 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
334 ifs =
address.Assign (ndc3_5a);
335 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
337 oss << 10 + z <<
".5.254.0";
338 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
339 ifs =
address.Assign (ndc3_5b);
341 std::cout <<
" Assigning IP addresses..." << std::endl;
342 for (
int i = 0; i < 3; ++i)
345 oss << 10 + z <<
".1." << 1 + i <<
".0";
346 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
347 ifs0[z][i] =
address.Assign (ndc0[i]);
349 for (
int i = 0; i < 6; ++i)
356 oss << 10 + z <<
".2." << 1 + i <<
".0";
357 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
358 ifs1[z][i] =
address.Assign (ndc1[i]);
361 oss << 10 + z <<
".3.1.0";
362 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
364 for (
int i = 0; i < 14; ++i)
367 oss << 10 + z <<
".4." << 1 + i <<
".0";
368 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
369 ifs2[z][i] =
address.Assign (ndc2[i]);
371 for (
int i = 0; i < 9; ++i)
374 oss << 10 + z <<
".5." << 1 + i <<
".0";
375 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
376 ifs3[z][i] =
address.Assign (ndc3[i]);
382 std::cout <<
"Forming Ring Topology..." << std::endl;
383 vectorOfNodeContainer nodes_ring(nCN);
384 for (uint32_t z = 0; z < nCN - 1; ++z)
386 nodes_ring[z].Add (nodes_net0[z][0].Get (0));
387 nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
389 nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
390 nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
391 vectorOfNetDeviceContainer ndc_ring(nCN);
392 for (uint32_t z = 0; z < nCN; ++z)
394 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
396 oss <<
"254.1." << z + 1 <<
".0";
397 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
398 ifs =
address.Assign (ndc_ring[z]);
403 std::cout <<
"Creating UDP Traffic Flows:" << std::endl;
407 StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
409 StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
414 if (systemCount == 1)
424 std::cout <<
"Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl;
425 client.SetAttribute (
"Remote", remoteAddress);
428 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
431 else if (systemId == 1)
437 sinkHelper.Install (nodes_net1[1][0].Get (0));
441 else if (systemId == 0)
447 std::cout <<
"Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl;
448 client.SetAttribute (
"Remote", remoteAddress);
451 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
460 for (uint32_t z = 0; z < nCN; ++z)
468 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
469 for (
int i = 0; i < 7; ++i)
471 for (uint32_t j = 0; j < nLANClients; ++j)
474 if (systemCount == 1)
477 (
"ns3::UdpSocketFactory",
481 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
485 else if (systemId == z % systemCount)
488 (
"ns3::UdpSocketFactory",
492 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
497 if (systemCount == 1)
499 r1 = 2 + (int)(4 * urng->
GetValue ());
506 client.SetAttribute (
"Remote", remoteAddress);
508 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
511 else if (systemId ==
x % systemCount)
513 r1 = 2 + (int)(4 * urng->
GetValue ());
520 client.SetAttribute (
"Remote", remoteAddress);
522 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
528 std::cout <<
"Net3 ]" << std::endl;
529 for (
int i = 0; i < 5; ++i)
531 for (uint32_t j = 0; j < nLANClients; ++j)
534 if (systemCount == 1)
537 (
"ns3::UdpSocketFactory",
541 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
545 else if (systemId == z % systemCount)
548 (
"ns3::UdpSocketFactory",
552 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
557 if (systemCount == 1)
559 r1 = 2 + (int)(4 * urng->
GetValue ());
566 client.SetAttribute (
"Remote", remoteAddress);
568 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
571 else if (systemId ==
x % systemCount)
573 r1 = 2 + (int)(4 * urng->
GetValue ());
580 client.SetAttribute (
"Remote", remoteAddress);
582 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
596 std::cout <<
"Using Nix-vectors..." << std::endl;
601 std::cout <<
"Populating Routing tables..." << std::endl;
607 std::cout <<
"Routing tables population took " 608 <<
TIMER_DIFF (routingEnd, routingStart) << std::endl;
610 std::cout <<
"Running simulator..." << std::endl;
615 std::cout <<
"Simulator finished." << std::endl;
620 std::cout <<
"-----" << std::endl <<
"Runtime Stats:" << std::endl;
621 std::cout <<
"Simulator init time: " << d1 << std::endl;
622 std::cout <<
"Simulator run time: " << d2 << std::endl;
623 std::cout <<
"Total elapsed time: " << d1 + d2 << std::endl;
holds a vector of ns3::Application pointers.
static Ipv4Address GetAny(void)
static uint32_t GetNNodes(void)
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Hold variables of type string.
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
static void Disable()
Terminates the parallel environment.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
a polymophic address class
static void Enable(int *pargc, char ***pargv)
Sets up parallel communication interface.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
#define TIMER_DIFF(_t1, _t2)
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
AttributeValue implementation for Address.
struct timeval TIMER_TYPE
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetSystemId()
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static uint32_t GetSize()