author | Josh Pelkey <jpelkey@gatech.edu> |
Mon, 01 Nov 2010 12:23:07 -0400 | |
changeset 6651 | 4bd42b7fbb3b |
parent 6649 | f5413d463948 |
child 6821 | 203367ae7433 |
permissions | -rw-r--r-- |
6113
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
2 |
/* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
6 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
11 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
15 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
16 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
17 |
* TestDistributed creates a dumbbell topology and logically splits it in |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
18 |
* half. The left half is placed on logical processor 0 and the right half |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
19 |
* is placed on logical processor 1. |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
20 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
21 |
* ------- ------- |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
22 |
* RANK 0 RANK 1 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
23 |
* ------- | ------- |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
24 |
* | |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
25 |
* n0 ---------| | |---------- n6 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
26 |
* | | | |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
27 |
* n1 -------\ | | | /------- n7 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
28 |
* n4 ----------|---------- n5 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
29 |
* n2 -------/ | | | \------- n8 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
30 |
* | | | |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
31 |
* n3 ---------| | |---------- n9 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
32 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
33 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
34 |
* OnOff clients are placed on each left leaf node. Each right leaf node |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
35 |
* is a packet sink for a left leaf node. As a packet travels from one |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
36 |
* logical processor to another (the link between n4 and n5), MPI messages |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
37 |
* are passed containing the serialized packet. The message is then |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
38 |
* deserialized into a new packet and sent on as normal. |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
39 |
* |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
40 |
* One packet is sent from each left leaf node. The packet sinks on the |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
41 |
* right leaf nodes output logging information when they receive the packet. |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
42 |
*/ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
43 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
44 |
#include "ns3/core-module.h" |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
45 |
#include "ns3/simulator-module.h" |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
46 |
#include "ns3/node-module.h" |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
47 |
#include "ns3/helper-module.h" |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
48 |
#include "ns3/mpi-interface.h" |
6649
f5413d463948
Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6113
diff
changeset
|
49 |
#include "ns3/ipv4-global-routing-helper.h" |
6651
4bd42b7fbb3b
add includes for mpi build
Josh Pelkey <jpelkey@gatech.edu>
parents:
6649
diff
changeset
|
50 |
#include "ns3/ipv4-static-routing-helper.h" |
4bd42b7fbb3b
add includes for mpi build
Josh Pelkey <jpelkey@gatech.edu>
parents:
6649
diff
changeset
|
51 |
#include "ns3/ipv4-list-routing-helper.h" |
6113
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
52 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
53 |
#ifdef NS3_MPI |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
54 |
#include <mpi.h> |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
55 |
#endif |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
56 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
57 |
using namespace ns3; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
58 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
59 |
NS_LOG_COMPONENT_DEFINE ("SimpleDistributed"); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
60 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
61 |
int |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
62 |
main (int argc, char *argv[]) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
63 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
64 |
#ifdef NS3_MPI |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
65 |
// Distributed simulation setup |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
66 |
MpiInterface::Enable (&argc, &argv); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
67 |
GlobalValue::Bind ("SimulatorImplementationType", |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
68 |
StringValue ("ns3::DistributedSimulatorImpl")); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
69 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
70 |
LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
71 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
72 |
uint32_t systemId = MpiInterface::GetSystemId (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
73 |
uint32_t systemCount = MpiInterface::GetSize (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
74 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
75 |
// Check for valid distributed parameters. |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
76 |
// Must have 2 and only 2 Logical Processors (LPs) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
77 |
if (systemCount != 2) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
78 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
79 |
std::cout << "This simulation requires 2 and only 2 logical processors." << std::endl; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
80 |
return 1; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
81 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
82 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
83 |
// Some default values |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
84 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
85 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1Mbps")); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
86 |
Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (512)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
87 |
bool nix = true; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
88 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
89 |
// Parse command line |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
90 |
CommandLine cmd; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
91 |
cmd.AddValue ("nix", "Enable the use of nix-vector or global routing", nix); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
92 |
cmd.Parse (argc, argv); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
93 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
94 |
// Create leaf nodes on left with system id 0 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
95 |
NodeContainer leftLeafNodes; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
96 |
leftLeafNodes.Create (4, 0); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
97 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
98 |
// Create router nodes. Left router |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
99 |
// with system id 0, right router with |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
100 |
// system id 1 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
101 |
NodeContainer routerNodes; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
102 |
Ptr<Node> routerNode1 = CreateObject<Node> (0); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
103 |
Ptr<Node> routerNode2 = CreateObject<Node> (1); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
104 |
routerNodes.Add (routerNode1); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
105 |
routerNodes.Add (routerNode2); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
106 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
107 |
// Create leaf nodes on left with system id 1 |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
108 |
NodeContainer rightLeafNodes; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
109 |
rightLeafNodes.Create (4, 1); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
110 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
111 |
PointToPointHelper routerLink; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
112 |
routerLink.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
113 |
routerLink.SetChannelAttribute ("Delay", StringValue ("5ms")); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
114 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
115 |
PointToPointHelper leafLink; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
116 |
leafLink.SetDeviceAttribute ("DataRate", StringValue ("1Mbps")); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
117 |
leafLink.SetChannelAttribute ("Delay", StringValue ("2ms")); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
118 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
119 |
// Add link connecting routers |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
120 |
NetDeviceContainer routerDevices; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
121 |
routerDevices = routerLink.Install (routerNodes); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
122 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
123 |
// Add links for left side leaf nodes to left router |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
124 |
NetDeviceContainer leftRouterDevices; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
125 |
NetDeviceContainer leftLeafDevices; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
126 |
for (uint32_t i = 0; i < 4; ++i) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
127 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
128 |
NetDeviceContainer temp = leafLink.Install (leftLeafNodes.Get (i), routerNodes.Get (0)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
129 |
leftLeafDevices.Add (temp.Get (0)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
130 |
leftRouterDevices.Add (temp.Get (1)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
131 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
132 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
133 |
// Add links for right side leaf nodes to right router |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
134 |
NetDeviceContainer rightRouterDevices; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
135 |
NetDeviceContainer rightLeafDevices; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
136 |
for (uint32_t i = 0; i < 4; ++i) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
137 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
138 |
NetDeviceContainer temp = leafLink.Install (rightLeafNodes.Get (i), routerNodes.Get (1)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
139 |
rightLeafDevices.Add (temp.Get (0)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
140 |
rightRouterDevices.Add (temp.Get (1)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
141 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
142 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
143 |
InternetStackHelper stack; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
144 |
Ipv4NixVectorHelper nixRouting; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
145 |
Ipv4StaticRoutingHelper staticRouting; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
146 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
147 |
Ipv4ListRoutingHelper list; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
148 |
list.Add (staticRouting, 0); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
149 |
list.Add (nixRouting, 10); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
150 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
151 |
if (nix) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
152 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
153 |
stack.SetRoutingHelper (list); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
154 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
155 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
156 |
stack.InstallAll (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
157 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
158 |
Ipv4InterfaceContainer routerInterfaces; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
159 |
Ipv4InterfaceContainer leftLeafInterfaces; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
160 |
Ipv4InterfaceContainer leftRouterInterfaces; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
161 |
Ipv4InterfaceContainer rightLeafInterfaces; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
162 |
Ipv4InterfaceContainer rightRouterInterfaces; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
163 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
164 |
Ipv4AddressHelper leftAddress; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
165 |
leftAddress.SetBase ("10.1.1.0", "255.255.255.0"); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
166 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
167 |
Ipv4AddressHelper routerAddress; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
168 |
routerAddress.SetBase ("10.2.1.0", "255.255.255.0"); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
169 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
170 |
Ipv4AddressHelper rightAddress; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
171 |
rightAddress.SetBase ("10.3.1.0", "255.255.255.0"); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
172 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
173 |
// Router-to-Router interfaces |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
174 |
routerInterfaces = routerAddress.Assign (routerDevices); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
175 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
176 |
// Left interfaces |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
177 |
for (uint32_t i = 0; i < 4; ++i) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
178 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
179 |
NetDeviceContainer ndc; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
180 |
ndc.Add (leftLeafDevices.Get (i)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
181 |
ndc.Add (leftRouterDevices.Get (i)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
182 |
Ipv4InterfaceContainer ifc = leftAddress.Assign (ndc); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
183 |
leftLeafInterfaces.Add (ifc.Get (0)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
184 |
leftRouterInterfaces.Add (ifc.Get (1)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
185 |
leftAddress.NewNetwork (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
186 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
187 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
188 |
// Right interfaces |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
189 |
for (uint32_t i = 0; i < 4; ++i) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
190 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
191 |
NetDeviceContainer ndc; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
192 |
ndc.Add (rightLeafDevices.Get (i)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
193 |
ndc.Add (rightRouterDevices.Get (i)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
194 |
Ipv4InterfaceContainer ifc = rightAddress.Assign (ndc); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
195 |
rightLeafInterfaces.Add (ifc.Get (0)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
196 |
rightRouterInterfaces.Add (ifc.Get (1)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
197 |
rightAddress.NewNetwork (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
198 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
199 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
200 |
if (!nix) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
201 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
202 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
203 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
204 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
205 |
// Create a packet sink on the right leafs to receive packets from left leafs |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
206 |
uint16_t port = 50000; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
207 |
if (systemId == 1) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
208 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
209 |
Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
210 |
PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
211 |
ApplicationContainer sinkApp; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
212 |
for (uint32_t i = 0; i < 4; ++i) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
213 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
214 |
sinkApp.Add (sinkHelper.Install (rightLeafNodes.Get (i))); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
215 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
216 |
sinkApp.Start (Seconds (1.0)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
217 |
sinkApp.Stop (Seconds (5)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
218 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
219 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
220 |
// Create the OnOff applications to send |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
221 |
if (systemId == 0) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
222 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
223 |
OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ()); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
224 |
clientHelper.SetAttribute |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
225 |
("OnTime", RandomVariableValue (ConstantVariable (1))); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
226 |
clientHelper.SetAttribute |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
227 |
("OffTime", RandomVariableValue (ConstantVariable (0))); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
228 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
229 |
ApplicationContainer clientApps; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
230 |
for (uint32_t i = 0; i < 4; ++i) |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
231 |
{ |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
232 |
AddressValue remoteAddress |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
233 |
(InetSocketAddress (rightLeafInterfaces.GetAddress (i), port)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
234 |
clientHelper.SetAttribute ("Remote", remoteAddress); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
235 |
clientApps.Add (clientHelper.Install (leftLeafNodes.Get (i))); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
236 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
237 |
clientApps.Start (Seconds (1.0)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
238 |
clientApps.Stop (Seconds (5)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
239 |
} |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
240 |
|
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
241 |
Simulator::Stop (Seconds (5)); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
242 |
Simulator::Run (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
243 |
Simulator::Destroy (); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
244 |
return 0; |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
245 |
#else |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
246 |
NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
247 |
#endif |
0ce37bf4f1c1
Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff
changeset
|
248 |
} |