44 #include "ns3/core-module.h"
45 #include "ns3/internet-module.h"
46 #include "ns3/network-module.h"
47 #include "ns3/point-to-point-module.h"
48 #include "ns3/applications-module.h"
49 #include "ns3/onoff-application.h"
50 #include "ns3/packet-sink.h"
51 #include "ns3/simulator.h"
52 #include "ns3/nix-vector-helper.h"
77 p (new T*[
x]), m_xMax (
x)
79 for (
size_t i = 0; i < m_xMax; i++)
85 for (
size_t i = 0; i < m_xMax; i++)
96 T* operator[] (
const size_t i)
109 template <
typename T>
121 for (
size_t i = 0; i < m_xMax; i++)
127 for (
size_t i = 0; i < m_xMax; i++)
151 main (
int argc,
char *argv[])
153 auto t0 = std::chrono::steady_clock::now ();
155 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
158 int nCN = 2, nLANClients = 42;
160 bool useIpv6 =
false;
163 cmd.AddValue (
"useIPv6",
"Use IPv6 instead of IPv4", useIpv6);
164 cmd.AddValue (
"CN",
"Number of total CNs [2]", nCN);
165 cmd.AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
166 cmd.AddValue (
"NIX",
"Toggle nix-vector routing", nix);
167 cmd.Parse (argc,argv);
171 std::cout <<
"This script can work in IPv6 only by using NIX"
177 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
182 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
199 std::ostringstream oss;
213 stack.SetRoutingHelper (nixRouting);
218 stack.SetRoutingHelper (nixRouting);
223 for (
int z = 0; z < nCN; ++z)
225 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
227 std::cout <<
" SubNet [ 0";
228 for (
int i = 0; i < 3; ++i)
230 nodes_net0[z][i].Create (1);
231 stack.Install (nodes_net0[z][i]);
233 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
234 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
235 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
237 for (
int i = 0; i < 3; ++i)
239 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
243 for (
int i = 0; i < 6; ++i)
245 nodes_net1[z][i].Create (1);
246 stack.Install (nodes_net1[z][i]);
248 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
249 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
250 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
251 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
252 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
254 for (
int i = 0; i < 6; ++i)
260 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
264 net0_1.
Add (nodes_net0[z][2].Get (0));
265 net0_1.
Add (nodes_net1[z][0].Get (0));
267 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
271 oss << 10 + z <<
".1.252.0";
272 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
273 addressHelperv4.
Assign (ndc0_1);
277 oss << 2001 + z <<
":1:252::";
279 addressHelperv6.
Assign (ndc0_1);
283 for (
int i = 0; i < 14; ++i)
285 nodes_net2[z][i].Create (1);
286 stack.Install (nodes_net2[z][i]);
288 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
289 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
290 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
291 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
292 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
293 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
294 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
295 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
296 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
297 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
298 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
299 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
300 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
301 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
303 for (
int i = 0; i < 14; ++i)
305 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
308 for (
int i = 0; i < 7; ++i)
313 oss << 10 + z <<
".4." << 15 + i <<
".0";
314 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
318 oss << 2001 + z <<
":4:" << 15 + i <<
"::";
321 for (
int j = 0; j < nLANClients; ++j)
323 nodes_net2LAN[z][i][j].Create (1);
324 stack.Install (nodes_net2LAN[z][i][j]);
325 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
326 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
338 std::cout <<
" 3 ]" << std::endl;
339 for (
int i = 0; i < 9; ++i)
341 nodes_net3[z][i].Create (1);
342 stack.Install (nodes_net3[z][i]);
344 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
345 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
346 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
347 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
348 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
349 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
350 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
351 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
352 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
354 for (
int i = 0; i < 9; ++i)
356 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
359 for (
int i = 0; i < 5; ++i)
364 oss << 10 + z <<
".5." << 10 + i <<
".0";
365 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
369 oss << 2001 + z <<
":5:" << 10 + i <<
"::";
373 for (
int j = 0; j < nLANClients; ++j)
375 nodes_net3LAN[z][i][j].Create (1);
376 stack.Install (nodes_net3LAN[z][i][j]);
377 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
378 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
389 std::cout <<
" Connecting Subnets..." << std::endl;
391 nodes_netLR[z].
Create (2);
392 stack.Install (nodes_netLR[z]);
394 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
396 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
397 net0_4.
Add (nodes_netLR[z].Get (0));
398 net0_4.
Add (nodes_net0[z][0].Get (0));
399 net0_5.
Add (nodes_netLR[z].Get (1));
400 net0_5.
Add (nodes_net0[z][1].Get (0));
401 net2_4a.
Add (nodes_netLR[z].Get (0));
402 net2_4a.
Add (nodes_net2[z][0].Get (0));
403 net2_4b.
Add (nodes_netLR[z].Get (1));
404 net2_4b.
Add (nodes_net2[z][1].Get (0));
405 net3_5a.
Add (nodes_netLR[z].Get (1));
406 net3_5a.
Add (nodes_net3[z][0].Get (0));
407 net3_5b.
Add (nodes_netLR[z].Get (1));
408 net3_5b.
Add (nodes_net3[z][1].Get (0));
410 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
411 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
412 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
413 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
414 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
415 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
423 oss << 10 + z <<
".1.253.0";
424 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
425 addressHelperv4.
Assign (ndc0_4);
428 oss << 10 + z <<
".1.254.0";
429 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
430 addressHelperv4.
Assign (ndc0_5);
433 oss << 10 + z <<
".4.253.0";
434 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
435 addressHelperv4.
Assign (ndc2_4a);
438 oss << 10 + z <<
".4.254.0";
439 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
440 addressHelperv4.
Assign (ndc2_4b);
443 oss << 10 + z <<
".5.253.0";
444 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
445 addressHelperv4.
Assign (ndc3_5a);
448 oss << 10 + z <<
".5.254.0";
449 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
450 addressHelperv4.
Assign (ndc3_5b);
456 oss << 2001 + z <<
":1:253::";
458 addressHelperv6.
Assign (ndc0_4);
461 oss << 2001 + z <<
":1:254::";
463 addressHelperv6.
Assign (ndc0_5);
466 oss << 2001 + z <<
":4:253::";
468 addressHelperv6.
Assign (ndc2_4a);
471 oss << 2001 + z <<
":4:254::";
473 addressHelperv6.
Assign (ndc2_4b);
476 oss << 2001 + z <<
":5:253::";
478 addressHelperv6.
Assign (ndc3_5a);
481 oss << 2001 + z <<
":5:254::";
483 addressHelperv6.
Assign (ndc3_5b);
487 std::cout <<
" Assigning IP addresses..." << std::endl;
488 for (
int i = 0; i < 3; ++i)
493 oss << 10 + z <<
".1." << 1 + i <<
".0";
494 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
495 addressHelperv4.
Assign (ndc0[i]);
499 oss << 2001 + z <<
":1:" << 1 + i <<
"::";
501 addressHelperv6.
Assign (ndc0[i]);
504 for (
int i = 0; i < 6; ++i)
513 oss << 10 + z <<
".2." << 1 + i <<
".0";
514 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
515 addressHelperv4.
Assign (ndc1[i]);
519 oss << 2001 + z <<
":2:" << 1 + i <<
"::";
521 addressHelperv6.
Assign (ndc1[i]);
527 oss << 10 + z <<
".3.1.0";
528 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
529 addressHelperv4.
Assign (ndcLR);
533 oss << 2001 + z <<
":3:1::";
535 addressHelperv6.
Assign (ndcLR);
538 for (
int i = 0; i < 14; ++i)
543 oss << 10 + z <<
".4." << 1 + i <<
".0";
544 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
545 addressHelperv4.
Assign (ndc2[i]);
549 oss << 2001 + z <<
":4:" << 1 + i <<
"::";
551 addressHelperv6.
Assign (ndc2[i]);
555 for (
int i = 0; i < 9; ++i)
560 oss << 10 + z <<
".5." << 1 + i <<
".0";
561 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
562 addressHelperv4.
Assign (ndc3[i]);
566 oss << 2001 + z <<
":5:" << 1 + i <<
"::";
568 addressHelperv6.
Assign (ndc3[i]);
575 std::cout <<
"Forming Ring Topology..." << std::endl;
577 for (
int z = 0; z < nCN-1; ++z)
579 nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
580 nodes_ring[z].
Add (nodes_net0[z+1][0].Get (0));
582 nodes_ring[nCN-1].
Add (nodes_net0[nCN-1][0].Get (0));
583 nodes_ring[nCN-1].
Add (nodes_net0[0][0].Get (0));
585 for (
int z = 0; z < nCN; ++z)
587 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
591 oss <<
"254.1." << z + 1 <<
".0";
592 addressHelperv4.
SetBase (oss.str ().c_str (),
"255.255.255.0");
593 addressHelperv4.
Assign (ndc_ring[z]);
597 oss <<
"254:1:" << z + 1 <<
"::";
599 addressHelperv6.
Assign (ndc_ring[z]);
607 std::cout <<
"Creating TCP Traffic Flows:" << std::endl;
610 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"));
612 StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
629 for (
int z = 0; z < nCN; ++z)
637 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
638 for (
int i = 0; i < 7; ++i)
640 for (
int j = 0; j < nLANClients; ++j)
645 nodes_net2LAN[z][i][j].Get (0));
648 r1 = 2 + (int)(4 * urng->
GetValue ());
651 AddressValue remoteAddress (ifs2LanRemoteAddress[z][i][j]);
652 client.SetAttribute (
"Remote", remoteAddress);
654 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
659 std::cout <<
"Net3 ]" << std::endl;
660 for (
int i = 0; i < 5; ++i)
662 for (
int j = 0; j < nLANClients; ++j)
667 nodes_net3LAN[z][i][j].Get (0));
670 r1 = 2 + (int)(4 * urng->
GetValue ());
673 AddressValue remoteAddress (ifs3LanRemoteAddress[z][i][j]);
674 client.SetAttribute (
"Remote", remoteAddress);
676 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
683 auto routingStart = std::chrono::steady_clock::now ();
688 std::cout <<
"Using Nix-vectors..." << std::endl;
693 std::cout <<
"Populating Global Static Routing Tables..." << std::endl;
697 auto routingEnd = std::chrono::steady_clock::now ();
698 std::cout <<
"Routing tables population took "
699 << std::chrono::duration_cast<std::chrono::milliseconds> (routingEnd - routingStart).count () <<
"ms"
703 std::cout <<
"Running simulator..." << std::endl;
704 auto t1 = std::chrono::steady_clock::now ();
707 auto t2 = std::chrono::steady_clock::now ();
708 std::cout <<
"Simulator finished." << std::endl;
711 auto d1 = std::chrono::duration_cast<std::chrono::seconds>(t1 - t0);
712 auto d2 = std::chrono::duration_cast<std::chrono::seconds>(t2 - t1);
714 std::cout <<
"-----" << std::endl
715 <<
"Runtime Stats:" << std::endl;
716 std::cout <<
"Simulator init time: " << d1.count () <<
"s" << std::endl;
717 std::cout <<
"Simulator run time: " << d2.count () <<
"s" << std::endl;
718 std::cout <<
"Total elapsed time: " << (d1 + d2).count () <<
"s" << std::endl;
720 delete[] nodes_netLR;
2D array used in nix-vector-routing example "nms-p2p-nix.cc"
Array2D(const size_t x, const size_t y)
Constructor.
const size_t m_xMax
maximum number of rows
3D array used in nix-vector-routing example "nms-p2p-nix.cc"
Array3D(const size_t x, const size_t y, const size_t z)
Constructor.
const size_t m_xMax
maximum number of rows
Array2D< T > ** p
Stored elements.
a polymophic address class
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static Ipv4Address GetAny(void)
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
holds a vector of ns3::NetDevice pointers
Helper class that adds Nix-vector routing to nodes.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetNNodes(void)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
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.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Run(void)
Run the simulation.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Hold variables of type string.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
list x
Random number samples.