A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
nms-p2p-nix-distributed.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * (c) 2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
17  *
18  * DARPA NMS Campus Network Model
19  *
20  * This topology replicates the original NMS Campus Network model
21  * with the exception of chord links (which were never utilized in the
22  * original model)
23  * Link Bandwidths and Delays may not be the same as the original
24  * specifications
25  *
26  * Modified for distributed simulation by Josh Pelkey <jpelkey@gatech.edu>
27  *
28  * The fundamental unit of the NMS model consists of a campus network. The
29  * campus network topology can been seen here:
30  * http://www.nsnam.org/~jpelkey3/nms.png
31  * The number of hosts (default 42) is variable. Finally, an arbitrary
32  * number of these campus networks can be connected together (default 2)
33  * to make very large simulations.
34  */
35 
36 // for timing functions
37 #include <cstdlib>
38 #include <sys/time.h>
39 #include <fstream>
40 #include <vector>
41 
42 #include "ns3/core-module.h"
43 #include "ns3/internet-module.h"
44 #include "ns3/network-module.h"
45 #include "ns3/on-off-helper.h"
46 #include "ns3/packet-sink-helper.h"
47 #include "ns3/point-to-point-helper.h"
48 #include "ns3/mpi-interface.h"
49 #include "ns3/ipv4-static-routing-helper.h"
50 #include "ns3/ipv4-list-routing-helper.h"
51 #include "ns3/ipv4-nix-vector-helper.h"
52 
53 using namespace ns3;
54 
55 typedef struct timeval TIMER_TYPE;
56 #define TIMER_NOW(_t) gettimeofday (&_t,NULL);
57 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec * 1e-6)
58 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1) - TIMER_SECONDS (_t2))
59 
60 NS_LOG_COMPONENT_DEFINE ("CampusNetworkModelDistributed");
61 
62 int
63 main (int argc, char *argv[])
64 {
65 #ifdef NS3_MPI
66 
67  typedef std::vector<NodeContainer> vectorOfNodeContainer;
68  typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
69  typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
70 
71  typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
72  typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
73  typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
74 
75  typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
76  typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
77 
78  // Enable parallel simulator with the command line arguments
79  MpiInterface::Enable (&argc, &argv);
80 
81  TIMER_TYPE t0, t1, t2;
82  TIMER_NOW (t0);
83  std::cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
84 
85  GlobalValue::Bind ("SimulatorImplementationType",
86  StringValue ("ns3::DistributedSimulatorImpl"));
87 
88  uint32_t systemId = MpiInterface::GetSystemId ();
89  uint32_t systemCount = MpiInterface::GetSize ();
90 
91  uint32_t nCN = 2, nLANClients = 42;
92  int32_t single = 0;
93  int nBytes = 500000; // Bytes for each on/off app
94  bool nix = true;
95 
96  CommandLine cmd;
97  cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
98  cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
99  cmd.AddValue ("single", "1 if use single flow", single);
100  cmd.AddValue ("nBytes", "Number of bytes for each on/off app", nBytes);
101  cmd.AddValue ("nix", "Toggle the use of nix-vector or global routing", nix);
102  cmd.Parse (argc,argv);
103 
104  if (nCN < 2)
105  {
106  std::cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
107  << std::endl;
108  return 1;
109  }
110  if (systemCount > nCN)
111  {
112  std::cout << "Number of total CNs (" << nCN << ") should be >= systemCount ("
113  << systemCount << ")." << std::endl;
114  return 1;
115  }
116 
117  std::cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl;
118 
119 
120 
121  vectorOfNodeContainer nodes_netLR(nCN);
122  vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
123  vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
124  vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
125  vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
126 
127  vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
128  vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
129 
130  PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
132 
134 
135  vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
136  vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
137  vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
138  vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
139  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
140  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
141 
143  std::ostringstream oss;
144  p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
145  p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
146  p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
147  p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
148  p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
149  p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
150 
151  Ipv4NixVectorHelper nixRouting;
152  Ipv4StaticRoutingHelper staticRouting;
153 
155  list.Add (staticRouting, 0);
156  list.Add (nixRouting, 10);
157 
158  if (nix)
159  {
160  stack.SetRoutingHelper (list); // has effect on the next Install ()
161  }
162 
163  // Create Campus Networks
164  for (uint32_t z = 0; z < nCN; ++z)
165  {
166  std::cout << "Creating Campus Network " << z << ":" << std::endl;
167  // Create Net0
168  std::cout << " SubNet [ 0";
169  for (int i = 0; i < 3; ++i)
170  {
171  Ptr<Node> node = CreateObject<Node> (z % systemCount);
172  nodes_net0[z][i].Add (node);
173  stack.Install (nodes_net0[z][i]);
174  }
175  nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
176  nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
177  nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
178  NetDeviceContainer ndc0[3];
179  for (int i = 0; i < 3; ++i)
180  {
181  ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
182  }
183  // Create Net1
184  std::cout << " 1";
185  for (int i = 0; i < 6; ++i)
186  {
187  Ptr<Node> node = CreateObject<Node> (z % systemCount);
188  nodes_net1[z][i].Add (node);
189  stack.Install (nodes_net1[z][i]);
190  }
191  nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
192  nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
193  nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
194  nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
195  nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
196  NetDeviceContainer ndc1[6];
197  for (int i = 0; i < 6; ++i)
198  {
199  if (i == 1)
200  {
201  continue;
202  }
203  ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
204  }
205  // Connect Net0 <-> Net1
206  NodeContainer net0_1;
207  net0_1.Add (nodes_net0[z][2].Get (0));
208  net0_1.Add (nodes_net1[z][0].Get (0));
209  NetDeviceContainer ndc0_1;
210  ndc0_1 = p2p_1gb5ms.Install (net0_1);
211  oss.str ("");
212  oss << 10 + z << ".1.252.0";
213  address.SetBase (oss.str ().c_str (), "255.255.255.0");
214  ifs = address.Assign (ndc0_1);
215  // Create Net2
216  std::cout << " 2";
217  for (int i = 0; i < 14; ++i)
218  {
219  Ptr<Node> node = CreateObject<Node> (z % systemCount);
220  nodes_net2[z][i].Add (node);
221  stack.Install (nodes_net2[z][i]);
222  }
223  nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
224  nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
225  nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
226  nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
227  nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
228  nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
229  nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
230  nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
231  nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
232  nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
233  nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
234  nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
235  nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
236  nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
237  NetDeviceContainer ndc2[14];
238  for (int i = 0; i < 14; ++i)
239  {
240  ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
241  }
242  vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
243  for (int i = 0; i < 7; ++i)
244  {
245  oss.str ("");
246  oss << 10 + z << ".4." << 15 + i << ".0";
247  address.SetBase (oss.str ().c_str (), "255.255.255.0");
248  for (uint32_t j = 0; j < nLANClients; ++j)
249  {
250  Ptr<Node> node = CreateObject<Node> (z % systemCount);
251  nodes_net2LAN[z][i][j].Add (node);
252  stack.Install (nodes_net2LAN[z][i][j]);
253  nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
254  ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
255  ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
256  }
257  }
258  // Create Net3
259  std::cout << " 3 ]" << std::endl;
260  for (int i = 0; i < 9; ++i)
261  {
262  Ptr<Node> node = CreateObject<Node> (z % systemCount);
263  nodes_net3[z][i].Add (node);
264  stack.Install (nodes_net3[z][i]);
265  }
266  nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
267  nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
268  nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
269  nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
270  nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
271  nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
272  nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
273  nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
274  nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
275  NetDeviceContainer ndc3[9];
276  for (int i = 0; i < 9; ++i)
277  {
278  ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
279  }
280  vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
281  for (int i = 0; i < 5; ++i)
282  {
283  oss.str ("");
284  oss << 10 + z << ".5." << 10 + i << ".0";
285  address.SetBase (oss.str ().c_str (), "255.255.255.255");
286  for (uint32_t j = 0; j < nLANClients; ++j)
287  {
288  Ptr<Node> node = CreateObject<Node> (z % systemCount);
289  nodes_net3LAN[z][i][j].Add (node);
290  stack.Install (nodes_net3LAN[z][i][j]);
291  nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
292  ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
293  ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
294  }
295  }
296  std::cout << " Connecting Subnets..." << std::endl;
297  // Create Lone Routers (Node 4 & 5)
298  Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
299  Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
300  nodes_netLR[z].Add (node1);
301  nodes_netLR[z].Add (node2);
302  stack.Install (nodes_netLR[z]);
303  NetDeviceContainer ndcLR;
304  ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
305  // Connect Net2/Net3 through Lone Routers to Net0
306  NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
307  net0_4.Add (nodes_netLR[z].Get (0));
308  net0_4.Add (nodes_net0[z][0].Get (0));
309  net0_5.Add (nodes_netLR[z].Get (1));
310  net0_5.Add (nodes_net0[z][1].Get (0));
311  net2_4a.Add (nodes_netLR[z].Get (0));
312  net2_4a.Add (nodes_net2[z][0].Get (0));
313  net2_4b.Add (nodes_netLR[z].Get (1));
314  net2_4b.Add (nodes_net2[z][1].Get (0));
315  net3_5a.Add (nodes_netLR[z].Get (1));
316  net3_5a.Add (nodes_net3[z][0].Get (0));
317  net3_5b.Add (nodes_netLR[z].Get (1));
318  net3_5b.Add (nodes_net3[z][1].Get (0));
319  NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
320  ndc0_4 = p2p_1gb5ms.Install (net0_4);
321  oss.str ("");
322  oss << 10 + z << ".1.253.0";
323  address.SetBase (oss.str ().c_str (), "255.255.255.0");
324  ifs = address.Assign (ndc0_4);
325  ndc0_5 = p2p_1gb5ms.Install (net0_5);
326  oss.str ("");
327  oss << 10 + z << ".1.254.0";
328  address.SetBase (oss.str ().c_str (), "255.255.255.0");
329  ifs = address.Assign (ndc0_5);
330  ndc2_4a = p2p_1gb5ms.Install (net2_4a);
331  oss.str ("");
332  oss << 10 + z << ".4.253.0";
333  address.SetBase (oss.str ().c_str (), "255.255.255.0");
334  ifs = address.Assign (ndc2_4a);
335  ndc2_4b = p2p_1gb5ms.Install (net2_4b);
336  oss.str ("");
337  oss << 10 + z << ".4.254.0";
338  address.SetBase (oss.str ().c_str (), "255.255.255.0");
339  ifs = address.Assign (ndc2_4b);
340  ndc3_5a = p2p_1gb5ms.Install (net3_5a);
341  oss.str ("");
342  oss << 10 + z << ".5.253.0";
343  address.SetBase (oss.str ().c_str (), "255.255.255.0");
344  ifs = address.Assign (ndc3_5a);
345  ndc3_5b = p2p_1gb5ms.Install (net3_5b);
346  oss.str ("");
347  oss << 10 + z << ".5.254.0";
348  address.SetBase (oss.str ().c_str (), "255.255.255.0");
349  ifs = address.Assign (ndc3_5b);
350  // Assign IP addresses
351  std::cout << " Assigning IP addresses..." << std::endl;
352  for (int i = 0; i < 3; ++i)
353  {
354  oss.str ("");
355  oss << 10 + z << ".1." << 1 + i << ".0";
356  address.SetBase (oss.str ().c_str (), "255.255.255.0");
357  ifs0[z][i] = address.Assign (ndc0[i]);
358  }
359  for (int i = 0; i < 6; ++i)
360  {
361  if (i == 1)
362  {
363  continue;
364  }
365  oss.str ("");
366  oss << 10 + z << ".2." << 1 + i << ".0";
367  address.SetBase (oss.str ().c_str (), "255.255.255.0");
368  ifs1[z][i] = address.Assign (ndc1[i]);
369  }
370  oss.str ("");
371  oss << 10 + z << ".3.1.0";
372  address.SetBase (oss.str ().c_str (), "255.255.255.0");
373  ifs = address.Assign (ndcLR);
374  for (int i = 0; i < 14; ++i)
375  {
376  oss.str ("");
377  oss << 10 + z << ".4." << 1 + i << ".0";
378  address.SetBase (oss.str ().c_str (), "255.255.255.0");
379  ifs2[z][i] = address.Assign (ndc2[i]);
380  }
381  for (int i = 0; i < 9; ++i)
382  {
383  oss.str ("");
384  oss << 10 + z << ".5." << 1 + i << ".0";
385  address.SetBase (oss.str ().c_str (), "255.255.255.0");
386  ifs3[z][i] = address.Assign (ndc3[i]);
387  }
388  }
389  // Create Ring Links
390  if (nCN > 1)
391  {
392  std::cout << "Forming Ring Topology..." << std::endl;
393  vectorOfNodeContainer nodes_ring(nCN);
394  for (uint32_t z = 0; z < nCN - 1; ++z)
395  {
396  nodes_ring[z].Add (nodes_net0[z][0].Get (0));
397  nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
398  }
399  nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
400  nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
401  vectorOfNetDeviceContainer ndc_ring(nCN);
402  for (uint32_t z = 0; z < nCN; ++z)
403  {
404  ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
405  oss.str ("");
406  oss << "254.1." << z + 1 << ".0";
407  address.SetBase (oss.str ().c_str (), "255.255.255.0");
408  ifs = address.Assign (ndc_ring[z]);
409  }
410  }
411 
412  // Create Traffic Flows
413  std::cout << "Creating UDP Traffic Flows:" << std::endl;
414  Config::SetDefault ("ns3::OnOffApplication::MaxBytes",
415  UintegerValue (nBytes));
416  Config::SetDefault ("ns3::OnOffApplication::OnTime",
417  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
418  Config::SetDefault ("ns3::OnOffApplication::OffTime",
419  StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
420 
421 
422  if (single)
423  {
424  if (systemCount == 1)
425  {
426  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
428  9999));
429  ApplicationContainer sinkApp = sinkHelper.Install (nodes_net1[0][2].Get (0));
430  sinkApp.Start (Seconds (0.0));
431 
432  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
433  AddressValue remoteAddress (InetSocketAddress (ifs1[0][2].GetAddress (0), 9999));
434  std::cout << "Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl;
435  client.SetAttribute ("Remote", remoteAddress);
436 
437  ApplicationContainer clientApp;
438  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
439  clientApp.Start (Seconds (0));
440  }
441  else if (systemId == 1)
442  {
443  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
445  9999));
446  ApplicationContainer sinkApp =
447  sinkHelper.Install (nodes_net1[1][0].Get (0));
448 
449  sinkApp.Start (Seconds (0.0));
450  }
451  else if (systemId == 0)
452  {
453  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
454  AddressValue remoteAddress
455  (InetSocketAddress (ifs1[1][0].GetAddress (0), 9999));
456 
457  std::cout << "Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl;
458  client.SetAttribute ("Remote", remoteAddress);
459 
460  ApplicationContainer clientApp;
461  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
462  clientApp.Start (Seconds (0));
463  }
464  }
465  else
466  {
467  Ptr<UniformRandomVariable> urng = CreateObject<UniformRandomVariable> ();
468  int r1;
469  double r2;
470  for (uint32_t z = 0; z < nCN; ++z)
471  {
472  uint32_t x = z + 1;
473  if (z == nCN - 1)
474  {
475  x = 0;
476  }
477  // Subnet 2 LANs
478  std::cout << " Campus Network " << z << " Flows [ Net2 ";
479  for (int i = 0; i < 7; ++i)
480  {
481  for (uint32_t j = 0; j < nLANClients; ++j)
482  {
483  // Sinks
484  if (systemCount == 1)
485  {
486  PacketSinkHelper sinkHelper
487  ("ns3::UdpSocketFactory",
489 
490  ApplicationContainer sinkApp =
491  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
492 
493  sinkApp.Start (Seconds (0.0));
494  }
495  else if (systemId == z % systemCount)
496  {
497  PacketSinkHelper sinkHelper
498  ("ns3::UdpSocketFactory",
500 
501  ApplicationContainer sinkApp =
502  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
503 
504  sinkApp.Start (Seconds (0.0));
505  }
506  // Sources
507  if (systemCount == 1)
508  {
509  r1 = 2 + (int)(4 * urng->GetValue ());
510  r2 = 10 * urng->GetValue ();
511  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
512 
513  AddressValue remoteAddress
514  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
515 
516  client.SetAttribute ("Remote", remoteAddress);
517  ApplicationContainer clientApp;
518  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
519  clientApp.Start (Seconds (r2));
520  }
521  else if (systemId == x % systemCount)
522  {
523  r1 = 2 + (int)(4 * urng->GetValue ());
524  r2 = 10 * urng->GetValue ();
525  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
526 
527  AddressValue remoteAddress
528  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
529 
530  client.SetAttribute ("Remote", remoteAddress);
531  ApplicationContainer clientApp;
532  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
533  clientApp.Start (Seconds (r2));
534  }
535  }
536  }
537  // Subnet 3 LANs
538  std::cout << "Net3 ]" << std::endl;
539  for (int i = 0; i < 5; ++i)
540  {
541  for (uint32_t j = 0; j < nLANClients; ++j)
542  {
543  // Sinks
544  if (systemCount == 1)
545  {
546  PacketSinkHelper sinkHelper
547  ("ns3::UdpSocketFactory",
549 
550  ApplicationContainer sinkApp =
551  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
552 
553  sinkApp.Start (Seconds (0.0));
554  }
555  else if (systemId == z % systemCount)
556  {
557  PacketSinkHelper sinkHelper
558  ("ns3::UdpSocketFactory",
560 
561  ApplicationContainer sinkApp =
562  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
563 
564  sinkApp.Start (Seconds (0.0));
565  }
566  // Sources
567  if (systemCount == 1)
568  {
569  r1 = 2 + (int)(4 * urng->GetValue ());
570  r2 = 10 * urng->GetValue ();
571  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
572 
573  AddressValue remoteAddress
574  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
575 
576  client.SetAttribute ("Remote", remoteAddress);
577  ApplicationContainer clientApp;
578  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
579  clientApp.Start (Seconds (r2));
580  }
581  else if (systemId == x % systemCount)
582  {
583  r1 = 2 + (int)(4 * urng->GetValue ());
584  r2 = 10 * urng->GetValue ();
585  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
586 
587  AddressValue remoteAddress
588  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
589 
590  client.SetAttribute ("Remote", remoteAddress);
591  ApplicationContainer clientApp;
592  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
593  clientApp.Start (Seconds (r2));
594  }
595  }
596  }
597  }
598  }
599 
600  std::cout << "Created " << NodeList::GetNNodes () << " nodes." << std::endl;
601  TIMER_TYPE routingStart;
602  TIMER_NOW (routingStart);
603 
604  if (nix)
605  {
606  std::cout << "Using Nix-vectors..." << std::endl;
607  }
608  else
609  {
610  // Calculate routing tables
611  std::cout << "Populating Routing tables..." << std::endl;
613  }
614 
615  TIMER_TYPE routingEnd;
616  TIMER_NOW (routingEnd);
617  std::cout << "Routing tables population took "
618  << TIMER_DIFF (routingEnd, routingStart) << std::endl;
619 
620  std::cout << "Running simulator..." << std::endl;
621  TIMER_NOW (t1);
622  Simulator::Stop (Seconds (100.0));
623  Simulator::Run ();
624  TIMER_NOW (t2);
625  std::cout << "Simulator finished." << std::endl;
627  // Exit the parallel execution environment
629  double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
630  std::cout << "-----" << std::endl << "Runtime Stats:" << std::endl;
631  std::cout << "Simulator init time: " << d1 << std::endl;
632  std::cout << "Simulator run time: " << d2 << std::endl;
633  std::cout << "Total elapsed time: " << d1 + d2 << std::endl;
634  return 0;
635 #else
636  NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
637 #endif
638 }
639 
holds a vector of ns3::Application pointers.
an Inet address class
static Ipv4Address GetAny(void)
static uint32_t GetNNodes(void)
Definition: node-list.cc:200
int main(int argc, char *argv[])
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
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
Definition: string.h:19
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
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...
static void Disable()
Terminates the parallel environment.
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.
Definition: on-off-helper.h:42
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
a polymophic address class
Definition: address.h:86
static void Enable(int *pargc, char ***pargv)
Sets up parallel communication interface.
Hold an unsigned integer type.
Definition: uinteger.h:46
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.
Definition: command-line.h:152
#define list
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
keep track of a set of node pointers.
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define TIMER_DIFF(_t1, _t2)
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
tuple stack
Definition: first.py:34
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
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.
static uint32_t GetSystemId()
Helper class that adds ns3::Ipv4StaticRouting objects.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:408
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
#define TIMER_NOW(_t)
Helper class that adds ns3::Ipv4ListRouting objects.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
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.
tuple address
Definition: first.py:37
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
static uint32_t GetSize()
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.