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[])
65 typedef std::vector<NodeContainer> vectorOfNodeContainer;
66 typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
67 typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
69 typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
70 typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
71 typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
73 typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
74 typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
81 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
89 uint32_t nCN = 2, nLANClients = 42;
95 cmd.AddValue (
"CN",
"Number of total CNs [2]", nCN);
96 cmd.AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
97 cmd.AddValue (
"single",
"1 if use single flow", single);
98 cmd.AddValue (
"nBytes",
"Number of bytes for each on/off app", nBytes);
99 cmd.AddValue (
"nix",
"Toggle the use of nix-vector or global routing", nix);
100 cmd.Parse (argc,argv);
104 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2" 108 if (systemCount > nCN)
110 std::cout <<
"Number of total CNs (" << nCN <<
") should be >= systemCount (" 111 << systemCount <<
")." << std::endl;
115 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
119 vectorOfNodeContainer nodes_netLR(nCN);
120 vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
121 vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
122 vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
123 vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
125 vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
126 vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
133 vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
134 vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
135 vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
136 vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
137 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
138 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
141 std::ostringstream oss;
152 stack.SetRoutingHelper (nixRouting);
156 for (uint32_t z = 0; z < nCN; ++z)
158 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
160 std::cout <<
" SubNet [ 0";
161 for (
int i = 0; i < 3; ++i)
163 Ptr<Node> node = CreateObject<Node> (z % systemCount);
164 nodes_net0[z][i].Add (node);
165 stack.Install (nodes_net0[z][i]);
167 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
168 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
169 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
171 for (
int i = 0; i < 3; ++i)
173 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
177 for (
int i = 0; i < 6; ++i)
179 Ptr<Node> node = CreateObject<Node> (z % systemCount);
180 nodes_net1[z][i].Add (node);
181 stack.Install (nodes_net1[z][i]);
183 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
184 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
185 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
186 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
187 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
189 for (
int i = 0; i < 6; ++i)
195 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
199 net0_1.
Add (nodes_net0[z][2].Get (0));
200 net0_1.
Add (nodes_net1[z][0].Get (0));
202 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
204 oss << 10 + z <<
".1.252.0";
205 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
209 for (
int i = 0; i < 14; ++i)
211 Ptr<Node> node = CreateObject<Node> (z % systemCount);
212 nodes_net2[z][i].Add (node);
213 stack.Install (nodes_net2[z][i]);
215 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
216 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
217 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
218 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
219 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
220 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
221 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
222 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
223 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
224 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
225 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
226 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
227 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
228 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
230 for (
int i = 0; i < 14; ++i)
232 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
234 vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
235 for (
int i = 0; i < 7; ++i)
238 oss << 10 + z <<
".4." << 15 + i <<
".0";
239 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
240 for (uint32_t j = 0; j < nLANClients; ++j)
242 Ptr<Node> node = CreateObject<Node> (z % systemCount);
243 nodes_net2LAN[z][i][j].Add (node);
244 stack.Install (nodes_net2LAN[z][i][j]);
245 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
246 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
247 ifs2LAN[z][i][j] =
address.Assign (ndc2LAN[i][j]);
251 std::cout <<
" 3 ]" << std::endl;
252 for (
int i = 0; i < 9; ++i)
254 Ptr<Node> node = CreateObject<Node> (z % systemCount);
255 nodes_net3[z][i].Add (node);
256 stack.Install (nodes_net3[z][i]);
258 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
259 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
260 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
261 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
262 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
263 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
264 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
265 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
266 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
268 for (
int i = 0; i < 9; ++i)
270 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
272 vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
273 for (
int i = 0; i < 5; ++i)
276 oss << 10 + z <<
".5." << 10 + i <<
".0";
277 address.SetBase (oss.str ().c_str (),
"255.255.255.255");
278 for (uint32_t j = 0; j < nLANClients; ++j)
280 Ptr<Node> node = CreateObject<Node> (z % systemCount);
281 nodes_net3LAN[z][i][j].Add (node);
282 stack.Install (nodes_net3LAN[z][i][j]);
283 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
284 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
285 ifs3LAN[z][i][j] =
address.Assign (ndc3LAN[i][j]);
288 std::cout <<
" Connecting Subnets..." << std::endl;
290 Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
291 Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
292 nodes_netLR[z].Add (node1);
293 nodes_netLR[z].Add (node2);
294 stack.Install (nodes_netLR[z]);
296 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
298 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
299 net0_4.
Add (nodes_netLR[z].Get (0));
300 net0_4.
Add (nodes_net0[z][0].Get (0));
301 net0_5.
Add (nodes_netLR[z].Get (1));
302 net0_5.
Add (nodes_net0[z][1].Get (0));
303 net2_4a.
Add (nodes_netLR[z].Get (0));
304 net2_4a.
Add (nodes_net2[z][0].Get (0));
305 net2_4b.
Add (nodes_netLR[z].Get (1));
306 net2_4b.
Add (nodes_net2[z][1].Get (0));
307 net3_5a.
Add (nodes_netLR[z].Get (1));
308 net3_5a.
Add (nodes_net3[z][0].Get (0));
309 net3_5b.
Add (nodes_netLR[z].Get (1));
310 net3_5b.
Add (nodes_net3[z][1].Get (0));
312 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
314 oss << 10 + z <<
".1.253.0";
315 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
317 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
319 oss << 10 + z <<
".1.254.0";
320 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
322 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
324 oss << 10 + z <<
".4.253.0";
325 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
326 ifs =
address.Assign (ndc2_4a);
327 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
329 oss << 10 + z <<
".4.254.0";
330 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
331 ifs =
address.Assign (ndc2_4b);
332 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
334 oss << 10 + z <<
".5.253.0";
335 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
336 ifs =
address.Assign (ndc3_5a);
337 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
339 oss << 10 + z <<
".5.254.0";
340 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
341 ifs =
address.Assign (ndc3_5b);
343 std::cout <<
" Assigning IP addresses..." << std::endl;
344 for (
int i = 0; i < 3; ++i)
347 oss << 10 + z <<
".1." << 1 + i <<
".0";
348 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
349 ifs0[z][i] =
address.Assign (ndc0[i]);
351 for (
int i = 0; i < 6; ++i)
358 oss << 10 + z <<
".2." << 1 + i <<
".0";
359 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
360 ifs1[z][i] =
address.Assign (ndc1[i]);
363 oss << 10 + z <<
".3.1.0";
364 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
366 for (
int i = 0; i < 14; ++i)
369 oss << 10 + z <<
".4." << 1 + i <<
".0";
370 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
371 ifs2[z][i] =
address.Assign (ndc2[i]);
373 for (
int i = 0; i < 9; ++i)
376 oss << 10 + z <<
".5." << 1 + i <<
".0";
377 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
378 ifs3[z][i] =
address.Assign (ndc3[i]);
384 std::cout <<
"Forming Ring Topology..." << std::endl;
385 vectorOfNodeContainer nodes_ring(nCN);
386 for (uint32_t z = 0; z < nCN - 1; ++z)
388 nodes_ring[z].Add (nodes_net0[z][0].Get (0));
389 nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
391 nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
392 nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
393 vectorOfNetDeviceContainer ndc_ring(nCN);
394 for (uint32_t z = 0; z < nCN; ++z)
396 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
398 oss <<
"254.1." << z + 1 <<
".0";
399 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
400 ifs =
address.Assign (ndc_ring[z]);
405 std::cout <<
"Creating UDP Traffic Flows:" << std::endl;
409 StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
411 StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
416 if (systemCount == 1)
426 std::cout <<
"Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl;
427 client.SetAttribute (
"Remote", remoteAddress);
430 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
433 else if (systemId == 1)
439 sinkHelper.Install (nodes_net1[1][0].Get (0));
443 else if (systemId == 0)
449 std::cout <<
"Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl;
450 client.SetAttribute (
"Remote", remoteAddress);
453 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
462 for (uint32_t z = 0; z < nCN; ++z)
470 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
471 for (
int i = 0; i < 7; ++i)
473 for (uint32_t j = 0; j < nLANClients; ++j)
476 if (systemCount == 1)
479 (
"ns3::UdpSocketFactory",
483 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
487 else if (systemId == z % systemCount)
490 (
"ns3::UdpSocketFactory",
494 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
499 if (systemCount == 1)
501 r1 = 2 + (int)(4 * urng->
GetValue ());
508 client.SetAttribute (
"Remote", remoteAddress);
510 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
513 else if (systemId ==
x % systemCount)
515 r1 = 2 + (int)(4 * urng->
GetValue ());
522 client.SetAttribute (
"Remote", remoteAddress);
524 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
530 std::cout <<
"Net3 ]" << std::endl;
531 for (
int i = 0; i < 5; ++i)
533 for (uint32_t j = 0; j < nLANClients; ++j)
536 if (systemCount == 1)
539 (
"ns3::UdpSocketFactory",
543 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
547 else if (systemId == z % systemCount)
550 (
"ns3::UdpSocketFactory",
554 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
559 if (systemCount == 1)
561 r1 = 2 + (int)(4 * urng->
GetValue ());
568 client.SetAttribute (
"Remote", remoteAddress);
570 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
573 else if (systemId ==
x % systemCount)
575 r1 = 2 + (int)(4 * urng->
GetValue ());
582 client.SetAttribute (
"Remote", remoteAddress);
584 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
598 std::cout <<
"Using Nix-vectors..." << std::endl;
603 std::cout <<
"Populating Routing tables..." << std::endl;
609 std::cout <<
"Routing tables population took " 610 <<
TIMER_DIFF (routingEnd, routingStart) << std::endl;
612 std::cout <<
"Running simulator..." << std::endl;
617 std::cout <<
"Simulator finished." << std::endl;
622 std::cout <<
"-----" << std::endl <<
"Runtime Stats:" << std::endl;
623 std::cout <<
"Simulator init time: " << d1 << std::endl;
624 std::cout <<
"Simulator run time: " << d2 << std::endl;
625 std::cout <<
"Total elapsed time: " << d1 + d2 << std::endl;
628 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)
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.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
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()