39 #include "ns3/core-module.h"
40 #include "ns3/internet-module.h"
41 #include "ns3/network-module.h"
42 #include "ns3/point-to-point-module.h"
43 #include "ns3/applications-module.h"
44 #include "ns3/onoff-application.h"
45 #include "ns3/packet-sink.h"
46 #include "ns3/simulator.h"
47 #include "ns3/ipv4-static-routing-helper.h"
48 #include "ns3/ipv4-list-routing-helper.h"
49 #include "ns3/ipv4-nix-vector-helper.h"
55 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
56 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
57 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1)-TIMER_SECONDS (_t2))
70 Array2D (
const size_t x,
const size_t y) : p (new T*[x]), m_xMax (x)
72 for (
size_t i = 0; i < m_xMax; i++)
78 for (
size_t i = 0; i < m_xMax; i++)
84 T* operator[] (
const size_t i)
97 Array3D (
const size_t x,
const size_t y,
const size_t z)
98 : p (new
Array2D<T>*[x]), m_xMax (x)
100 for (
size_t i = 0; i < m_xMax; i++)
106 for (
size_t i = 0; i < m_xMax; i++)
129 cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << endl;
132 int nCN = 2, nLANClients = 42;
136 cmd.
AddValue (
"CN",
"Number of total CNs [2]", nCN);
137 cmd.
AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
138 cmd.
AddValue (
"NIX",
"Toggle nix-vector routing", nix);
139 cmd.
Parse (argc,argv);
143 cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
148 cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << endl;
169 std::ostringstream oss;
182 list.
Add (staticRouting, 0);
183 list.
Add (nixRouting, 10);
191 for (
int z = 0; z < nCN; ++z)
193 cout <<
"Creating Campus Network " << z <<
":" << endl;
195 cout <<
" SubNet [ 0";
196 for (
int i = 0; i < 3; ++i)
198 nodes_net0[z][i].Create (1);
199 stack.
Install (nodes_net0[z][i]);
201 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
202 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
203 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
205 for (
int i = 0; i < 3; ++i)
207 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
211 for (
int i = 0; i < 6; ++i)
213 nodes_net1[z][i].Create (1);
214 stack.
Install (nodes_net1[z][i]);
216 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
217 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
218 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
219 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
220 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
222 for (
int i = 0; i < 6; ++i)
228 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
232 net0_1.
Add (nodes_net0[z][2].Get (0));
233 net0_1.
Add (nodes_net1[z][0].Get (0));
235 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
237 oss << 10 + z <<
".1.252.0";
238 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
239 ifs = address.
Assign (ndc0_1);
242 for (
int i = 0; i < 14; ++i)
244 nodes_net2[z][i].Create (1);
245 stack.
Install (nodes_net2[z][i]);
247 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
248 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
249 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
250 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
251 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
252 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
253 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
254 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
255 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
256 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
257 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
258 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
259 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
260 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
262 for (
int i = 0; i < 14; ++i)
264 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
268 for (
int i = 0; i < 7; ++i)
271 oss << 10 + z <<
".4." << 15 + i <<
".0";
272 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
273 for (
int j = 0; j < nLANClients; ++j)
275 nodes_net2LAN[z][i][j].Create (1);
276 stack.
Install (nodes_net2LAN[z][i][j]);
277 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
278 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
279 ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
283 cout <<
" 3 ]" << endl;
284 for (
int i = 0; i < 9; ++i)
286 nodes_net3[z][i].Create (1);
287 stack.
Install (nodes_net3[z][i]);
289 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
290 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
291 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
292 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
293 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
294 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
295 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
296 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
297 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
299 for (
int i = 0; i < 9; ++i)
301 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
305 for (
int i = 0; i < 5; ++i)
308 oss << 10 + z <<
".5." << 10 + i <<
".0";
309 address.
SetBase (oss.str ().c_str (),
"255.255.255.255");
310 for (
int j = 0; j < nLANClients; ++j)
312 nodes_net3LAN[z][i][j].Create (1);
313 stack.
Install (nodes_net3LAN[z][i][j]);
314 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
315 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
316 ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
319 cout <<
" Connecting Subnets..." << endl;
321 nodes_netLR[z].
Create (2);
322 stack.
Install (nodes_netLR[z]);
324 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
326 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
327 net0_4.
Add (nodes_netLR[z].Get (0));
328 net0_4.
Add (nodes_net0[z][0].Get (0));
329 net0_5.
Add (nodes_netLR[z].Get (1));
330 net0_5.
Add (nodes_net0[z][1].Get (0));
331 net2_4a.
Add (nodes_netLR[z].Get (0));
332 net2_4a.
Add (nodes_net2[z][0].Get (0));
333 net2_4b.
Add (nodes_netLR[z].Get (1));
334 net2_4b.
Add (nodes_net2[z][1].Get (0));
335 net3_5a.
Add (nodes_netLR[z].Get (1));
336 net3_5a.
Add (nodes_net3[z][0].Get (0));
337 net3_5b.
Add (nodes_netLR[z].Get (1));
338 net3_5b.
Add (nodes_net3[z][1].Get (0));
340 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
342 oss << 10 + z <<
".1.253.0";
343 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
344 ifs = address.
Assign (ndc0_4);
345 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
347 oss << 10 + z <<
".1.254.0";
348 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
349 ifs = address.
Assign (ndc0_5);
350 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
352 oss << 10 + z <<
".4.253.0";
353 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
354 ifs = address.
Assign (ndc2_4a);
355 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
357 oss << 10 + z <<
".4.254.0";
358 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
359 ifs = address.
Assign (ndc2_4b);
360 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
362 oss << 10 + z <<
".5.253.0";
363 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
364 ifs = address.
Assign (ndc3_5a);
365 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
367 oss << 10 + z <<
".5.254.0";
368 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
369 ifs = address.
Assign (ndc3_5b);
371 cout <<
" Assigning IP addresses..." << endl;
372 for (
int i = 0; i < 3; ++i)
375 oss << 10 + z <<
".1." << 1 + i <<
".0";
376 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
377 ifs0[z][i] = address.
Assign (ndc0[i]);
379 for (
int i = 0; i < 6; ++i)
386 oss << 10 + z <<
".2." << 1 + i <<
".0";
387 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
388 ifs1[z][i] = address.
Assign (ndc1[i]);
391 oss << 10 + z <<
".3.1.0";
392 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
393 ifs = address.
Assign (ndcLR);
394 for (
int i = 0; i < 14; ++i)
397 oss << 10 + z <<
".4." << 1 + i <<
".0";
398 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
399 ifs2[z][i] = address.
Assign (ndc2[i]);
401 for (
int i = 0; i < 9; ++i)
404 oss << 10 + z <<
".5." << 1 + i <<
".0";
405 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
406 ifs3[z][i] = address.
Assign (ndc3[i]);
412 cout <<
"Forming Ring Topology..." << endl;
414 for (
int z = 0; z < nCN-1; ++z)
416 nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
417 nodes_ring[z].
Add (nodes_net0[z+1][0].Get (0));
419 nodes_ring[nCN-1].
Add (nodes_net0[nCN-1][0].Get (0));
420 nodes_ring[nCN-1].
Add (nodes_net0[0][0].Get (0));
422 for (
int z = 0; z < nCN; ++z)
424 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
426 oss <<
"254.1." << z + 1 <<
".0";
427 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
428 ifs = address.
Assign (ndc_ring[z]);
435 cout <<
"Creating TCP Traffic Flows:" << endl;
438 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"));
440 StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
446 for (
int z = 0; z < nCN; ++z)
454 cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
455 for (
int i = 0; i < 7; ++i)
457 for (
int j = 0; j < nLANClients; ++j)
463 nodes_net2LAN[z][i][j].Get (0));
466 r1 = 2 + (int)(4 * urng->
GetValue ());
470 ifs2LAN[z][i][j].GetAddress (0), 9999));
473 clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
478 cout <<
"Net3 ]" << endl;
479 for (
int i = 0; i < 5; ++i)
481 for (
int j = 0; j < nLANClients; ++j)
487 nodes_net3LAN[z][i][j].Get (0));
490 r1 = 2 + (int)(4 * urng->
GetValue ());
494 ifs3LAN[z][i][j].GetAddress (0), 9999));
497 clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
503 cout <<
"Created " << NodeList::GetNNodes () <<
" nodes." << endl;
510 cout <<
"Using Nix-vectors..." << endl;
515 cout <<
"Populating Global Static Routing Tables..." << endl;
516 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
521 cout <<
"Routing tables population took "
522 <<
TIMER_DIFF (routingEnd, routingStart) << endl;
525 cout <<
"Running simulator..." << endl;
527 Simulator::Stop (
Seconds (100.0));
530 cout <<
"Simulator finished." << endl;
531 Simulator::Destroy ();
534 cout <<
"-----" << endl <<
"Runtime Stats:" << endl;
535 cout <<
"Simulator init time: " << d1 << endl;
536 cout <<
"Simulator run time: " << d2 << endl;
537 cout <<
"Total elapsed time: " << d1+d2 << endl;
539 delete[] nodes_netLR;