43 #include "ns3/core-module.h"
44 #include "ns3/internet-module.h"
45 #include "ns3/network-module.h"
46 #include "ns3/on-off-helper.h"
47 #include "ns3/packet-sink-helper.h"
48 #include "ns3/point-to-point-helper.h"
49 #include "ns3/mpi-interface.h"
50 #include "ns3/nix-vector-helper.h"
60 main (
int argc,
char *argv[])
62 typedef std::vector<NodeContainer> vectorOfNodeContainer;
63 typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
64 typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
66 typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
67 typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
68 typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
70 typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
71 typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
80 uint32_t nLANClients = 10;
89 cmd.AddValue (
"campuses",
"Number of campus networks", nCN);
90 cmd.AddValue (
"clients",
"Number of client nodes per LAN", nLANClients);
91 cmd.AddValue (
"packets",
"Number of packets each on/off app should send", nPackets);
92 cmd.AddValue (
"nix",
"Toggle the use of nix-vector or global routing", nix);
93 cmd.AddValue (
"stop",
"Simulation run time", stop);
94 cmd.AddValue (
"single",
"Use single on/off app per campus network", single);
95 cmd.AddValue (
"verbose",
"Show extra timing information",
verbose);
96 cmd.AddValue (
"test",
"Enable regression test output", testing);
98 cmd.Parse (argc,argv);
108 RANK0COUT (
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl);
116 RANK0COUT (
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
120 if (systemCount > nCN)
122 RANK0COUT (
"Number of total CNs (" << nCN <<
") should be >= systemCount ("
123 << systemCount <<
")." << std::endl);
127 RANK0COUT (
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl);
129 vectorOfNodeContainer nodes_netLR(nCN);
130 vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
131 vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
132 vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
133 vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
135 vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
136 vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
143 vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
144 vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
145 vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
146 vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
147 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
148 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
151 std::ostringstream oss;
162 stack.SetRoutingHelper (nixRouting);
166 for (uint32_t z = 0; z < nCN; ++z)
168 RANK0COUT (
"Creating Campus Network " << z <<
":" << std::endl);
171 for (
int i = 0; i < 3; ++i)
173 Ptr<Node> node = CreateObject<Node> (z % systemCount);
174 nodes_net0[z][i].Add (node);
175 stack.Install (nodes_net0[z][i]);
177 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
178 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
179 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
181 for (
int i = 0; i < 3; ++i)
183 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
187 for (
int i = 0; i < 6; ++i)
189 Ptr<Node> node = CreateObject<Node> (z % systemCount);
190 nodes_net1[z][i].Add (node);
191 stack.Install (nodes_net1[z][i]);
193 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
194 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
195 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
196 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
197 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
199 for (
int i = 0; i < 6; ++i)
205 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
209 net0_1.
Add (nodes_net0[z][2].Get (0));
210 net0_1.
Add (nodes_net1[z][0].Get (0));
212 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
214 oss << 10 + z <<
".1.252.0";
215 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
219 for (
int i = 0; i < 14; ++i)
221 Ptr<Node> node = CreateObject<Node> (z % systemCount);
222 nodes_net2[z][i].Add (node);
223 stack.Install (nodes_net2[z][i]);
225 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
226 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
227 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
228 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
229 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
230 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
231 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
232 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
233 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
234 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
235 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
236 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
237 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
238 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
240 for (
int i = 0; i < 14; ++i)
242 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
244 vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
245 for (
int i = 0; i < 7; ++i)
248 oss << 10 + z <<
".4." << 15 + i <<
".0";
249 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
250 for (uint32_t j = 0; j < nLANClients; ++j)
252 Ptr<Node> node = CreateObject<Node> (z % systemCount);
253 nodes_net2LAN[z][i][j].Add (node);
254 stack.Install (nodes_net2LAN[z][i][j]);
255 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
256 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
257 ifs2LAN[z][i][j] =
address.Assign (ndc2LAN[i][j]);
262 for (
int i = 0; i < 9; ++i)
264 Ptr<Node> node = CreateObject<Node> (z % systemCount);
265 nodes_net3[z][i].Add (node);
266 stack.Install (nodes_net3[z][i]);
268 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
269 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
270 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
271 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
272 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
273 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
274 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
275 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
276 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
278 for (
int i = 0; i < 9; ++i)
280 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
282 vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
283 for (
int i = 0; i < 5; ++i)
286 oss << 10 + z <<
".5." << 10 + i <<
".0";
287 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
288 for (uint32_t j = 0; j < nLANClients; ++j)
290 Ptr<Node> node = CreateObject<Node> (z % systemCount);
291 nodes_net3LAN[z][i][j].Add (node);
292 stack.Install (nodes_net3LAN[z][i][j]);
293 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
294 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
295 ifs3LAN[z][i][j] =
address.Assign (ndc3LAN[i][j]);
298 RANK0COUT (
" Connecting Subnets..." << std::endl);
300 Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
301 Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
302 nodes_netLR[z].Add (node1);
303 nodes_netLR[z].Add (node2);
304 stack.Install (nodes_netLR[z]);
306 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
308 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
309 net0_4.
Add (nodes_netLR[z].Get (0));
310 net0_4.
Add (nodes_net0[z][0].Get (0));
311 net0_5.
Add (nodes_netLR[z].Get (1));
312 net0_5.
Add (nodes_net0[z][1].Get (0));
313 net2_4a.
Add (nodes_netLR[z].Get (0));
314 net2_4a.
Add (nodes_net2[z][0].Get (0));
315 net2_4b.
Add (nodes_netLR[z].Get (1));
316 net2_4b.
Add (nodes_net2[z][1].Get (0));
317 net3_5a.
Add (nodes_netLR[z].Get (1));
318 net3_5a.
Add (nodes_net3[z][0].Get (0));
319 net3_5b.
Add (nodes_netLR[z].Get (1));
320 net3_5b.
Add (nodes_net3[z][1].Get (0));
322 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
324 oss << 10 + z <<
".1.253.0";
325 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
327 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
329 oss << 10 + z <<
".1.254.0";
330 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
332 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
334 oss << 10 + z <<
".4.253.0";
335 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
336 ifs =
address.Assign (ndc2_4a);
337 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
339 oss << 10 + z <<
".4.254.0";
340 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
341 ifs =
address.Assign (ndc2_4b);
342 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
344 oss << 10 + z <<
".5.253.0";
345 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
346 ifs =
address.Assign (ndc3_5a);
347 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
349 oss << 10 + z <<
".5.254.0";
350 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
351 ifs =
address.Assign (ndc3_5b);
353 RANK0COUT (
" Assigning IP addresses..." << std::endl);
354 for (
int i = 0; i < 3; ++i)
357 oss << 10 + z <<
".1." << 1 + i <<
".0";
358 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
359 ifs0[z][i] =
address.Assign (ndc0[i]);
361 for (
int i = 0; i < 6; ++i)
368 oss << 10 + z <<
".2." << 1 + i <<
".0";
369 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
370 ifs1[z][i] =
address.Assign (ndc1[i]);
373 oss << 10 + z <<
".3.1.0";
374 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
376 for (
int i = 0; i < 14; ++i)
379 oss << 10 + z <<
".4." << 1 + i <<
".0";
380 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
381 ifs2[z][i] =
address.Assign (ndc2[i]);
383 for (
int i = 0; i < 9; ++i)
386 oss << 10 + z <<
".5." << 1 + i <<
".0";
387 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
388 ifs3[z][i] =
address.Assign (ndc3[i]);
394 RANK0COUT (
"Forming Ring Topology..." << std::endl);
395 vectorOfNodeContainer nodes_ring(nCN);
396 for (uint32_t z = 0; z < nCN - 1; ++z)
398 nodes_ring[z].Add (nodes_net0[z][0].Get (0));
399 nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
401 nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
402 nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
403 vectorOfNetDeviceContainer ndc_ring(nCN);
404 for (uint32_t z = 0; z < nCN; ++z)
406 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
408 oss <<
"254.1." << z + 1 <<
".0";
409 address.SetBase (oss.str ().c_str (),
"255.255.255.0");
410 ifs =
address.Assign (ndc_ring[z]);
415 RANK0COUT (
"Creating UDP Traffic Flows:" << std::endl);
419 StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
421 StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
426 if (systemCount == 1)
440 RANK0COUT (
"Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl);
441 client.SetAttribute (
"Remote", remoteAddress);
444 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
447 else if (systemId == 1)
453 sinkHelper.Install (nodes_net1[1][0].Get (0));
460 else if (systemId == 0)
466 RANK0COUT (
"Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl);
467 client.SetAttribute (
"Remote", remoteAddress);
470 clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
479 for (uint32_t z = 0; z < nCN; ++z)
487 RANK0COUT (
" Campus Network " << z <<
" Flows [ Net2 ");
488 for (
int i = 0; i < 7; ++i)
490 for (uint32_t j = 0; j < nLANClients; ++j)
493 if (systemCount == 1)
496 (
"ns3::UdpSocketFactory",
500 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
508 else if (systemId == z % systemCount)
511 (
"ns3::UdpSocketFactory",
515 sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
524 if (systemCount == 1)
526 r1 = 2 + (int)(4 * urng->
GetValue ());
533 client.SetAttribute (
"Remote", remoteAddress);
535 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
538 else if (systemId ==
x % systemCount)
540 r1 = 2 + (int)(4 * urng->
GetValue ());
547 client.SetAttribute (
"Remote", remoteAddress);
549 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
556 for (
int i = 0; i < 5; ++i)
558 for (uint32_t j = 0; j < nLANClients; ++j)
561 if (systemCount == 1)
564 (
"ns3::UdpSocketFactory",
568 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
575 else if (systemId == z % systemCount)
578 (
"ns3::UdpSocketFactory",
582 sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
591 if (systemCount == 1)
593 r1 = 2 + (int)(4 * urng->
GetValue ());
600 client.SetAttribute (
"Remote", remoteAddress);
602 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
605 else if (systemId ==
x % systemCount)
607 r1 = 2 + (int)(4 * urng->
GetValue ());
614 client.SetAttribute (
"Remote", remoteAddress);
616 clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
630 RANK0COUT (
"Using Nix-vectors..." << std::endl);
635 RANK0COUT (
"Populating Routing tables..." << std::endl);
642 RANK0COUT (
"Routing tables population took "
646 RANK0COUT (
"Running simulator..." << std::endl);
651 RANK0COUT (
"Simulator finished." << std::endl);
656 const int numberNodesSending = nCN * ( nLANClients * (7 + 5));
657 const int expectedPacketCount = numberNodesSending * nPackets;
a polymophic address class
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
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.
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...
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny(void)
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static uint32_t GetSystemId()
Get the id number of this rank.
static uint32_t GetSize()
Get the number of ranks used by ns-3.
static void Disable()
Clean up the ns-3 parallel communications interface.
static void Enable(int *pargc, char ***pargv)
Setup the parallel communication interface.
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 Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetNNodes(void)
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
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 void Run(void)
Run the simulation.
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
static void Init(void)
PacketSink Init.
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
Hold variables of type string.
Measure elapsed wall clock time in milliseconds.
void Start(void)
Start a measure.
int64_t End(void)
Stop measuring the time since Start() was called.
int64_t GetElapsedReal(void) const
Simulation virtual time values and global simulation resolution.
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.
#define RANK0COUT(x)
Write to std::cout only from rank 0.
#define RANK0COUTAPPEND(x)
Append to std::cout only from rank 0.
Time Seconds(double value)
Construct a Time in the indicated unit.
Common methods for MPI examples.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
list x
Random number samples.