41 #include "ns3/core-module.h"
42 #include "ns3/internet-module.h"
43 #include "ns3/network-module.h"
44 #include "ns3/on-off-helper.h"
45 #include "ns3/packet-sink-helper.h"
46 #include "ns3/point-to-point-helper.h"
47 #include "ns3/mpi-interface.h"
48 #include "ns3/ipv4-static-routing-helper.h"
49 #include "ns3/ipv4-list-routing-helper.h"
50 #include "ns3/ipv4-nix-vector-helper.h"
59 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
60 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec * 1e-6)
61 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1) - TIMER_SECONDS (_t2))
71 main (
int argc,
char *argv[])
79 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
89 #define nLANClients (42)
98 cmd.
AddValue (
"single",
"1 if use single flow", single);
99 cmd.
AddValue (
"nBytes",
"Number of bytes for each on/off app", nBytes);
100 cmd.
AddValue (
"nix",
"Toggle the use of nix-vector or global routing", nix);
101 cmd.
Parse (argc,argv);
105 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
109 if (systemCount > nCN)
111 std::cout <<
"Number of total CNs (" << nCN <<
") should be >= systemCount ("
112 << systemCount <<
")." << std::endl;
116 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
118 NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
119 nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
120 nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
124 ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
125 ifs3LAN[nCN][5][nLANClients];
127 std::ostringstream oss;
139 list.
Add (staticRouting, 0);
140 list.
Add (nixRouting, 10);
148 for (uint32_t z = 0; z < nCN; ++z)
150 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
152 std::cout <<
" SubNet [ 0";
153 for (
int i = 0; i < 3; ++i)
155 Ptr<Node> node = CreateObject<Node> (z % systemCount);
156 nodes_net0[z][i].
Add (node);
157 stack.
Install (nodes_net0[z][i]);
159 nodes_net0[z][0].
Add (nodes_net0[z][1].Get (0));
160 nodes_net0[z][1].
Add (nodes_net0[z][2].Get (0));
161 nodes_net0[z][2].
Add (nodes_net0[z][0].Get (0));
163 for (
int i = 0; i < 3; ++i)
165 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
169 for (
int i = 0; i < 6; ++i)
171 Ptr<Node> node = CreateObject<Node> (z % systemCount);
172 nodes_net1[z][i].
Add (node);
173 stack.
Install (nodes_net1[z][i]);
175 nodes_net1[z][0].
Add (nodes_net1[z][1].Get (0));
176 nodes_net1[z][2].
Add (nodes_net1[z][0].Get (0));
177 nodes_net1[z][3].
Add (nodes_net1[z][0].Get (0));
178 nodes_net1[z][4].
Add (nodes_net1[z][1].Get (0));
179 nodes_net1[z][5].
Add (nodes_net1[z][1].Get (0));
181 for (
int i = 0; i < 6; ++i)
187 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
191 net0_1.
Add (nodes_net0[z][2].Get (0));
192 net0_1.
Add (nodes_net1[z][0].Get (0));
194 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
196 oss << 10 + z <<
".1.252.0";
197 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
198 ifs = address.
Assign (ndc0_1);
201 for (
int i = 0; i < 14; ++i)
203 Ptr<Node> node = CreateObject<Node> (z % systemCount);
204 nodes_net2[z][i].
Add (node);
205 stack.
Install (nodes_net2[z][i]);
207 nodes_net2[z][0].
Add (nodes_net2[z][1].Get (0));
208 nodes_net2[z][2].
Add (nodes_net2[z][0].Get (0));
209 nodes_net2[z][1].
Add (nodes_net2[z][3].Get (0));
210 nodes_net2[z][3].
Add (nodes_net2[z][2].Get (0));
211 nodes_net2[z][4].
Add (nodes_net2[z][2].Get (0));
212 nodes_net2[z][5].
Add (nodes_net2[z][3].Get (0));
213 nodes_net2[z][6].
Add (nodes_net2[z][5].Get (0));
214 nodes_net2[z][7].
Add (nodes_net2[z][2].Get (0));
215 nodes_net2[z][8].
Add (nodes_net2[z][3].Get (0));
216 nodes_net2[z][9].
Add (nodes_net2[z][4].Get (0));
217 nodes_net2[z][10].
Add (nodes_net2[z][5].Get (0));
218 nodes_net2[z][11].
Add (nodes_net2[z][6].Get (0));
219 nodes_net2[z][12].
Add (nodes_net2[z][6].Get (0));
220 nodes_net2[z][13].
Add (nodes_net2[z][6].Get (0));
222 for (
int i = 0; i < 14; ++i)
224 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
227 for (
int i = 0; i < 7; ++i)
230 oss << 10 + z <<
".4." << 15 + i <<
".0";
231 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
232 for (uint32_t j = 0; j < nLANClients; ++j)
234 Ptr<Node> node = CreateObject<Node> (z % systemCount);
235 nodes_net2LAN[z][i][j].
Add (node);
236 stack.
Install (nodes_net2LAN[z][i][j]);
237 nodes_net2LAN[z][i][j].
Add (nodes_net2[z][i + 7].Get (0));
238 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
239 ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
243 std::cout <<
" 3 ]" << std::endl;
244 for (
int i = 0; i < 9; ++i)
246 Ptr<Node> node = CreateObject<Node> (z % systemCount);
247 nodes_net3[z][i].
Add (node);
248 stack.
Install (nodes_net3[z][i]);
250 nodes_net3[z][0].
Add (nodes_net3[z][1].Get (0));
251 nodes_net3[z][1].
Add (nodes_net3[z][2].Get (0));
252 nodes_net3[z][2].
Add (nodes_net3[z][3].Get (0));
253 nodes_net3[z][3].
Add (nodes_net3[z][1].Get (0));
254 nodes_net3[z][4].
Add (nodes_net3[z][0].Get (0));
255 nodes_net3[z][5].
Add (nodes_net3[z][0].Get (0));
256 nodes_net3[z][6].
Add (nodes_net3[z][2].Get (0));
257 nodes_net3[z][7].
Add (nodes_net3[z][3].Get (0));
258 nodes_net3[z][8].
Add (nodes_net3[z][3].Get (0));
260 for (
int i = 0; i < 9; ++i)
262 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
265 for (
int i = 0; i < 5; ++i)
268 oss << 10 + z <<
".5." << 10 + i <<
".0";
269 address.
SetBase (oss.str ().c_str (),
"255.255.255.255");
270 for (uint32_t j = 0; j < nLANClients; ++j)
272 Ptr<Node> node = CreateObject<Node> (z % systemCount);
273 nodes_net3LAN[z][i][j].
Add (node);
274 stack.
Install (nodes_net3LAN[z][i][j]);
275 nodes_net3LAN[z][i][j].
Add (nodes_net3[z][i + 4].Get (0));
276 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
277 ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
280 std::cout <<
" Connecting Subnets..." << std::endl;
282 Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
283 Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
284 nodes_netLR[z].
Add (node1);
285 nodes_netLR[z].
Add (node2);
286 stack.
Install (nodes_netLR[z]);
288 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
290 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
291 net0_4.
Add (nodes_netLR[z].Get (0));
292 net0_4.
Add (nodes_net0[z][0].Get (0));
293 net0_5.
Add (nodes_netLR[z].Get (1));
294 net0_5.
Add (nodes_net0[z][1].Get (0));
295 net2_4a.
Add (nodes_netLR[z].Get (0));
296 net2_4a.
Add (nodes_net2[z][0].Get (0));
297 net2_4b.
Add (nodes_netLR[z].Get (1));
298 net2_4b.
Add (nodes_net2[z][1].Get (0));
299 net3_5a.
Add (nodes_netLR[z].Get (1));
300 net3_5a.
Add (nodes_net3[z][0].Get (0));
301 net3_5b.
Add (nodes_netLR[z].Get (1));
302 net3_5b.
Add (nodes_net3[z][1].Get (0));
304 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
306 oss << 10 + z <<
".1.253.0";
307 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
308 ifs = address.
Assign (ndc0_4);
309 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
311 oss << 10 + z <<
".1.254.0";
312 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
313 ifs = address.
Assign (ndc0_5);
314 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
316 oss << 10 + z <<
".4.253.0";
317 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
318 ifs = address.
Assign (ndc2_4a);
319 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
321 oss << 10 + z <<
".4.254.0";
322 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
323 ifs = address.
Assign (ndc2_4b);
324 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
326 oss << 10 + z <<
".5.253.0";
327 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
328 ifs = address.
Assign (ndc3_5a);
329 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
331 oss << 10 + z <<
".5.254.0";
332 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
333 ifs = address.
Assign (ndc3_5b);
335 std::cout <<
" Assigning IP addresses..." << std::endl;
336 for (
int i = 0; i < 3; ++i)
339 oss << 10 + z <<
".1." << 1 + i <<
".0";
340 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
341 ifs0[z][i] = address.
Assign (ndc0[i]);
343 for (
int i = 0; i < 6; ++i)
350 oss << 10 + z <<
".2." << 1 + i <<
".0";
351 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
352 ifs1[z][i] = address.
Assign (ndc1[i]);
355 oss << 10 + z <<
".3.1.0";
356 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
357 ifs = address.
Assign (ndcLR);
358 for (
int i = 0; i < 14; ++i)
361 oss << 10 + z <<
".4." << 1 + i <<
".0";
362 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
363 ifs2[z][i] = address.
Assign (ndc2[i]);
365 for (
int i = 0; i < 9; ++i)
368 oss << 10 + z <<
".5." << 1 + i <<
".0";
369 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
370 ifs3[z][i] = address.
Assign (ndc3[i]);
376 std::cout <<
"Forming Ring Topology..." << std::endl;
378 for (uint32_t z = 0; z < nCN - 1; ++z)
380 nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
381 nodes_ring[z].
Add (nodes_net0[z + 1][0].Get (0));
383 nodes_ring[nCN - 1].
Add (nodes_net0[nCN - 1][0].Get (0));
384 nodes_ring[nCN - 1].
Add (nodes_net0[0][0].Get (0));
386 for (uint32_t z = 0; z < nCN; ++z)
388 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
390 oss <<
"254.1." << z + 1 <<
".0";
391 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
392 ifs = address.
Assign (ndc_ring[z]);
397 std::cout <<
"Creating UDP Traffic Flows:" << std::endl;
401 StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
403 StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
408 if (systemCount == 1)
414 sinkApp.
Start (Seconds (0.0));
418 std::cout <<
"Remote Address is " << ifs1[0][2].
GetAddress (0) << std::endl;
422 clientApp.
Add (client.
Install (nodes_net2LAN[0][0][0].
Get (0)));
423 clientApp.
Start (Seconds (0));
425 else if (systemId == 1)
431 sinkHelper.
Install (nodes_net1[1][0].Get (0));
433 sinkApp.
Start (Seconds (0.0));
435 else if (systemId == 0)
441 std::cout <<
"Remote Address is " << ifs1[1][0].
GetAddress (0) << std::endl;
445 clientApp.
Add (client.
Install (nodes_net2LAN[0][0][0].
Get (0)));
446 clientApp.
Start (Seconds (0));
454 for (uint32_t z = 0; z < nCN; ++z)
462 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
463 for (
int i = 0; i < 7; ++i)
465 for (uint32_t j = 0; j < nLANClients; ++j)
468 if (systemCount == 1)
471 (
"ns3::UdpSocketFactory",
475 sinkHelper.
Install (nodes_net2LAN[z][i][j].Get (0));
477 sinkApp.
Start (Seconds (0.0));
479 else if (systemId == z % systemCount)
482 (
"ns3::UdpSocketFactory",
486 sinkHelper.
Install (nodes_net2LAN[z][i][j].Get (0));
488 sinkApp.
Start (Seconds (0.0));
491 if (systemCount == 1)
493 r1 = 2 + (int)(4 * urng->
GetValue ());
503 clientApp.
Start (Seconds (r2));
505 else if (systemId == x % systemCount)
507 r1 = 2 + (int)(4 * urng->
GetValue ());
517 clientApp.
Start (Seconds (r2));
522 std::cout <<
"Net3 ]" << std::endl;
523 for (
int i = 0; i < 5; ++i)
525 for (uint32_t j = 0; j < nLANClients; ++j)
528 if (systemCount == 1)
531 (
"ns3::UdpSocketFactory",
535 sinkHelper.
Install (nodes_net3LAN[z][i][j].Get (0));
537 sinkApp.
Start (Seconds (0.0));
539 else if (systemId == z % systemCount)
542 (
"ns3::UdpSocketFactory",
546 sinkHelper.
Install (nodes_net3LAN[z][i][j].Get (0));
548 sinkApp.
Start (Seconds (0.0));
551 if (systemCount == 1)
553 r1 = 2 + (int)(4 * urng->
GetValue ());
563 clientApp.
Start (Seconds (r2));
565 else if (systemId == x % systemCount)
567 r1 = 2 + (int)(4 * urng->
GetValue ());
577 clientApp.
Start (Seconds (r2));
590 std::cout <<
"Using Nix-vectors..." << std::endl;
595 std::cout <<
"Populating Routing tables..." << std::endl;
601 std::cout <<
"Routing tables population took "
602 <<
TIMER_DIFF (routingEnd, routingStart) << std::endl;
604 std::cout <<
"Running simulator..." << std::endl;
609 std::cout <<
"Simulator finished." << std::endl;
614 std::cout <<
"-----" << std::endl <<
"Runtime Stats:" << std::endl;
615 std::cout <<
"Simulator init time: " << d1 << std::endl;
616 std::cout <<
"Simulator run time: " << d2 << std::endl;
617 std::cout <<
"Total elapsed time: " << d1 + d2 << std::endl;
620 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. Makes all nodes in the simulation into routers.
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. ...
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing 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)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
static void Enable(int *pargc, char ***pargv)
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)
void SetDefault(std::string name, const AttributeValue &value)
keep track of a set of node pointers.
void Install(std::string nodeName) const
#define TIMER_DIFF(_t1, _t2)
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
void SetChannelAttribute(std::string name, const AttributeValue &value)
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.
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
int main(int argc, char *argv[])
static uint32_t GetSystemId()
Helper class that adds ns3::Ipv4StaticRouting objects.
void AddValue(const std::string &name, const std::string &help, T &value)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Helper class that adds ns3::Ipv4ListRouting objects.
ApplicationContainer Install(NodeContainer c) const
void Parse(int argc, char *argv[])
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
ApplicationContainer Install(NodeContainer c) const
static uint32_t GetSize()
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const