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-static-routing-helper.h"
50 #include "ns3/ipv4-list-routing-helper.h"
51 #include "ns3/ipv4-nix-vector-helper.h"
56 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
57 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec * 1e-6)
58 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1) - TIMER_SECONDS (_t2))
63 main (
int argc,
char *argv[])
67 typedef std::vector<NodeContainer> vectorOfNodeContainer;
68 typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
69 typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
71 typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
72 typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
73 typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
75 typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
76 typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
83 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
91 uint32_t nCN = 2, nLANClients = 42;
97 cmd.
AddValue (
"CN",
"Number of total CNs [2]", nCN);
98 cmd.
AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
99 cmd.
AddValue (
"single",
"1 if use single flow", single);
100 cmd.
AddValue (
"nBytes",
"Number of bytes for each on/off app", nBytes);
101 cmd.
AddValue (
"nix",
"Toggle the use of nix-vector or global routing", nix);
102 cmd.
Parse (argc,argv);
106 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
110 if (systemCount > nCN)
112 std::cout <<
"Number of total CNs (" << nCN <<
") should be >= systemCount ("
113 << systemCount <<
")." << std::endl;
117 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
121 vectorOfNodeContainer nodes_netLR(nCN);
122 vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
123 vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
124 vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
125 vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
127 vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
128 vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
135 vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
136 vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
137 vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
138 vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
139 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
140 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
143 std::ostringstream oss;
155 list.
Add (staticRouting, 0);
156 list.
Add (nixRouting, 10);
164 for (uint32_t z = 0; z < nCN; ++z)
166 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
168 std::cout <<
" SubNet [ 0";
169 for (
int i = 0; i < 3; ++i)
171 Ptr<Node> node = CreateObject<Node> (z % systemCount);
172 nodes_net0[z][i].Add (node);
173 stack.
Install (nodes_net0[z][i]);
175 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
176 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
177 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
179 for (
int i = 0; i < 3; ++i)
181 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
185 for (
int i = 0; i < 6; ++i)
187 Ptr<Node> node = CreateObject<Node> (z % systemCount);
188 nodes_net1[z][i].Add (node);
189 stack.
Install (nodes_net1[z][i]);
191 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
192 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
193 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
194 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
195 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
197 for (
int i = 0; i < 6; ++i)
203 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
207 net0_1.
Add (nodes_net0[z][2].Get (0));
208 net0_1.
Add (nodes_net1[z][0].Get (0));
210 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
212 oss << 10 + z <<
".1.252.0";
213 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
214 ifs = address.
Assign (ndc0_1);
217 for (
int i = 0; i < 14; ++i)
219 Ptr<Node> node = CreateObject<Node> (z % systemCount);
220 nodes_net2[z][i].Add (node);
221 stack.
Install (nodes_net2[z][i]);
223 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
224 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
225 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
226 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
227 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
228 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
229 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
230 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
231 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
232 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
233 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
234 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
235 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
236 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
238 for (
int i = 0; i < 14; ++i)
240 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
242 vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
243 for (
int i = 0; i < 7; ++i)
246 oss << 10 + z <<
".4." << 15 + i <<
".0";
247 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
248 for (uint32_t j = 0; j < nLANClients; ++j)
250 Ptr<Node> node = CreateObject<Node> (z % systemCount);
251 nodes_net2LAN[z][i][j].Add (node);
252 stack.
Install (nodes_net2LAN[z][i][j]);
253 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
254 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
255 ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
259 std::cout <<
" 3 ]" << std::endl;
260 for (
int i = 0; i < 9; ++i)
262 Ptr<Node> node = CreateObject<Node> (z % systemCount);
263 nodes_net3[z][i].Add (node);
264 stack.
Install (nodes_net3[z][i]);
266 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
267 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
268 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
269 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
270 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
271 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
272 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
273 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
274 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
276 for (
int i = 0; i < 9; ++i)
278 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
280 vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
281 for (
int i = 0; i < 5; ++i)
284 oss << 10 + z <<
".5." << 10 + i <<
".0";
285 address.
SetBase (oss.str ().c_str (),
"255.255.255.255");
286 for (uint32_t j = 0; j < nLANClients; ++j)
288 Ptr<Node> node = CreateObject<Node> (z % systemCount);
289 nodes_net3LAN[z][i][j].Add (node);
290 stack.
Install (nodes_net3LAN[z][i][j]);
291 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
292 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
293 ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
296 std::cout <<
" Connecting Subnets..." << std::endl;
298 Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
299 Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
300 nodes_netLR[z].Add (node1);
301 nodes_netLR[z].Add (node2);
302 stack.
Install (nodes_netLR[z]);
304 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
306 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
307 net0_4.
Add (nodes_netLR[z].Get (0));
308 net0_4.
Add (nodes_net0[z][0].Get (0));
309 net0_5.
Add (nodes_netLR[z].Get (1));
310 net0_5.
Add (nodes_net0[z][1].Get (0));
311 net2_4a.
Add (nodes_netLR[z].Get (0));
312 net2_4a.
Add (nodes_net2[z][0].Get (0));
313 net2_4b.
Add (nodes_netLR[z].Get (1));
314 net2_4b.
Add (nodes_net2[z][1].Get (0));
315 net3_5a.
Add (nodes_netLR[z].Get (1));
316 net3_5a.
Add (nodes_net3[z][0].Get (0));
317 net3_5b.
Add (nodes_netLR[z].Get (1));
318 net3_5b.
Add (nodes_net3[z][1].Get (0));
320 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
322 oss << 10 + z <<
".1.253.0";
323 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
324 ifs = address.
Assign (ndc0_4);
325 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
327 oss << 10 + z <<
".1.254.0";
328 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
329 ifs = address.
Assign (ndc0_5);
330 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
332 oss << 10 + z <<
".4.253.0";
333 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
334 ifs = address.
Assign (ndc2_4a);
335 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
337 oss << 10 + z <<
".4.254.0";
338 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
339 ifs = address.
Assign (ndc2_4b);
340 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
342 oss << 10 + z <<
".5.253.0";
343 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
344 ifs = address.
Assign (ndc3_5a);
345 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
347 oss << 10 + z <<
".5.254.0";
348 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
349 ifs = address.
Assign (ndc3_5b);
351 std::cout <<
" Assigning IP addresses..." << std::endl;
352 for (
int i = 0; i < 3; ++i)
355 oss << 10 + z <<
".1." << 1 + i <<
".0";
356 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
357 ifs0[z][i] = address.
Assign (ndc0[i]);
359 for (
int i = 0; i < 6; ++i)
366 oss << 10 + z <<
".2." << 1 + i <<
".0";
367 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
368 ifs1[z][i] = address.
Assign (ndc1[i]);
371 oss << 10 + z <<
".3.1.0";
372 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
373 ifs = address.
Assign (ndcLR);
374 for (
int i = 0; i < 14; ++i)
377 oss << 10 + z <<
".4." << 1 + i <<
".0";
378 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
379 ifs2[z][i] = address.
Assign (ndc2[i]);
381 for (
int i = 0; i < 9; ++i)
384 oss << 10 + z <<
".5." << 1 + i <<
".0";
385 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
386 ifs3[z][i] = address.
Assign (ndc3[i]);
392 std::cout <<
"Forming Ring Topology..." << std::endl;
393 vectorOfNodeContainer nodes_ring(nCN);
394 for (uint32_t z = 0; z < nCN - 1; ++z)
396 nodes_ring[z].Add (nodes_net0[z][0].Get (0));
397 nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
399 nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
400 nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
401 vectorOfNetDeviceContainer ndc_ring(nCN);
402 for (uint32_t z = 0; z < nCN; ++z)
404 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
406 oss <<
"254.1." << z + 1 <<
".0";
407 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
408 ifs = address.
Assign (ndc_ring[z]);
413 std::cout <<
"Creating UDP Traffic Flows:" << std::endl;
417 StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
419 StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
424 if (systemCount == 1)
434 std::cout <<
"Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl;
438 clientApp.
Add (client.
Install (nodes_net2LAN[0][0][0].Get (0)));
441 else if (systemId == 1)
447 sinkHelper.
Install (nodes_net1[1][0].Get (0));
451 else if (systemId == 0)
457 std::cout <<
"Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl;
461 clientApp.
Add (client.
Install (nodes_net2LAN[0][0][0].Get (0)));
470 for (uint32_t z = 0; z < nCN; ++z)
478 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
479 for (
int i = 0; i < 7; ++i)
481 for (uint32_t j = 0; j < nLANClients; ++j)
484 if (systemCount == 1)
487 (
"ns3::UdpSocketFactory",
491 sinkHelper.
Install (nodes_net2LAN[z][i][j].Get (0));
495 else if (systemId == z % systemCount)
498 (
"ns3::UdpSocketFactory",
502 sinkHelper.
Install (nodes_net2LAN[z][i][j].Get (0));
507 if (systemCount == 1)
509 r1 = 2 + (int)(4 * urng->
GetValue ());
518 clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
521 else if (systemId == x % systemCount)
523 r1 = 2 + (int)(4 * urng->
GetValue ());
532 clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
538 std::cout <<
"Net3 ]" << std::endl;
539 for (
int i = 0; i < 5; ++i)
541 for (uint32_t j = 0; j < nLANClients; ++j)
544 if (systemCount == 1)
547 (
"ns3::UdpSocketFactory",
551 sinkHelper.
Install (nodes_net3LAN[z][i][j].Get (0));
555 else if (systemId == z % systemCount)
558 (
"ns3::UdpSocketFactory",
562 sinkHelper.
Install (nodes_net3LAN[z][i][j].Get (0));
567 if (systemCount == 1)
569 r1 = 2 + (int)(4 * urng->
GetValue ());
578 clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
581 else if (systemId == x % systemCount)
583 r1 = 2 + (int)(4 * urng->
GetValue ());
592 clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
606 std::cout <<
"Using Nix-vectors..." << std::endl;
611 std::cout <<
"Populating Routing tables..." << std::endl;
617 std::cout <<
"Routing tables population took "
618 <<
TIMER_DIFF (routingEnd, routingStart) << std::endl;
620 std::cout <<
"Running simulator..." << std::endl;
625 std::cout <<
"Simulator finished." << std::endl;
630 std::cout <<
"-----" << std::endl <<
"Runtime Stats:" << std::endl;
631 std::cout <<
"Simulator init time: " << d1 << std::endl;
632 std::cout <<
"Simulator run time: " << d2 << std::endl;
633 std::cout <<
"Total elapsed time: " << d1 + d2 << std::endl;
636 NS_FATAL_ERROR (
"Can't use distributed simulator without MPI compiled in");
holds a vector of ns3::Application pointers.
static Ipv4Address GetAny(void)
static uint32_t GetNNodes(void)
int main(int argc, char *argv[])
holds a vector of std::pair of Ptr 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 until one of:
#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.
#define NS_FATAL_ERROR(msg)
fatal error handling
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)
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)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
void SetDefault(std::string name, const AttributeValue &value)
keep track of a set of node pointers.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define TIMER_DIFF(_t1, _t2)
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
hold objects of type ns3::Address
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
struct timeval TIMER_TYPE
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetSystemId()
Helper class that adds ns3::Ipv4StaticRouting objects.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Time Seconds(double value)
Construct a Time in the indicated unit.
Helper class that adds ns3::Ipv4ListRouting objects.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
static uint32_t GetSize()
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.