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))
67 Array2D (
const size_t x,
const size_t y) : p (new T*[x]), m_xMax (x)
69 for (
size_t i = 0; i < m_xMax; i++)
75 for (
size_t i = 0; i < m_xMax; i++)
81 T* operator[] (
const size_t i)
94 Array3D (
const size_t x,
const size_t y,
const size_t z)
95 : p (new
Array2D<T>*[x]), m_xMax (x)
97 for (
size_t i = 0; i < m_xMax; i++)
103 for (
size_t i = 0; i < m_xMax; i++)
122 main (
int argc,
char *argv[])
126 std::cout <<
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
129 int nCN = 2, nLANClients = 42;
133 cmd.
AddValue (
"CN",
"Number of total CNs [2]", nCN);
134 cmd.
AddValue (
"LAN",
"Number of nodes per LAN [42]", nLANClients);
135 cmd.
AddValue (
"NIX",
"Toggle nix-vector routing", nix);
136 cmd.
Parse (argc,argv);
140 std::cout <<
"Number of total CNs (" << nCN <<
") lower than minimum of 2"
145 std::cout <<
"Number of CNs: " << nCN <<
", LAN nodes: " << nLANClients << std::endl;
166 std::ostringstream oss;
182 for (
int z = 0; z < nCN; ++z)
184 std::cout <<
"Creating Campus Network " << z <<
":" << std::endl;
186 std::cout <<
" SubNet [ 0";
187 for (
int i = 0; i < 3; ++i)
189 nodes_net0[z][i].Create (1);
190 stack.
Install (nodes_net0[z][i]);
192 nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
193 nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
194 nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
196 for (
int i = 0; i < 3; ++i)
198 ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
202 for (
int i = 0; i < 6; ++i)
204 nodes_net1[z][i].Create (1);
205 stack.
Install (nodes_net1[z][i]);
207 nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
208 nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
209 nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
210 nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
211 nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
213 for (
int i = 0; i < 6; ++i)
219 ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
223 net0_1.
Add (nodes_net0[z][2].Get (0));
224 net0_1.
Add (nodes_net1[z][0].Get (0));
226 ndc0_1 = p2p_1gb5ms.
Install (net0_1);
228 oss << 10 + z <<
".1.252.0";
229 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
230 ifs = address.
Assign (ndc0_1);
233 for (
int i = 0; i < 14; ++i)
235 nodes_net2[z][i].Create (1);
236 stack.
Install (nodes_net2[z][i]);
238 nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
239 nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
240 nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
241 nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
242 nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
243 nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
244 nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
245 nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
246 nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
247 nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
248 nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
249 nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
250 nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
251 nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
253 for (
int i = 0; i < 14; ++i)
255 ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
259 for (
int i = 0; i < 7; ++i)
262 oss << 10 + z <<
".4." << 15 + i <<
".0";
263 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
264 for (
int j = 0; j < nLANClients; ++j)
266 nodes_net2LAN[z][i][j].Create (1);
267 stack.
Install (nodes_net2LAN[z][i][j]);
268 nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
269 ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
270 ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
274 std::cout <<
" 3 ]" << std::endl;
275 for (
int i = 0; i < 9; ++i)
277 nodes_net3[z][i].Create (1);
278 stack.
Install (nodes_net3[z][i]);
280 nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
281 nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
282 nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
283 nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
284 nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
285 nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
286 nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
287 nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
288 nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
290 for (
int i = 0; i < 9; ++i)
292 ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
296 for (
int i = 0; i < 5; ++i)
299 oss << 10 + z <<
".5." << 10 + i <<
".0";
300 address.
SetBase (oss.str ().c_str (),
"255.255.255.255");
301 for (
int j = 0; j < nLANClients; ++j)
303 nodes_net3LAN[z][i][j].Create (1);
304 stack.
Install (nodes_net3LAN[z][i][j]);
305 nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
306 ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
307 ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
310 std::cout <<
" Connecting Subnets..." << std::endl;
312 nodes_netLR[z].
Create (2);
313 stack.
Install (nodes_netLR[z]);
315 ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
317 NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
318 net0_4.
Add (nodes_netLR[z].Get (0));
319 net0_4.
Add (nodes_net0[z][0].Get (0));
320 net0_5.
Add (nodes_netLR[z].Get (1));
321 net0_5.
Add (nodes_net0[z][1].Get (0));
322 net2_4a.
Add (nodes_netLR[z].Get (0));
323 net2_4a.
Add (nodes_net2[z][0].Get (0));
324 net2_4b.
Add (nodes_netLR[z].Get (1));
325 net2_4b.
Add (nodes_net2[z][1].Get (0));
326 net3_5a.
Add (nodes_netLR[z].Get (1));
327 net3_5a.
Add (nodes_net3[z][0].Get (0));
328 net3_5b.
Add (nodes_netLR[z].Get (1));
329 net3_5b.
Add (nodes_net3[z][1].Get (0));
331 ndc0_4 = p2p_1gb5ms.
Install (net0_4);
333 oss << 10 + z <<
".1.253.0";
334 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
335 ifs = address.
Assign (ndc0_4);
336 ndc0_5 = p2p_1gb5ms.
Install (net0_5);
338 oss << 10 + z <<
".1.254.0";
339 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
340 ifs = address.
Assign (ndc0_5);
341 ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
343 oss << 10 + z <<
".4.253.0";
344 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
345 ifs = address.
Assign (ndc2_4a);
346 ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
348 oss << 10 + z <<
".4.254.0";
349 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
350 ifs = address.
Assign (ndc2_4b);
351 ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
353 oss << 10 + z <<
".5.253.0";
354 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
355 ifs = address.
Assign (ndc3_5a);
356 ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
358 oss << 10 + z <<
".5.254.0";
359 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
360 ifs = address.
Assign (ndc3_5b);
362 std::cout <<
" Assigning IP addresses..." << std::endl;
363 for (
int i = 0; i < 3; ++i)
366 oss << 10 + z <<
".1." << 1 + i <<
".0";
367 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
368 ifs0[z][i] = address.
Assign (ndc0[i]);
370 for (
int i = 0; i < 6; ++i)
377 oss << 10 + z <<
".2." << 1 + i <<
".0";
378 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
379 ifs1[z][i] = address.
Assign (ndc1[i]);
382 oss << 10 + z <<
".3.1.0";
383 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
384 ifs = address.
Assign (ndcLR);
385 for (
int i = 0; i < 14; ++i)
388 oss << 10 + z <<
".4." << 1 + i <<
".0";
389 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
390 ifs2[z][i] = address.
Assign (ndc2[i]);
392 for (
int i = 0; i < 9; ++i)
395 oss << 10 + z <<
".5." << 1 + i <<
".0";
396 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
397 ifs3[z][i] = address.
Assign (ndc3[i]);
403 std::cout <<
"Forming Ring Topology..." << std::endl;
405 for (
int z = 0; z < nCN-1; ++z)
407 nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
408 nodes_ring[z].
Add (nodes_net0[z+1][0].Get (0));
410 nodes_ring[nCN-1].
Add (nodes_net0[nCN-1][0].Get (0));
411 nodes_ring[nCN-1].
Add (nodes_net0[0][0].Get (0));
413 for (
int z = 0; z < nCN; ++z)
415 ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
417 oss <<
"254.1." << z + 1 <<
".0";
418 address.
SetBase (oss.str ().c_str (),
"255.255.255.0");
419 ifs = address.
Assign (ndc_ring[z]);
426 std::cout <<
"Creating TCP Traffic Flows:" << std::endl;
429 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"));
431 StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
437 for (
int z = 0; z < nCN; ++z)
445 std::cout <<
" Campus Network " << z <<
" Flows [ Net2 ";
446 for (
int i = 0; i < 7; ++i)
448 for (
int j = 0; j < nLANClients; ++j)
454 nodes_net2LAN[z][i][j].Get (0));
457 r1 = 2 + (int)(4 * urng->
GetValue ());
461 ifs2LAN[z][i][j].GetAddress (0), 9999));
462 client.SetAttribute (
"Remote", remoteAddress);
464 clientApp.
Add (client.Install (nodes_net1[x][r1].Get (0)));
469 std::cout <<
"Net3 ]" << std::endl;
470 for (
int i = 0; i < 5; ++i)
472 for (
int j = 0; j < nLANClients; ++j)
478 nodes_net3LAN[z][i][j].Get (0));
481 r1 = 2 + (int)(4 * urng->
GetValue ());
485 ifs3LAN[z][i][j].GetAddress (0), 9999));
486 client.SetAttribute (
"Remote", remoteAddress);
488 clientApp.
Add (client.Install (nodes_net1[x][r1].Get (0)));
501 std::cout <<
"Using Nix-vectors..." << std::endl;
506 std::cout <<
"Populating Global Static Routing Tables..." << std::endl;
512 std::cout <<
"Routing tables population took "
513 <<
TIMER_DIFF (routingEnd, routingStart) << std::endl;
516 std::cout <<
"Running simulator..." << std::endl;
521 std::cout <<
"Simulator finished." << std::endl;
525 std::cout <<
"-----" << std::endl <<
"Runtime Stats:" << std::endl;
526 std::cout <<
"Simulator init time: " << d1 << std::endl;
527 std::cout <<
"Simulator run time: " << d2 << std::endl;
528 std::cout <<
"Total elapsed time: " << d1+d2 << std::endl;
530 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.
NetDeviceContainer Install(NodeContainer c)
Array2D(const size_t x, const size_t y)
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.
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)
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Hold an unsigned integer type.
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.
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.
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.