42 #include "ns3/core-module.h"
43 #include "ns3/internet-module.h"
44 #include "ns3/mpi-interface.h"
45 #include "ns3/network-module.h"
46 #include "ns3/nix-vector-helper.h"
47 #include "ns3/on-off-helper.h"
48 #include "ns3/packet-sink-helper.h"
49 #include "ns3/point-to-point-helper.h"
59 main(
int argc,
char* argv[])
61 typedef std::vector<NodeContainer> vectorOfNodeContainer;
62 typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
63 typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
65 typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
66 typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
67 typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer>
68 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);
114 RANK0COUT(
"Number of total CNs (" << nCN <<
") lower than minimum of 2" << std::endl);
117 if (systemCount > nCN)
119 RANK0COUT(
"Number of total CNs (" << nCN <<
") should be >= systemCount (" << systemCount
120 <<
")." << std::endl);
124 RANK0COUT(
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl);
126 vectorOfNodeContainer nodes_netLR(nCN);
127 vectorOfVectorOfNodeContainer nodes_net0(nCN, vectorOfNodeContainer(3));
128 vectorOfVectorOfNodeContainer nodes_net1(nCN, vectorOfNodeContainer(6));
129 vectorOfVectorOfNodeContainer nodes_net2(nCN, vectorOfNodeContainer(14));
130 vectorOfVectorOfNodeContainer nodes_net3(nCN, vectorOfNodeContainer(9));
132 vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(
134 vectorOfVectorOfNodeContainer(7, vectorOfNodeContainer(nLANClients)));
135 vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(
137 vectorOfVectorOfNodeContainer(5, vectorOfNodeContainer(nLANClients)));
146 vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN, vectorOfIpv4InterfaceContainer(3));
147 vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN, vectorOfIpv4InterfaceContainer(6));
148 vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN, vectorOfIpv4InterfaceContainer(14));
149 vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN, vectorOfIpv4InterfaceContainer(9));
150 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(
152 vectorOfVectorOfIpv4InterfaceContainer(7, vectorOfIpv4InterfaceContainer(nLANClients)));
153 vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(
155 vectorOfVectorOfIpv4InterfaceContainer(5, vectorOfIpv4InterfaceContainer(nLANClients)));
158 std::ostringstream oss;
173 for (uint32_t z = 0; z < nCN; ++z)
175 RANK0COUT(
"Creating Campus Network " << z <<
":" << std::endl);
178 for (
int i = 0; i < 3; ++i)
180 Ptr<Node> node = CreateObject<Node>(z % systemCount);
181 nodes_net0[z][i].Add(node);
182 stack.Install(nodes_net0[z][i]);
184 nodes_net0[z][0].Add(nodes_net0[z][1].Get(0));
185 nodes_net0[z][1].Add(nodes_net0[z][2].Get(0));
186 nodes_net0[z][2].Add(nodes_net0[z][0].Get(0));
188 for (
int i = 0; i < 3; ++i)
190 ndc0[i] = p2p_1gb5ms.
Install(nodes_net0[z][i]);
194 for (
int i = 0; i < 6; ++i)
196 Ptr<Node> node = CreateObject<Node>(z % systemCount);
197 nodes_net1[z][i].Add(node);
198 stack.Install(nodes_net1[z][i]);
200 nodes_net1[z][0].Add(nodes_net1[z][1].Get(0));
201 nodes_net1[z][2].Add(nodes_net1[z][0].Get(0));
202 nodes_net1[z][3].Add(nodes_net1[z][0].Get(0));
203 nodes_net1[z][4].Add(nodes_net1[z][1].Get(0));
204 nodes_net1[z][5].Add(nodes_net1[z][1].Get(0));
206 for (
int i = 0; i < 6; ++i)
212 ndc1[i] = p2p_1gb5ms.
Install(nodes_net1[z][i]);
216 net0_1.
Add(nodes_net0[z][2].Get(0));
217 net0_1.
Add(nodes_net1[z][0].Get(0));
219 ndc0_1 = p2p_1gb5ms.
Install(net0_1);
221 oss << 10 + z <<
".1.252.0";
222 address.SetBase(oss.str().c_str(),
"255.255.255.0");
226 for (
int i = 0; i < 14; ++i)
228 Ptr<Node> node = CreateObject<Node>(z % systemCount);
229 nodes_net2[z][i].Add(node);
230 stack.Install(nodes_net2[z][i]);
232 nodes_net2[z][0].Add(nodes_net2[z][1].Get(0));
233 nodes_net2[z][2].Add(nodes_net2[z][0].Get(0));
234 nodes_net2[z][1].Add(nodes_net2[z][3].Get(0));
235 nodes_net2[z][3].Add(nodes_net2[z][2].Get(0));
236 nodes_net2[z][4].Add(nodes_net2[z][2].Get(0));
237 nodes_net2[z][5].Add(nodes_net2[z][3].Get(0));
238 nodes_net2[z][6].Add(nodes_net2[z][5].Get(0));
239 nodes_net2[z][7].Add(nodes_net2[z][2].Get(0));
240 nodes_net2[z][8].Add(nodes_net2[z][3].Get(0));
241 nodes_net2[z][9].Add(nodes_net2[z][4].Get(0));
242 nodes_net2[z][10].Add(nodes_net2[z][5].Get(0));
243 nodes_net2[z][11].Add(nodes_net2[z][6].Get(0));
244 nodes_net2[z][12].Add(nodes_net2[z][6].Get(0));
245 nodes_net2[z][13].Add(nodes_net2[z][6].Get(0));
247 for (
int i = 0; i < 14; ++i)
249 ndc2[i] = p2p_1gb5ms.
Install(nodes_net2[z][i]);
251 vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
252 for (
int i = 0; i < 7; ++i)
255 oss << 10 + z <<
".4." << 15 + i <<
".0";
256 address.SetBase(oss.str().c_str(),
"255.255.255.0");
257 for (uint32_t j = 0; j < nLANClients; ++j)
259 Ptr<Node> node = CreateObject<Node>(z % systemCount);
260 nodes_net2LAN[z][i][j].Add(node);
261 stack.Install(nodes_net2LAN[z][i][j]);
262 nodes_net2LAN[z][i][j].Add(nodes_net2[z][i + 7].Get(0));
263 ndc2LAN[i][j] = p2p_100mb1ms.
Install(nodes_net2LAN[z][i][j]);
264 ifs2LAN[z][i][j] =
address.Assign(ndc2LAN[i][j]);
269 for (
int i = 0; i < 9; ++i)
271 Ptr<Node> node = CreateObject<Node>(z % systemCount);
272 nodes_net3[z][i].Add(node);
273 stack.Install(nodes_net3[z][i]);
275 nodes_net3[z][0].Add(nodes_net3[z][1].Get(0));
276 nodes_net3[z][1].Add(nodes_net3[z][2].Get(0));
277 nodes_net3[z][2].Add(nodes_net3[z][3].Get(0));
278 nodes_net3[z][3].Add(nodes_net3[z][1].Get(0));
279 nodes_net3[z][4].Add(nodes_net3[z][0].Get(0));
280 nodes_net3[z][5].Add(nodes_net3[z][0].Get(0));
281 nodes_net3[z][6].Add(nodes_net3[z][2].Get(0));
282 nodes_net3[z][7].Add(nodes_net3[z][3].Get(0));
283 nodes_net3[z][8].Add(nodes_net3[z][3].Get(0));
285 for (
int i = 0; i < 9; ++i)
287 ndc3[i] = p2p_1gb5ms.
Install(nodes_net3[z][i]);
289 vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
290 for (
int i = 0; i < 5; ++i)
293 oss << 10 + z <<
".5." << 10 + i <<
".0";
294 address.SetBase(oss.str().c_str(),
"255.255.255.0");
295 for (uint32_t j = 0; j < nLANClients; ++j)
297 Ptr<Node> node = CreateObject<Node>(z % systemCount);
298 nodes_net3LAN[z][i][j].Add(node);
299 stack.Install(nodes_net3LAN[z][i][j]);
300 nodes_net3LAN[z][i][j].Add(nodes_net3[z][i + 4].Get(0));
301 ndc3LAN[i][j] = p2p_100mb1ms.
Install(nodes_net3LAN[z][i][j]);
302 ifs3LAN[z][i][j] =
address.Assign(ndc3LAN[i][j]);
305 RANK0COUT(
" Connecting Subnets..." << std::endl);
307 Ptr<Node> node1 = CreateObject<Node>(z % systemCount);
308 Ptr<Node> node2 = CreateObject<Node>(z % systemCount);
309 nodes_netLR[z].Add(node1);
310 nodes_netLR[z].Add(node2);
311 stack.Install(nodes_netLR[z]);
313 ndcLR = p2p_1gb5ms.
Install(nodes_netLR[z]);
321 net0_4.
Add(nodes_netLR[z].Get(0));
322 net0_4.
Add(nodes_net0[z][0].Get(0));
323 net0_5.
Add(nodes_netLR[z].Get(1));
324 net0_5.
Add(nodes_net0[z][1].Get(0));
325 net2_4a.
Add(nodes_netLR[z].Get(0));
326 net2_4a.
Add(nodes_net2[z][0].Get(0));
327 net2_4b.
Add(nodes_netLR[z].Get(1));
328 net2_4b.
Add(nodes_net2[z][1].Get(0));
329 net3_5a.
Add(nodes_netLR[z].Get(1));
330 net3_5a.
Add(nodes_net3[z][0].Get(0));
331 net3_5b.
Add(nodes_netLR[z].Get(1));
332 net3_5b.
Add(nodes_net3[z][1].Get(0));
339 ndc0_4 = p2p_1gb5ms.
Install(net0_4);
341 oss << 10 + z <<
".1.253.0";
342 address.SetBase(oss.str().c_str(),
"255.255.255.0");
344 ndc0_5 = p2p_1gb5ms.
Install(net0_5);
346 oss << 10 + z <<
".1.254.0";
347 address.SetBase(oss.str().c_str(),
"255.255.255.0");
349 ndc2_4a = p2p_1gb5ms.
Install(net2_4a);
351 oss << 10 + z <<
".4.253.0";
352 address.SetBase(oss.str().c_str(),
"255.255.255.0");
354 ndc2_4b = p2p_1gb5ms.
Install(net2_4b);
356 oss << 10 + z <<
".4.254.0";
357 address.SetBase(oss.str().c_str(),
"255.255.255.0");
359 ndc3_5a = p2p_1gb5ms.
Install(net3_5a);
361 oss << 10 + z <<
".5.253.0";
362 address.SetBase(oss.str().c_str(),
"255.255.255.0");
364 ndc3_5b = p2p_1gb5ms.
Install(net3_5b);
366 oss << 10 + z <<
".5.254.0";
367 address.SetBase(oss.str().c_str(),
"255.255.255.0");
370 RANK0COUT(
" Assigning IP addresses..." << std::endl);
371 for (
int i = 0; i < 3; ++i)
374 oss << 10 + z <<
".1." << 1 + i <<
".0";
375 address.SetBase(oss.str().c_str(),
"255.255.255.0");
376 ifs0[z][i] =
address.Assign(ndc0[i]);
378 for (
int i = 0; i < 6; ++i)
385 oss << 10 + z <<
".2." << 1 + i <<
".0";
386 address.SetBase(oss.str().c_str(),
"255.255.255.0");
387 ifs1[z][i] =
address.Assign(ndc1[i]);
390 oss << 10 + z <<
".3.1.0";
391 address.SetBase(oss.str().c_str(),
"255.255.255.0");
393 for (
int i = 0; i < 14; ++i)
396 oss << 10 + z <<
".4." << 1 + i <<
".0";
397 address.SetBase(oss.str().c_str(),
"255.255.255.0");
398 ifs2[z][i] =
address.Assign(ndc2[i]);
400 for (
int i = 0; i < 9; ++i)
403 oss << 10 + z <<
".5." << 1 + i <<
".0";
404 address.SetBase(oss.str().c_str(),
"255.255.255.0");
405 ifs3[z][i] =
address.Assign(ndc3[i]);
411 RANK0COUT(
"Forming Ring Topology..." << std::endl);
412 vectorOfNodeContainer nodes_ring(nCN);
413 for (uint32_t z = 0; z < nCN - 1; ++z)
415 nodes_ring[z].Add(nodes_net0[z][0].Get(0));
416 nodes_ring[z].Add(nodes_net0[z + 1][0].Get(0));
418 nodes_ring[nCN - 1].Add(nodes_net0[nCN - 1][0].Get(0));
419 nodes_ring[nCN - 1].Add(nodes_net0[0][0].Get(0));
420 vectorOfNetDeviceContainer ndc_ring(nCN);
421 for (uint32_t z = 0; z < nCN; ++z)
423 ndc_ring[z] = p2p_2gb200ms.
Install(nodes_ring[z]);
425 oss <<
"254.1." << z + 1 <<
".0";
426 address.SetBase(oss.str().c_str(),
"255.255.255.0");
427 ifs =
address.Assign(ndc_ring[z]);
432 RANK0COUT(
"Creating UDP Traffic Flows:" << std::endl);
435 StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
437 StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
441 if (systemCount == 1)
455 RANK0COUT(
"Remote Address is " << ifs1[0][2].GetAddress(0) << std::endl);
459 clientApp.
Add(
client.Install(nodes_net2LAN[0][0][0].Get(0)));
462 else if (systemId == 1)
474 else if (systemId == 0)
479 RANK0COUT(
"Remote Address is " << ifs1[1][0].GetAddress(0) << std::endl);
483 clientApp.
Add(
client.Install(nodes_net2LAN[0][0][0].Get(0)));
492 for (uint32_t z = 0; z < nCN; ++z)
500 RANK0COUT(
" Campus Network " << z <<
" Flows [ Net2 ");
501 for (
int i = 0; i < 7; ++i)
503 for (uint32_t j = 0; j < nLANClients; ++j)
506 if (systemCount == 1)
512 sinkHelper.Install(nodes_net2LAN[z][i][j].Get(0));
522 else if (systemId == z % systemCount)
528 sinkHelper.Install(nodes_net2LAN[z][i][j].Get(0));
539 if (systemCount == 1)
541 r1 = 2 + (int)(4 * urng->
GetValue());
550 clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
553 else if (systemId ==
x % systemCount)
555 r1 = 2 + (int)(4 * urng->
GetValue());
564 clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
571 for (
int i = 0; i < 5; ++i)
573 for (uint32_t j = 0; j < nLANClients; ++j)
576 if (systemCount == 1)
582 sinkHelper.Install(nodes_net3LAN[z][i][j].Get(0));
591 else if (systemId == z % systemCount)
597 sinkHelper.Install(nodes_net3LAN[z][i][j].Get(0));
608 if (systemCount == 1)
610 r1 = 2 + (int)(4 * urng->
GetValue());
619 clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
622 else if (systemId ==
x % systemCount)
624 r1 = 2 + (int)(4 * urng->
GetValue());
633 clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
648 RANK0COUT(
"Using Nix-vectors..." << std::endl);
653 RANK0COUT(
"Populating Routing tables..." << std::endl);
664 RANK0COUT(
"Running simulator..." << std::endl);
669 RANK0COUT(
"Simulator finished." << std::endl);
674 const int numberNodesSending =
675 nCN * (nLANClients * (7 + 5));
676 const int expectedPacketCount = numberNodesSending * nPackets;
691 <<
"Total elapsed time: " << t0.
GetElapsedReal() <<
"ms" << std::endl);
a polymophic address class
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
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()
static void PopulateRoutingTables()
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(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetNNodes()
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 Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
static void Init()
PacketSink Init.
Hold variables of type string.
Measure elapsed wall clock time in milliseconds.
int64_t End()
Stop measuring the time since Start() was called.
int64_t GetElapsedReal() const
void Start()
Start a measure.
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, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...