39 #include "ns3/core-module.h"
40 #include "ns3/internet-module.h"
41 #include "ns3/network-module.h"
42 #include "ns3/point-to-point-module.h"
43 #include "ns3/applications-module.h"
44 #include "ns3/onoff-application.h"
45 #include "ns3/packet-sink.h"
46 #include "ns3/simulator.h"
47 #include "ns3/ipv4-nix-vector-helper.h"
52 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
53 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
54 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1)-TIMER_SECONDS (_t2))
77 p (new T*[x]), m_xMax (x)
79 for (
size_t i = 0; i < m_xMax; i++)
85 for (
size_t i = 0; i < m_xMax; i++)
96 T* operator[] (
const size_t i)
109 template <
typename T>
119 Array3D (
const size_t x,
const size_t y,
const size_t z) : p (new
Array2D<T>*[x]), m_xMax (x)
121 for (
size_t i = 0; i < m_xMax; i++)
127 for (
size_t i = 0; i < m_xMax; i++)
151 main (
int argc,
char *argv[])
155 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
158 int nCN = 2, nLANClients = 42;
162 cmd.
AddValue (
"CN",
"Number of total CNs [2]", nCN);
163 cmd.
AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
164 cmd.
AddValue (
"NIX",
"Toggle nix-vector routing", nix);
165 cmd.
Parse (argc,argv);
169 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
174 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
195 std::ostringstream oss;
211 for (
int z = 0; z < nCN; ++z)
213 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
215 std::cout <<
" SubNet [ 0";
216 for (
int i = 0; i < 3; ++i)
218 nodes_net0[z][i].Create (1);
219 stack.
Install (nodes_net0[z][i]);
221 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
222 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
223 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
225 for (
int i = 0; i < 3; ++i)
227 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
231 for (
int i = 0; i < 6; ++i)
233 nodes_net1[z][i].Create (1);
234 stack.
Install (nodes_net1[z][i]);
236 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
237 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
238 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
239 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
240 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
242 for (
int i = 0; i < 6; ++i)
248 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
252 net0_1.
Add (nodes_net0[z][2].Get (0));
253 net0_1.
Add (nodes_net1[z][0].Get (0));
255 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
257 oss << 10 + z <<
".1.252.0";
258 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
259 ifs = address.
Assign (ndc0_1);
262 for (
int i = 0; i < 14; ++i)
264 nodes_net2[z][i].Create (1);
265 stack.
Install (nodes_net2[z][i]);
267 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
268 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
269 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
270 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
271 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
272 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
273 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
274 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
275 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
276 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
277 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
278 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
279 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
280 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
282 for (
int i = 0; i < 14; ++i)
284 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
288 for (
int i = 0; i < 7; ++i)
291 oss << 10 + z <<
".4." << 15 + i <<
".0";
292 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
293 for (
int j = 0; j < nLANClients; ++j)
295 nodes_net2LAN[z][i][j].Create (1);
296 stack.
Install (nodes_net2LAN[z][i][j]);
297 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
298 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
299 ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
303 std::cout <<
" 3 ]" << std::endl;
304 for (
int i = 0; i < 9; ++i)
306 nodes_net3[z][i].Create (1);
307 stack.
Install (nodes_net3[z][i]);
309 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
310 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
311 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
312 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
313 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
314 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
315 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
316 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
317 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
319 for (
int i = 0; i < 9; ++i)
321 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
325 for (
int i = 0; i < 5; ++i)
328 oss << 10 + z <<
".5." << 10 + i <<
".0";
329 address.
SetBase (oss.str ().c_str (),
"255.255.255.255");
330 for (
int j = 0; j < nLANClients; ++j)
332 nodes_net3LAN[z][i][j].Create (1);
333 stack.
Install (nodes_net3LAN[z][i][j]);
334 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
335 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
336 ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
339 std::cout <<
" Connecting Subnets..." << std::endl;
341 nodes_netLR[z].
Create (2);
342 stack.
Install (nodes_netLR[z]);
344 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
346 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
347 net0_4.
Add (nodes_netLR[z].Get (0));
348 net0_4.
Add (nodes_net0[z][0].Get (0));
349 net0_5.
Add (nodes_netLR[z].Get (1));
350 net0_5.
Add (nodes_net0[z][1].Get (0));
351 net2_4a.
Add (nodes_netLR[z].Get (0));
352 net2_4a.
Add (nodes_net2[z][0].Get (0));
353 net2_4b.
Add (nodes_netLR[z].Get (1));
354 net2_4b.
Add (nodes_net2[z][1].Get (0));
355 net3_5a.
Add (nodes_netLR[z].Get (1));
356 net3_5a.
Add (nodes_net3[z][0].Get (0));
357 net3_5b.
Add (nodes_netLR[z].Get (1));
358 net3_5b.
Add (nodes_net3[z][1].Get (0));
360 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
362 oss << 10 + z <<
".1.253.0";
363 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
364 ifs = address.
Assign (ndc0_4);
365 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
367 oss << 10 + z <<
".1.254.0";
368 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
369 ifs = address.
Assign (ndc0_5);
370 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
372 oss << 10 + z <<
".4.253.0";
373 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
374 ifs = address.
Assign (ndc2_4a);
375 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
377 oss << 10 + z <<
".4.254.0";
378 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
379 ifs = address.
Assign (ndc2_4b);
380 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
382 oss << 10 + z <<
".5.253.0";
383 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
384 ifs = address.
Assign (ndc3_5a);
385 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
387 oss << 10 + z <<
".5.254.0";
388 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
389 ifs = address.
Assign (ndc3_5b);
391 std::cout <<
" Assigning IP addresses..." << std::endl;
392 for (
int i = 0; i < 3; ++i)
395 oss << 10 + z <<
".1." << 1 + i <<
".0";
396 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
397 ifs0[z][i] = address.
Assign (ndc0[i]);
399 for (
int i = 0; i < 6; ++i)
406 oss << 10 + z <<
".2." << 1 + i <<
".0";
407 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
408 ifs1[z][i] = address.
Assign (ndc1[i]);
411 oss << 10 + z <<
".3.1.0";
412 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
413 ifs = address.
Assign (ndcLR);
414 for (
int i = 0; i < 14; ++i)
417 oss << 10 + z <<
".4." << 1 + i <<
".0";
418 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
419 ifs2[z][i] = address.
Assign (ndc2[i]);
421 for (
int i = 0; i < 9; ++i)
424 oss << 10 + z <<
".5." << 1 + i <<
".0";
425 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
426 ifs3[z][i] = address.
Assign (ndc3[i]);
432 std::cout <<
"Forming Ring Topology..." << std::endl;
434 for (
int z = 0; z < nCN-1; ++z)
436 nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
437 nodes_ring[z].
Add (nodes_net0[z+1][0].Get (0));
439 nodes_ring[nCN-1].
Add (nodes_net0[nCN-1][0].Get (0));
440 nodes_ring[nCN-1].
Add (nodes_net0[0][0].Get (0));
442 for (
int z = 0; z < nCN; ++z)
444 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
446 oss <<
"254.1." << z + 1 <<
".0";
447 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
448 ifs = address.
Assign (ndc_ring[z]);
455 std::cout <<
"Creating TCP Traffic Flows:" << std::endl;
458 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"));
460 StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
466 for (
int z = 0; z < nCN; ++z)
474 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
475 for (
int i = 0; i < 7; ++i)
477 for (
int j = 0; j < nLANClients; ++j)
483 nodes_net2LAN[z][i][j].Get (0));
486 r1 = 2 + (int)(4 * urng->
GetValue ());
490 ifs2LAN[z][i][j].GetAddress (0), 9999));
491 client.SetAttribute (
"Remote", remoteAddress);
493 clientApp.
Add (client.Install (nodes_net1[x][r1].Get (0)));
498 std::cout <<
"Net3 ]" << std::endl;
499 for (
int i = 0; i < 5; ++i)
501 for (
int j = 0; j < nLANClients; ++j)
507 nodes_net3LAN[z][i][j].Get (0));
510 r1 = 2 + (int)(4 * urng->
GetValue ());
514 ifs3LAN[z][i][j].GetAddress (0), 9999));
515 client.SetAttribute (
"Remote", remoteAddress);
517 clientApp.
Add (client.Install (nodes_net1[x][r1].Get (0)));
530 std::cout <<
"Using Nix-vectors..." << std::endl;
535 std::cout <<
"Populating Global Static Routing Tables..." << std::endl;
541 std::cout <<
"Routing tables population took "
542 <<
TIMER_DIFF (routingEnd, routingStart) << std::endl;
545 std::cout <<
"Running simulator..." << std::endl;
550 std::cout <<
"Simulator finished." << std::endl;
554 std::cout <<
"-----" << std::endl <<
"Runtime Stats:" << std::endl;
555 std::cout <<
"Simulator init time: " << d1 << std::endl;
556 std::cout <<
"Simulator run time: " << d2 << std::endl;
557 std::cout <<
"Total elapsed time: " << d1+d2 << std::endl;
559 delete[] nodes_netLR;
holds a vector of ns3::Application pointers.
static Ipv4Address GetAny(void)
static uint32_t GetNNodes(void)
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.
const size_t m_xMax
maximum number of rows
NetDeviceContainer Install(NodeContainer c)
Array2D(const size_t x, const size_t y)
Constructor.
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.
const size_t m_xMax
maximum number of rows
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)
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
Array3D(const size_t x, const size_t y, const size_t z)
Constructor.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Hold an unsigned integer type.
Array2D< T > ** p
Stored elements.
holds a vector of ns3::NetDevice pointers
#define TIMER_DIFF(_t1, _t2)
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.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
2D array used in nix-vector-routing example "nms-p2p-nix.cc"
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
3D array used in nix-vector-routing example "nms-p2p-nix.cc"
AttributeValue implementation for 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.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
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)
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.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.