A Discrete-Event Network Simulator
API
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 
41 #include "mpi-test-fixtures.h"
42 
43 #include "ns3/core-module.h"
44 #include "ns3/internet-module.h"
45 #include "ns3/network-module.h"
46 #include "ns3/on-off-helper.h"
47 #include "ns3/packet-sink-helper.h"
48 #include "ns3/point-to-point-helper.h"
49 #include "ns3/mpi-interface.h"
50 #include "ns3/nix-vector-helper.h"
51 
52 #include <fstream>
53 #include <vector>
54 
55 using namespace ns3;
56 
57 NS_LOG_COMPONENT_DEFINE ("CampusNetworkModelDistributed");
58 
59 int
60 main (int argc, char *argv[])
61 {
62  typedef std::vector<NodeContainer> vectorOfNodeContainer;
63  typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
64  typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
65 
66  typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
67  typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
68  typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
69 
70  typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
71  typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
72 
73  SystemWallClockMs t0; // Total time
74  SystemWallClockMs t1; // Setup time
75  SystemWallClockMs t2; // Run time/
76  t0.Start ();
77  t1.Start ();
78 
79  uint32_t nCN = 2;
80  uint32_t nLANClients = 10;
81  bool single = 0;
82  int nPackets = 10; // Packets sent by OnOff applications
83  bool nix = true;
84  Time stop = Seconds (100);
85  bool verbose = false;
86  bool testing = false;
87 
88  CommandLine cmd (__FILE__);
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);
97 
98  cmd.Parse (argc,argv);
99 
100  // Enable parallel simulator with the command line arguments
101  MpiInterface::Enable (&argc, &argv);
102 
103  SinkTracer::Init ();
104 
105  uint32_t systemId = MpiInterface::GetSystemId ();
106  uint32_t systemCount = MpiInterface::GetSize ();
107 
108  RANK0COUT (" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl);
109 
110  GlobalValue::Bind ("SimulatorImplementationType",
111  StringValue ("ns3::DistributedSimulatorImpl"));
112 
113 
114  if (nCN < 2)
115  {
116  RANK0COUT ("Number of total CNs (" << nCN << ") lower than minimum of 2"
117  << std::endl);
118  return 1;
119  }
120  if (systemCount > nCN)
121  {
122  RANK0COUT ("Number of total CNs (" << nCN << ") should be >= systemCount ("
123  << systemCount << ")." << std::endl);
124  return 1;
125  }
126 
127  RANK0COUT ("Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl);
128 
129  vectorOfNodeContainer nodes_netLR(nCN);
130  vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
131  vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
132  vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
133  vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
134 
135  vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
136  vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
137 
138  PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
140 
142 
143  vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
144  vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
145  vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
146  vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
147  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
148  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
149 
151  std::ostringstream oss;
152  p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
153  p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
154  p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
155  p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
156  p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
157  p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
158 
159  if (nix)
160  {
161  Ipv4NixVectorHelper nixRouting;
162  stack.SetRoutingHelper (nixRouting); // has effect on the next Install ()
163  }
164 
165  // Create Campus Networks
166  for (uint32_t z = 0; z < nCN; ++z)
167  {
168  RANK0COUT ("Creating Campus Network " << z << ":" << std::endl);
169  // Create Net0
170  RANK0COUT (" SubNet [ 0");
171  for (int i = 0; i < 3; ++i)
172  {
173  Ptr<Node> node = CreateObject<Node> (z % systemCount);
174  nodes_net0[z][i].Add (node);
175  stack.Install (nodes_net0[z][i]);
176  }
177  nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
178  nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
179  nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
180  NetDeviceContainer ndc0[3];
181  for (int i = 0; i < 3; ++i)
182  {
183  ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
184  }
185  // Create Net1
186  RANK0COUTAPPEND (" 1");
187  for (int i = 0; i < 6; ++i)
188  {
189  Ptr<Node> node = CreateObject<Node> (z % systemCount);
190  nodes_net1[z][i].Add (node);
191  stack.Install (nodes_net1[z][i]);
192  }
193  nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
194  nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
195  nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
196  nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
197  nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
198  NetDeviceContainer ndc1[6];
199  for (int i = 0; i < 6; ++i)
200  {
201  if (i == 1)
202  {
203  continue;
204  }
205  ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
206  }
207  // Connect Net0 <-> Net1
208  NodeContainer net0_1;
209  net0_1.Add (nodes_net0[z][2].Get (0));
210  net0_1.Add (nodes_net1[z][0].Get (0));
211  NetDeviceContainer ndc0_1;
212  ndc0_1 = p2p_1gb5ms.Install (net0_1);
213  oss.str ("");
214  oss << 10 + z << ".1.252.0";
215  address.SetBase (oss.str ().c_str (), "255.255.255.0");
216  ifs = address.Assign (ndc0_1);
217  // Create Net2
218  RANK0COUTAPPEND (" 2");
219  for (int i = 0; i < 14; ++i)
220  {
221  Ptr<Node> node = CreateObject<Node> (z % systemCount);
222  nodes_net2[z][i].Add (node);
223  stack.Install (nodes_net2[z][i]);
224  }
225  nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
226  nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
227  nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
228  nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
229  nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
230  nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
231  nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
232  nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
233  nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
234  nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
235  nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
236  nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
237  nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
238  nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
239  NetDeviceContainer ndc2[14];
240  for (int i = 0; i < 14; ++i)
241  {
242  ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
243  }
244  vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
245  for (int i = 0; i < 7; ++i)
246  {
247  oss.str ("");
248  oss << 10 + z << ".4." << 15 + i << ".0";
249  address.SetBase (oss.str ().c_str (), "255.255.255.0");
250  for (uint32_t j = 0; j < nLANClients; ++j)
251  {
252  Ptr<Node> node = CreateObject<Node> (z % systemCount);
253  nodes_net2LAN[z][i][j].Add (node);
254  stack.Install (nodes_net2LAN[z][i][j]);
255  nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
256  ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
257  ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
258  }
259  }
260  // Create Net3
261  RANK0COUTAPPEND (" 3 ]" << std::endl);
262  for (int i = 0; i < 9; ++i)
263  {
264  Ptr<Node> node = CreateObject<Node> (z % systemCount);
265  nodes_net3[z][i].Add (node);
266  stack.Install (nodes_net3[z][i]);
267  }
268  nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
269  nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
270  nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
271  nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
272  nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
273  nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
274  nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
275  nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
276  nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
277  NetDeviceContainer ndc3[9];
278  for (int i = 0; i < 9; ++i)
279  {
280  ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
281  }
282  vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
283  for (int i = 0; i < 5; ++i)
284  {
285  oss.str ("");
286  oss << 10 + z << ".5." << 10 + i << ".0";
287  address.SetBase (oss.str ().c_str (), "255.255.255.0");
288  for (uint32_t j = 0; j < nLANClients; ++j)
289  {
290  Ptr<Node> node = CreateObject<Node> (z % systemCount);
291  nodes_net3LAN[z][i][j].Add (node);
292  stack.Install (nodes_net3LAN[z][i][j]);
293  nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
294  ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
295  ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
296  }
297  }
298  RANK0COUT (" Connecting Subnets..." << std::endl);
299  // Create Lone Routers (Node 4 & 5)
300  Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
301  Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
302  nodes_netLR[z].Add (node1);
303  nodes_netLR[z].Add (node2);
304  stack.Install (nodes_netLR[z]);
305  NetDeviceContainer ndcLR;
306  ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
307  // Connect Net2/Net3 through Lone Routers to Net0
308  NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
309  net0_4.Add (nodes_netLR[z].Get (0));
310  net0_4.Add (nodes_net0[z][0].Get (0));
311  net0_5.Add (nodes_netLR[z].Get (1));
312  net0_5.Add (nodes_net0[z][1].Get (0));
313  net2_4a.Add (nodes_netLR[z].Get (0));
314  net2_4a.Add (nodes_net2[z][0].Get (0));
315  net2_4b.Add (nodes_netLR[z].Get (1));
316  net2_4b.Add (nodes_net2[z][1].Get (0));
317  net3_5a.Add (nodes_netLR[z].Get (1));
318  net3_5a.Add (nodes_net3[z][0].Get (0));
319  net3_5b.Add (nodes_netLR[z].Get (1));
320  net3_5b.Add (nodes_net3[z][1].Get (0));
321  NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
322  ndc0_4 = p2p_1gb5ms.Install (net0_4);
323  oss.str ("");
324  oss << 10 + z << ".1.253.0";
325  address.SetBase (oss.str ().c_str (), "255.255.255.0");
326  ifs = address.Assign (ndc0_4);
327  ndc0_5 = p2p_1gb5ms.Install (net0_5);
328  oss.str ("");
329  oss << 10 + z << ".1.254.0";
330  address.SetBase (oss.str ().c_str (), "255.255.255.0");
331  ifs = address.Assign (ndc0_5);
332  ndc2_4a = p2p_1gb5ms.Install (net2_4a);
333  oss.str ("");
334  oss << 10 + z << ".4.253.0";
335  address.SetBase (oss.str ().c_str (), "255.255.255.0");
336  ifs = address.Assign (ndc2_4a);
337  ndc2_4b = p2p_1gb5ms.Install (net2_4b);
338  oss.str ("");
339  oss << 10 + z << ".4.254.0";
340  address.SetBase (oss.str ().c_str (), "255.255.255.0");
341  ifs = address.Assign (ndc2_4b);
342  ndc3_5a = p2p_1gb5ms.Install (net3_5a);
343  oss.str ("");
344  oss << 10 + z << ".5.253.0";
345  address.SetBase (oss.str ().c_str (), "255.255.255.0");
346  ifs = address.Assign (ndc3_5a);
347  ndc3_5b = p2p_1gb5ms.Install (net3_5b);
348  oss.str ("");
349  oss << 10 + z << ".5.254.0";
350  address.SetBase (oss.str ().c_str (), "255.255.255.0");
351  ifs = address.Assign (ndc3_5b);
352  // Assign IP addresses
353  RANK0COUT (" Assigning IP addresses..." << std::endl);
354  for (int i = 0; i < 3; ++i)
355  {
356  oss.str ("");
357  oss << 10 + z << ".1." << 1 + i << ".0";
358  address.SetBase (oss.str ().c_str (), "255.255.255.0");
359  ifs0[z][i] = address.Assign (ndc0[i]);
360  }
361  for (int i = 0; i < 6; ++i)
362  {
363  if (i == 1)
364  {
365  continue;
366  }
367  oss.str ("");
368  oss << 10 + z << ".2." << 1 + i << ".0";
369  address.SetBase (oss.str ().c_str (), "255.255.255.0");
370  ifs1[z][i] = address.Assign (ndc1[i]);
371  }
372  oss.str ("");
373  oss << 10 + z << ".3.1.0";
374  address.SetBase (oss.str ().c_str (), "255.255.255.0");
375  ifs = address.Assign (ndcLR);
376  for (int i = 0; i < 14; ++i)
377  {
378  oss.str ("");
379  oss << 10 + z << ".4." << 1 + i << ".0";
380  address.SetBase (oss.str ().c_str (), "255.255.255.0");
381  ifs2[z][i] = address.Assign (ndc2[i]);
382  }
383  for (int i = 0; i < 9; ++i)
384  {
385  oss.str ("");
386  oss << 10 + z << ".5." << 1 + i << ".0";
387  address.SetBase (oss.str ().c_str (), "255.255.255.0");
388  ifs3[z][i] = address.Assign (ndc3[i]);
389  }
390  }
391  // Create Ring Links
392  if (nCN > 1)
393  {
394  RANK0COUT ("Forming Ring Topology..." << std::endl);
395  vectorOfNodeContainer nodes_ring(nCN);
396  for (uint32_t z = 0; z < nCN - 1; ++z)
397  {
398  nodes_ring[z].Add (nodes_net0[z][0].Get (0));
399  nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
400  }
401  nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
402  nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
403  vectorOfNetDeviceContainer ndc_ring(nCN);
404  for (uint32_t z = 0; z < nCN; ++z)
405  {
406  ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
407  oss.str ("");
408  oss << "254.1." << z + 1 << ".0";
409  address.SetBase (oss.str ().c_str (), "255.255.255.0");
410  ifs = address.Assign (ndc_ring[z]);
411  }
412  }
413 
414  // Create Traffic Flows
415  RANK0COUT ("Creating UDP Traffic Flows:" << std::endl);
416  Config::SetDefault ("ns3::OnOffApplication::MaxBytes",
417  UintegerValue (nPackets * 512));
418  Config::SetDefault ("ns3::OnOffApplication::OnTime",
419  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
420  Config::SetDefault ("ns3::OnOffApplication::OffTime",
421  StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
422 
423 
424  if (single)
425  {
426  if (systemCount == 1)
427  {
428  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
430  9999));
431  ApplicationContainer sinkApp = sinkHelper.Install (nodes_net1[0][2].Get (0));
432  sinkApp.Start (Seconds (0.0));
433  if (testing)
434  {
435  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
436  }
437 
438  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
439  AddressValue remoteAddress (InetSocketAddress (ifs1[0][2].GetAddress (0), 9999));
440  RANK0COUT ("Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl);
441  client.SetAttribute ("Remote", remoteAddress);
442 
443  ApplicationContainer clientApp;
444  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
445  clientApp.Start (Seconds (0));
446  }
447  else if (systemId == 1)
448  {
449  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
451  9999));
452  ApplicationContainer sinkApp =
453  sinkHelper.Install (nodes_net1[1][0].Get (0));
454  sinkApp.Start (Seconds (0.0));
455  if (testing)
456  {
457  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
458  }
459  }
460  else if (systemId == 0)
461  {
462  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
463  AddressValue remoteAddress
464  (InetSocketAddress (ifs1[1][0].GetAddress (0), 9999));
465 
466  RANK0COUT ("Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl);
467  client.SetAttribute ("Remote", remoteAddress);
468 
469  ApplicationContainer clientApp;
470  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
471  clientApp.Start (Seconds (0));
472  }
473  }
474  else
475  {
476  Ptr<UniformRandomVariable> urng = CreateObject<UniformRandomVariable> ();
477  int r1;
478  double r2;
479  for (uint32_t z = 0; z < nCN; ++z)
480  {
481  uint32_t x = z + 1;
482  if (z == nCN - 1)
483  {
484  x = 0;
485  }
486  // Subnet 2 LANs
487  RANK0COUT (" Campus Network " << z << " Flows [ Net2 ");
488  for (int i = 0; i < 7; ++i)
489  {
490  for (uint32_t j = 0; j < nLANClients; ++j)
491  {
492  // Sinks
493  if (systemCount == 1)
494  {
495  PacketSinkHelper sinkHelper
496  ("ns3::UdpSocketFactory",
498 
499  ApplicationContainer sinkApp =
500  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
501 
502  sinkApp.Start (Seconds (0.0));
503  if (testing)
504  {
505  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
506  }
507  }
508  else if (systemId == z % systemCount)
509  {
510  PacketSinkHelper sinkHelper
511  ("ns3::UdpSocketFactory",
513 
514  ApplicationContainer sinkApp =
515  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
516 
517  sinkApp.Start (Seconds (0.0));
518  if (testing)
519  {
520  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
521  }
522  }
523  // Sources
524  if (systemCount == 1)
525  {
526  r1 = 2 + (int)(4 * urng->GetValue ());
527  r2 = 10 * urng->GetValue ();
528  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
529 
530  AddressValue remoteAddress
531  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
532 
533  client.SetAttribute ("Remote", remoteAddress);
534  ApplicationContainer clientApp;
535  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
536  clientApp.Start (Seconds (r2));
537  }
538  else if (systemId == x % systemCount)
539  {
540  r1 = 2 + (int)(4 * urng->GetValue ());
541  r2 = 10 * urng->GetValue ();
542  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
543 
544  AddressValue remoteAddress
545  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
546 
547  client.SetAttribute ("Remote", remoteAddress);
548  ApplicationContainer clientApp;
549  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
550  clientApp.Start (Seconds (r2));
551  }
552  }
553  }
554  // Subnet 3 LANs
555  RANK0COUTAPPEND ("Net3 ]" << std::endl);
556  for (int i = 0; i < 5; ++i)
557  {
558  for (uint32_t j = 0; j < nLANClients; ++j)
559  {
560  // Sinks
561  if (systemCount == 1)
562  {
563  PacketSinkHelper sinkHelper
564  ("ns3::UdpSocketFactory",
566 
567  ApplicationContainer sinkApp =
568  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
569  sinkApp.Start (Seconds (0.0));
570  if (testing)
571  {
572  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
573  }
574  }
575  else if (systemId == z % systemCount)
576  {
577  PacketSinkHelper sinkHelper
578  ("ns3::UdpSocketFactory",
580 
581  ApplicationContainer sinkApp =
582  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
583 
584  sinkApp.Start (Seconds (0.0));
585  if (testing)
586  {
587  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
588  }
589  }
590  // Sources
591  if (systemCount == 1)
592  {
593  r1 = 2 + (int)(4 * urng->GetValue ());
594  r2 = 10 * urng->GetValue ();
595  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
596 
597  AddressValue remoteAddress
598  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
599 
600  client.SetAttribute ("Remote", remoteAddress);
601  ApplicationContainer clientApp;
602  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
603  clientApp.Start (Seconds (r2));
604  }
605  else if (systemId == x % systemCount)
606  {
607  r1 = 2 + (int)(4 * urng->GetValue ());
608  r2 = 10 * urng->GetValue ();
609  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
610 
611  AddressValue remoteAddress
612  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
613 
614  client.SetAttribute ("Remote", remoteAddress);
615  ApplicationContainer clientApp;
616  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
617  clientApp.Start (Seconds (r2));
618  }
619  }
620  }
621  }
622  }
623 
624  RANK0COUT ("Created " << NodeList::GetNNodes () << " nodes." << std::endl);
625  SystemWallClockMs tRouting;
626  tRouting.Start ();;
627 
628  if (nix)
629  {
630  RANK0COUT ("Using Nix-vectors..." << std::endl);
631  }
632  else
633  {
634  // Calculate routing tables
635  RANK0COUT ("Populating Routing tables..." << std::endl);
637  }
638 
639  tRouting.End ();
640  if (verbose)
641  {
642  RANK0COUT ("Routing tables population took "
643  << tRouting.GetElapsedReal () << "ms" << std::endl);
644  }
645 
646  RANK0COUT ("Running simulator..." << std::endl);
647  t1.End ();
648  t2.Start ();
649  Simulator::Stop (stop);
650  Simulator::Run ();
651  RANK0COUT ("Simulator finished." << std::endl);
653 
654  if (testing)
655  {
656  const int numberNodesSending = nCN * ( nLANClients * (7 + 5)); // 7 size of Net2, 5 size of Net3
657  const int expectedPacketCount = numberNodesSending * nPackets;
658 
659  SinkTracer::Verify (expectedPacketCount);
660  }
661 
662  // Exit the parallel execution environment
664  t2.End ();
665  RANK0COUT ("-----" << std::endl);
666 
667  if (verbose)
668  {
669  RANK0COUT ("Runtime Stats:\n"
670  << "Simulator init time: " << t1.GetElapsedReal () << "ms\n"
671  << "Simulator run time: " << t2.GetElapsedReal () << "ms\n"
672  << "Total elapsed time: " << t0.GetElapsedReal () << "ms"
673  << std::endl);
674  }
675  return 0;
676 }
677 
a polymophic address class
Definition: address.h:91
AttributeValue implementation for Address.
Definition: address.h:278
holds a vector of ns3::Application pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
Definition: command-line.h:229
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...
an Inet address class
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(void)
static void PopulateRoutingTables(void)
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(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:43
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 Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
static void Init(void)
PacketSink Init.
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
Hold variables of type string.
Definition: string.h:41
Measure elapsed wall clock time in milliseconds.
void Start(void)
Start a measure.
int64_t End(void)
Stop measuring the time since Start() was called.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Hold an unsigned integer type.
Definition: uinteger.h:44
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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.
Definition: nstime.h:1244
Common methods for MPI examples.
address
Definition: first.py:44
stack
Definition: first.py:41
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
list x
Random number samples.
cmd
Definition: second.py:35
bool verbose