OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * This program is free software; you can redistribute it and/or modify | 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 | 4 * it under the terms of the GNU General Public License version 2 as |
5 * published by the Free Software Foundation; | 5 * published by the Free Software Foundation; |
6 * | 6 * |
7 * This program is distributed in the hope that it will be useful, | 7 * This program is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #endif | 59 #endif |
60 | 60 |
61 using namespace ns3; | 61 using namespace ns3; |
62 | 62 |
63 NS_LOG_COMPONENT_DEFINE ("SimpleDistributed"); | 63 NS_LOG_COMPONENT_DEFINE ("SimpleDistributed"); |
64 | 64 |
65 int | 65 int |
66 main (int argc, char *argv[]) | 66 main (int argc, char *argv[]) |
67 { | 67 { |
68 #ifdef NS3_MPI | 68 #ifdef NS3_MPI |
69 // Distributed simulation setup | 69 |
| 70 bool nix = true; |
| 71 bool nullmsg = false; |
| 72 bool tracing = false; |
| 73 |
| 74 // Parse command line |
| 75 CommandLine cmd; |
| 76 cmd.AddValue ("nix", "Enable the use of nix-vector or global routing", nix); |
| 77 cmd.AddValue ("nullmsg", "Enable the use of null-message synchronization", nul
lmsg); |
| 78 cmd.AddValue ("tracing", "Enable pcap tracing", tracing); |
| 79 cmd.Parse (argc, argv); |
| 80 |
| 81 // Distributed simulation setup; by default use granted time window algorithm. |
| 82 if(nullmsg)· |
| 83 { |
| 84 GlobalValue::Bind ("SimulatorImplementationType", |
| 85 StringValue ("ns3::NullMessageSimulatorImpl")); |
| 86 }· |
| 87 else· |
| 88 { |
| 89 GlobalValue::Bind ("SimulatorImplementationType", |
| 90 StringValue ("ns3::DistributedSimulatorImpl")); |
| 91 } |
| 92 |
| 93 // Enable parallel simulator with the command line arguments |
70 MpiInterface::Enable (&argc, &argv); | 94 MpiInterface::Enable (&argc, &argv); |
71 GlobalValue::Bind ("SimulatorImplementationType", | |
72 StringValue ("ns3::DistributedSimulatorImpl")); | |
73 | 95 |
74 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); | 96 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); |
75 | 97 |
76 uint32_t systemId = MpiInterface::GetSystemId (); | 98 uint32_t systemId = MpiInterface::GetSystemId (); |
77 uint32_t systemCount = MpiInterface::GetSize (); | 99 uint32_t systemCount = MpiInterface::GetSize (); |
78 | 100 |
79 // Check for valid distributed parameters. | 101 // Check for valid distributed parameters. |
80 // Must have 2 and only 2 Logical Processors (LPs) | 102 // Must have 2 and only 2 Logical Processors (LPs) |
81 if (systemCount != 2) | 103 if (systemCount != 2) |
82 { | 104 { |
83 std::cout << "This simulation requires 2 and only 2 logical processors." <
< std::endl; | 105 std::cout << "This simulation requires 2 and only 2 logical processors." <
< std::endl; |
84 return 1; | 106 return 1; |
85 } | 107 } |
86 | 108 |
87 // Some default values | 109 // Some default values |
88 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512)); | 110 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512)); |
89 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1Mbps")); | 111 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1Mbps")); |
90 Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (512)); | 112 Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (512)); |
91 bool nix = true; | |
92 | |
93 // Parse command line | |
94 CommandLine cmd; | |
95 cmd.AddValue ("nix", "Enable the use of nix-vector or global routing", nix); | |
96 cmd.Parse (argc, argv); | |
97 | 113 |
98 // Create leaf nodes on left with system id 0 | 114 // Create leaf nodes on left with system id 0 |
99 NodeContainer leftLeafNodes; | 115 NodeContainer leftLeafNodes; |
100 leftLeafNodes.Create (4, 0); | 116 leftLeafNodes.Create (4, 0); |
101 | 117 |
102 // Create router nodes. Left router | 118 // Create router nodes. Left router |
103 // with system id 0, right router with | 119 // with system id 0, right router with |
104 // system id 1 | 120 // system id 1 |
105 NodeContainer routerNodes; | 121 NodeContainer routerNodes; |
106 Ptr<Node> routerNode1 = CreateObject<Node> (0); | 122 Ptr<Node> routerNode1 = CreateObject<Node> (0); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 rightLeafInterfaces.Add (ifc.Get (0)); | 215 rightLeafInterfaces.Add (ifc.Get (0)); |
200 rightRouterInterfaces.Add (ifc.Get (1)); | 216 rightRouterInterfaces.Add (ifc.Get (1)); |
201 rightAddress.NewNetwork (); | 217 rightAddress.NewNetwork (); |
202 } | 218 } |
203 | 219 |
204 if (!nix) | 220 if (!nix) |
205 { | 221 { |
206 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); | 222 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
207 } | 223 } |
208 | 224 |
| 225 if (tracing == true) |
| 226 { |
| 227 if (systemId == 0) |
| 228 { |
| 229 routerLink.EnablePcap("router-left", routerDevices, true); |
| 230 leafLink.EnablePcap("leaf-left", leftLeafDevices, true); |
| 231 } |
| 232 ······ |
| 233 if (systemId == 1) |
| 234 { |
| 235 routerLink.EnablePcap("router-right", routerDevices, true); |
| 236 leafLink.EnablePcap("leaf-right", rightLeafDevices, true); |
| 237 } |
| 238 } |
| 239 |
209 // Create a packet sink on the right leafs to receive packets from left leafs | 240 // Create a packet sink on the right leafs to receive packets from left leafs |
210 uint16_t port = 50000; | 241 uint16_t port = 50000; |
211 if (systemId == 1) | 242 if (systemId == 1) |
212 { | 243 { |
213 Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)
); | 244 Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)
); |
214 PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress); | 245 PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkLocalAddress); |
215 ApplicationContainer sinkApp; | 246 ApplicationContainer sinkApp; |
216 for (uint32_t i = 0; i < 4; ++i) | 247 for (uint32_t i = 0; i < 4; ++i) |
217 { | 248 { |
218 sinkApp.Add (sinkHelper.Install (rightLeafNodes.Get (i))); | 249 sinkApp.Add (sinkHelper.Install (rightLeafNodes.Get (i))); |
(...skipping 26 matching lines...) Expand all Loading... |
245 Simulator::Stop (Seconds (5)); | 276 Simulator::Stop (Seconds (5)); |
246 Simulator::Run (); | 277 Simulator::Run (); |
247 Simulator::Destroy (); | 278 Simulator::Destroy (); |
248 // Exit the MPI execution environment | 279 // Exit the MPI execution environment |
249 MpiInterface::Disable (); | 280 MpiInterface::Disable (); |
250 return 0; | 281 return 0; |
251 #else | 282 #else |
252 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); | 283 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); |
253 #endif | 284 #endif |
254 } | 285 } |
OLD | NEW |