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/ipv4-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  // Enable parallel simulator with the command line arguments
74  MpiInterface::Enable (&argc, &argv);
75 
77 
78  SystemWallClockMs t0; // Total time
79  SystemWallClockMs t1; // Setup time
80  SystemWallClockMs t2; // Run time/
81  t0.Start ();
82  t1.Start ();
83 
84  uint32_t systemId = MpiInterface::GetSystemId ();
85  uint32_t systemCount = MpiInterface::GetSize ();
86 
87  RANK0COUT (" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl);
88 
89  GlobalValue::Bind ("SimulatorImplementationType",
90  StringValue ("ns3::DistributedSimulatorImpl"));
91 
92  uint32_t nCN = 2;
93  uint32_t nLANClients = 10;
94  bool single = 0;
95  int nPackets = 10; // Packets sent by OnOff applications
96  bool nix = true;
97  Time stop = Seconds (100);
98  bool verbose = false;
99  bool testing = false;
100 
101  CommandLine cmd (__FILE__);
102  cmd.AddValue ("campuses", "Number of campus networks", nCN);
103  cmd.AddValue ("clients", "Number of client nodes per LAN", nLANClients);
104  cmd.AddValue ("packets", "Number of packets each on/off app should send", nPackets);
105  cmd.AddValue ("nix", "Toggle the use of nix-vector or global routing", nix);
106  cmd.AddValue ("stop", "Simulation run time", stop);
107  cmd.AddValue ("single", "Use single on/off app per campus network", single);
108  cmd.AddValue ("verbose", "Show extra timing information", verbose);
109  cmd.AddValue ("test", "Enable regression test output", testing);
110 
111  cmd.Parse (argc,argv);
112 
113  if (nCN < 2)
114  {
115  RANK0COUT ("Number of total CNs (" << nCN << ") lower than minimum of 2"
116  << std::endl);
117  return 1;
118  }
119  if (systemCount > nCN)
120  {
121  RANK0COUT ("Number of total CNs (" << nCN << ") should be >= systemCount ("
122  << systemCount << ")." << std::endl);
123  return 1;
124  }
125 
126  RANK0COUT ("Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << std::endl);
127 
128  vectorOfNodeContainer nodes_netLR(nCN);
129  vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
130  vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
131  vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
132  vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
133 
134  vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
135  vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
136 
137  PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
139 
141 
142  vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
143  vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
144  vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
145  vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
146  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
147  vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
148 
150  std::ostringstream oss;
151  p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
152  p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
153  p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
154  p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
155  p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
156  p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
157 
158  if (nix)
159  {
160  Ipv4NixVectorHelper nixRouting;
161  stack.SetRoutingHelper (nixRouting); // has effect on the next Install ()
162  }
163 
164  // Create Campus Networks
165  for (uint32_t z = 0; z < nCN; ++z)
166  {
167  RANK0COUT ("Creating Campus Network " << z << ":" << std::endl);
168  // Create Net0
169  RANK0COUT (" SubNet [ 0");
170  for (int i = 0; i < 3; ++i)
171  {
172  Ptr<Node> node = CreateObject<Node> (z % systemCount);
173  nodes_net0[z][i].Add (node);
174  stack.Install (nodes_net0[z][i]);
175  }
176  nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
177  nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
178  nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
179  NetDeviceContainer ndc0[3];
180  for (int i = 0; i < 3; ++i)
181  {
182  ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
183  }
184  // Create Net1
185  RANK0COUTAPPEND (" 1");
186  for (int i = 0; i < 6; ++i)
187  {
188  Ptr<Node> node = CreateObject<Node> (z % systemCount);
189  nodes_net1[z][i].Add (node);
190  stack.Install (nodes_net1[z][i]);
191  }
192  nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
193  nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
194  nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
195  nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
196  nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
197  NetDeviceContainer ndc1[6];
198  for (int i = 0; i < 6; ++i)
199  {
200  if (i == 1)
201  {
202  continue;
203  }
204  ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
205  }
206  // Connect Net0 <-> Net1
207  NodeContainer net0_1;
208  net0_1.Add (nodes_net0[z][2].Get (0));
209  net0_1.Add (nodes_net1[z][0].Get (0));
210  NetDeviceContainer ndc0_1;
211  ndc0_1 = p2p_1gb5ms.Install (net0_1);
212  oss.str ("");
213  oss << 10 + z << ".1.252.0";
214  address.SetBase (oss.str ().c_str (), "255.255.255.0");
215  ifs = address.Assign (ndc0_1);
216  // Create Net2
217  RANK0COUTAPPEND (" 2");
218  for (int i = 0; i < 14; ++i)
219  {
220  Ptr<Node> node = CreateObject<Node> (z % systemCount);
221  nodes_net2[z][i].Add (node);
222  stack.Install (nodes_net2[z][i]);
223  }
224  nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
225  nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
226  nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
227  nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
228  nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
229  nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
230  nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
231  nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
232  nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
233  nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
234  nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
235  nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
236  nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
237  nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
238  NetDeviceContainer ndc2[14];
239  for (int i = 0; i < 14; ++i)
240  {
241  ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
242  }
243  vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
244  for (int i = 0; i < 7; ++i)
245  {
246  oss.str ("");
247  oss << 10 + z << ".4." << 15 + i << ".0";
248  address.SetBase (oss.str ().c_str (), "255.255.255.0");
249  for (uint32_t j = 0; j < nLANClients; ++j)
250  {
251  Ptr<Node> node = CreateObject<Node> (z % systemCount);
252  nodes_net2LAN[z][i][j].Add (node);
253  stack.Install (nodes_net2LAN[z][i][j]);
254  nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
255  ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
256  ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
257  }
258  }
259  // Create Net3
260  RANK0COUTAPPEND (" 3 ]" << std::endl);
261  for (int i = 0; i < 9; ++i)
262  {
263  Ptr<Node> node = CreateObject<Node> (z % systemCount);
264  nodes_net3[z][i].Add (node);
265  stack.Install (nodes_net3[z][i]);
266  }
267  nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
268  nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
269  nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
270  nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
271  nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
272  nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
273  nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
274  nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
275  nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
276  NetDeviceContainer ndc3[9];
277  for (int i = 0; i < 9; ++i)
278  {
279  ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
280  }
281  vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
282  for (int i = 0; i < 5; ++i)
283  {
284  oss.str ("");
285  oss << 10 + z << ".5." << 10 + i << ".0";
286  address.SetBase (oss.str ().c_str (), "255.255.255.255");
287  for (uint32_t j = 0; j < nLANClients; ++j)
288  {
289  Ptr<Node> node = CreateObject<Node> (z % systemCount);
290  nodes_net3LAN[z][i][j].Add (node);
291  stack.Install (nodes_net3LAN[z][i][j]);
292  nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
293  ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
294  ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
295  }
296  }
297  RANK0COUT (" Connecting Subnets..." << std::endl);
298  // Create Lone Routers (Node 4 & 5)
299  Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
300  Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
301  nodes_netLR[z].Add (node1);
302  nodes_netLR[z].Add (node2);
303  stack.Install (nodes_netLR[z]);
304  NetDeviceContainer ndcLR;
305  ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
306  // Connect Net2/Net3 through Lone Routers to Net0
307  NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
308  net0_4.Add (nodes_netLR[z].Get (0));
309  net0_4.Add (nodes_net0[z][0].Get (0));
310  net0_5.Add (nodes_netLR[z].Get (1));
311  net0_5.Add (nodes_net0[z][1].Get (0));
312  net2_4a.Add (nodes_netLR[z].Get (0));
313  net2_4a.Add (nodes_net2[z][0].Get (0));
314  net2_4b.Add (nodes_netLR[z].Get (1));
315  net2_4b.Add (nodes_net2[z][1].Get (0));
316  net3_5a.Add (nodes_netLR[z].Get (1));
317  net3_5a.Add (nodes_net3[z][0].Get (0));
318  net3_5b.Add (nodes_netLR[z].Get (1));
319  net3_5b.Add (nodes_net3[z][1].Get (0));
320  NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
321  ndc0_4 = p2p_1gb5ms.Install (net0_4);
322  oss.str ("");
323  oss << 10 + z << ".1.253.0";
324  address.SetBase (oss.str ().c_str (), "255.255.255.0");
325  ifs = address.Assign (ndc0_4);
326  ndc0_5 = p2p_1gb5ms.Install (net0_5);
327  oss.str ("");
328  oss << 10 + z << ".1.254.0";
329  address.SetBase (oss.str ().c_str (), "255.255.255.0");
330  ifs = address.Assign (ndc0_5);
331  ndc2_4a = p2p_1gb5ms.Install (net2_4a);
332  oss.str ("");
333  oss << 10 + z << ".4.253.0";
334  address.SetBase (oss.str ().c_str (), "255.255.255.0");
335  ifs = address.Assign (ndc2_4a);
336  ndc2_4b = p2p_1gb5ms.Install (net2_4b);
337  oss.str ("");
338  oss << 10 + z << ".4.254.0";
339  address.SetBase (oss.str ().c_str (), "255.255.255.0");
340  ifs = address.Assign (ndc2_4b);
341  ndc3_5a = p2p_1gb5ms.Install (net3_5a);
342  oss.str ("");
343  oss << 10 + z << ".5.253.0";
344  address.SetBase (oss.str ().c_str (), "255.255.255.0");
345  ifs = address.Assign (ndc3_5a);
346  ndc3_5b = p2p_1gb5ms.Install (net3_5b);
347  oss.str ("");
348  oss << 10 + z << ".5.254.0";
349  address.SetBase (oss.str ().c_str (), "255.255.255.0");
350  ifs = address.Assign (ndc3_5b);
351  // Assign IP addresses
352  RANK0COUT (" Assigning IP addresses..." << std::endl);
353  for (int i = 0; i < 3; ++i)
354  {
355  oss.str ("");
356  oss << 10 + z << ".1." << 1 + i << ".0";
357  address.SetBase (oss.str ().c_str (), "255.255.255.0");
358  ifs0[z][i] = address.Assign (ndc0[i]);
359  }
360  for (int i = 0; i < 6; ++i)
361  {
362  if (i == 1)
363  {
364  continue;
365  }
366  oss.str ("");
367  oss << 10 + z << ".2." << 1 + i << ".0";
368  address.SetBase (oss.str ().c_str (), "255.255.255.0");
369  ifs1[z][i] = address.Assign (ndc1[i]);
370  }
371  oss.str ("");
372  oss << 10 + z << ".3.1.0";
373  address.SetBase (oss.str ().c_str (), "255.255.255.0");
374  ifs = address.Assign (ndcLR);
375  for (int i = 0; i < 14; ++i)
376  {
377  oss.str ("");
378  oss << 10 + z << ".4." << 1 + i << ".0";
379  address.SetBase (oss.str ().c_str (), "255.255.255.0");
380  ifs2[z][i] = address.Assign (ndc2[i]);
381  }
382  for (int i = 0; i < 9; ++i)
383  {
384  oss.str ("");
385  oss << 10 + z << ".5." << 1 + i << ".0";
386  address.SetBase (oss.str ().c_str (), "255.255.255.0");
387  ifs3[z][i] = address.Assign (ndc3[i]);
388  }
389  }
390  // Create Ring Links
391  if (nCN > 1)
392  {
393  RANK0COUT ("Forming Ring Topology..." << std::endl);
394  vectorOfNodeContainer nodes_ring(nCN);
395  for (uint32_t z = 0; z < nCN - 1; ++z)
396  {
397  nodes_ring[z].Add (nodes_net0[z][0].Get (0));
398  nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
399  }
400  nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
401  nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
402  vectorOfNetDeviceContainer ndc_ring(nCN);
403  for (uint32_t z = 0; z < nCN; ++z)
404  {
405  ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
406  oss.str ("");
407  oss << "254.1." << z + 1 << ".0";
408  address.SetBase (oss.str ().c_str (), "255.255.255.0");
409  ifs = address.Assign (ndc_ring[z]);
410  }
411  }
412 
413  // Create Traffic Flows
414  RANK0COUT ("Creating UDP Traffic Flows:" << std::endl);
415  Config::SetDefault ("ns3::OnOffApplication::MaxBytes",
416  UintegerValue (nPackets * 512));
417  Config::SetDefault ("ns3::OnOffApplication::OnTime",
418  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
419  Config::SetDefault ("ns3::OnOffApplication::OffTime",
420  StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
421 
422 
423  if (single)
424  {
425  if (systemCount == 1)
426  {
427  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
429  9999));
430  ApplicationContainer sinkApp = sinkHelper.Install (nodes_net1[0][2].Get (0));
431  sinkApp.Start (Seconds (0.0));
432  if (testing)
433  {
434  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
435  }
436 
437  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
438  AddressValue remoteAddress (InetSocketAddress (ifs1[0][2].GetAddress (0), 9999));
439  RANK0COUT ("Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl);
440  client.SetAttribute ("Remote", remoteAddress);
441 
442  ApplicationContainer clientApp;
443  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
444  clientApp.Start (Seconds (0));
445  }
446  else if (systemId == 1)
447  {
448  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
450  9999));
451  ApplicationContainer sinkApp =
452  sinkHelper.Install (nodes_net1[1][0].Get (0));
453  sinkApp.Start (Seconds (0.0));
454  if (testing)
455  {
456  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
457  }
458  }
459  else if (systemId == 0)
460  {
461  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
462  AddressValue remoteAddress
463  (InetSocketAddress (ifs1[1][0].GetAddress (0), 9999));
464 
465  RANK0COUT ("Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl);
466  client.SetAttribute ("Remote", remoteAddress);
467 
468  ApplicationContainer clientApp;
469  clientApp.Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
470  clientApp.Start (Seconds (0));
471  }
472  }
473  else
474  {
475  Ptr<UniformRandomVariable> urng = CreateObject<UniformRandomVariable> ();
476  int r1;
477  double r2;
478  for (uint32_t z = 0; z < nCN; ++z)
479  {
480  uint32_t x = z + 1;
481  if (z == nCN - 1)
482  {
483  x = 0;
484  }
485  // Subnet 2 LANs
486  RANK0COUT (" Campus Network " << z << " Flows [ Net2 ");
487  for (int i = 0; i < 7; ++i)
488  {
489  for (uint32_t j = 0; j < nLANClients; ++j)
490  {
491  // Sinks
492  if (systemCount == 1)
493  {
494  PacketSinkHelper sinkHelper
495  ("ns3::UdpSocketFactory",
497 
498  ApplicationContainer sinkApp =
499  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
500 
501  sinkApp.Start (Seconds (0.0));
502  if (testing)
503  {
504  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
505  }
506  }
507  else if (systemId == z % systemCount)
508  {
509  PacketSinkHelper sinkHelper
510  ("ns3::UdpSocketFactory",
512 
513  ApplicationContainer sinkApp =
514  sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
515 
516  sinkApp.Start (Seconds (0.0));
517  if (testing)
518  {
519  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
520  }
521  }
522  // Sources
523  if (systemCount == 1)
524  {
525  r1 = 2 + (int)(4 * urng->GetValue ());
526  r2 = 10 * urng->GetValue ();
527  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
528 
529  AddressValue remoteAddress
530  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
531 
532  client.SetAttribute ("Remote", remoteAddress);
533  ApplicationContainer clientApp;
534  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
535  clientApp.Start (Seconds (r2));
536  }
537  else if (systemId == x % systemCount)
538  {
539  r1 = 2 + (int)(4 * urng->GetValue ());
540  r2 = 10 * urng->GetValue ();
541  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
542 
543  AddressValue remoteAddress
544  (InetSocketAddress (ifs2LAN[z][i][j].GetAddress (0), 9999));
545 
546  client.SetAttribute ("Remote", remoteAddress);
547  ApplicationContainer clientApp;
548  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
549  clientApp.Start (Seconds (r2));
550  }
551  }
552  }
553  // Subnet 3 LANs
554  RANK0COUTAPPEND ("Net3 ]" << std::endl);
555  for (int i = 0; i < 5; ++i)
556  {
557  for (uint32_t j = 0; j < nLANClients; ++j)
558  {
559  // Sinks
560  if (systemCount == 1)
561  {
562  PacketSinkHelper sinkHelper
563  ("ns3::UdpSocketFactory",
565 
566  ApplicationContainer sinkApp =
567  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
568  sinkApp.Start (Seconds (0.0));
569  if (testing)
570  {
571  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
572  }
573  }
574  else if (systemId == z % systemCount)
575  {
576  PacketSinkHelper sinkHelper
577  ("ns3::UdpSocketFactory",
579 
580  ApplicationContainer sinkApp =
581  sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
582 
583  sinkApp.Start (Seconds (0.0));
584  if (testing)
585  {
586  sinkApp.Get (0)->TraceConnectWithoutContext ("RxWithAddresses", MakeCallback (&SinkTracer::SinkTrace));
587  }
588  }
589  // Sources
590  if (systemCount == 1)
591  {
592  r1 = 2 + (int)(4 * urng->GetValue ());
593  r2 = 10 * urng->GetValue ();
594  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
595 
596  AddressValue remoteAddress
597  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
598 
599  client.SetAttribute ("Remote", remoteAddress);
600  ApplicationContainer clientApp;
601  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
602  clientApp.Start (Seconds (r2));
603  }
604  else if (systemId == x % systemCount)
605  {
606  r1 = 2 + (int)(4 * urng->GetValue ());
607  r2 = 10 * urng->GetValue ();
608  OnOffHelper client ("ns3::UdpSocketFactory", Address ());
609 
610  AddressValue remoteAddress
611  (InetSocketAddress (ifs3LAN[z][i][j].GetAddress (0), 9999));
612 
613  client.SetAttribute ("Remote", remoteAddress);
614  ApplicationContainer clientApp;
615  clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
616  clientApp.Start (Seconds (r2));
617  }
618  }
619  }
620  }
621  }
622 
623  RANK0COUT ("Created " << NodeList::GetNNodes () << " nodes." << std::endl);
624  SystemWallClockMs tRouting;
625  tRouting.Start ();;
626 
627  if (nix)
628  {
629  RANK0COUT ("Using Nix-vectors..." << std::endl);
630  }
631  else
632  {
633  // Calculate routing tables
634  RANK0COUT ("Populating Routing tables..." << std::endl);
636  }
637 
638  tRouting.End ();
639  if (verbose)
640  {
641  RANK0COUT ("Routing tables population took "
642  << tRouting.GetElapsedReal () << "ms" << std::endl);
643  }
644 
645  RANK0COUT ("Running simulator..." << std::endl);
646  t1.End ();
647  t2.Start ();
648  Simulator::Stop (stop);
649  Simulator::Run ();
650  RANK0COUT ("Simulator finished." << std::endl);
652 
653  if (testing)
654  {
655  const int numberNodesSending = nCN * ( nLANClients * (7 + 5)); // 7 size of Net2, 5 size of Net3
656  const int expectedPacketCount = numberNodesSending * nPackets;
657 
658  SinkTracer::Verify (expectedPacketCount);
659  }
660 
661  // Exit the parallel execution environment
663  t2.End ();
664  RANK0COUT ("-----" << std::endl);
665 
666  if (verbose)
667  {
668  RANK0COUT ("Runtime Stats:\n"
669  << "Simulator init time: " << t1.GetElapsedReal () << "ms\n"
670  << "Simulator run time: " << t2.GetElapsedReal () << "ms\n"
671  << "Total elapsed time: " << t0.GetElapsedReal () << "ms"
672  << std::endl);
673  }
674  return 0;
675 }
676 
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:228
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.
Helper class that adds Nix-vector routing to nodes.
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
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:293
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 receive trace callback.
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:104
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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
Common methods for MPI examples.
#define RANK0COUT(x)
Write to std::cout only from rank 0.
#define RANK0COUTAPPEND(x)
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:1642
cmd
Definition: second.py:35
bool verbose