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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // -------------------------|---------------------------- | 48 // -------------------------|---------------------------- |
49 | 49 |
50 using namespace ns3; | 50 using namespace ns3; |
51 | 51 |
52 NS_LOG_COMPONENT_DEFINE ("ThirdExampleDistributed"); | 52 NS_LOG_COMPONENT_DEFINE ("ThirdExampleDistributed"); |
53 | 53 |
54 int· | 54 int· |
55 main (int argc, char *argv[]) | 55 main (int argc, char *argv[]) |
56 { | 56 { |
57 #ifdef NS3_MPI | 57 #ifdef NS3_MPI |
58 // Distributed simulation setup | |
59 MpiInterface::Enable (&argc, &argv); | |
60 GlobalValue::Bind ("SimulatorImplementationType", | |
61 StringValue ("ns3::DistributedSimulatorImpl")); | |
62 | |
63 uint32_t systemId = MpiInterface::GetSystemId (); | |
64 uint32_t systemCount = MpiInterface::GetSize (); | |
65 | |
66 // Check for valid distributed parameters. | |
67 // Must have 2 and only 2 Logical Processors (LPs) | |
68 if (systemCount != 2) | |
69 { | |
70 std::cout << "This simulation requires 2 and only 2 logical processors." <
< std::endl; | |
71 return 1; | |
72 } | |
73 | 58 |
74 bool verbose = true; | 59 bool verbose = true; |
75 uint32_t nCsma = 3; | 60 uint32_t nCsma = 3; |
76 uint32_t nWifi = 3; | 61 uint32_t nWifi = 3; |
| 62 bool nullmsg = false; |
77 bool tracing = false; | 63 bool tracing = false; |
78 | 64 |
79 CommandLine cmd; | 65 CommandLine cmd; |
80 cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); | 66 cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); |
81 cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); | 67 cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); |
82 cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); | 68 cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); |
| 69 cmd.AddValue ("nullmsg", "Enable the use of null-message synchronization", nul
lmsg); |
83 cmd.AddValue ("tracing", "Enable pcap tracing", tracing); | 70 cmd.AddValue ("tracing", "Enable pcap tracing", tracing); |
84 cmd.Parse (argc,argv); | 71 cmd.Parse (argc,argv); |
85 | 72 |
86 // Check for valid number of csma or wifi nodes | 73 // Check for valid number of csma or wifi nodes |
87 // 250 should be enough, otherwise IP addresses· | 74 // 250 should be enough, otherwise IP addresses· |
88 // soon become an issue | 75 // soon become an issue |
89 if (nWifi > 250 || nCsma > 250) | 76 if (nWifi > 250 || nCsma > 250) |
90 { | 77 { |
91 std::cout << "Too many wifi or csma nodes, max 200 each." << std::endl; | 78 std::cout << "Too many wifi or csma nodes, max 200 each." << std::endl; |
92 return 1; | 79 return 1; |
93 } | 80 } |
94 | 81 |
95 if (verbose) | 82 if (verbose) |
96 { | 83 { |
97 LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); | 84 LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); |
98 LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); | 85 LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); |
99 } | 86 } |
100 | 87 |
| 88 // Distributed simulation setup; by default use granted time window algorithm. |
| 89 if(nullmsg)· |
| 90 { |
| 91 GlobalValue::Bind ("SimulatorImplementationType", |
| 92 StringValue ("ns3::NullMessageSimulatorImpl")); |
| 93 }· |
| 94 else· |
| 95 { |
| 96 GlobalValue::Bind ("SimulatorImplementationType", |
| 97 StringValue ("ns3::DistributedSimulatorImpl")); |
| 98 } |
| 99 |
| 100 MpiInterface::Enable (&argc, &argv); |
| 101 |
| 102 uint32_t systemId = MpiInterface::GetSystemId (); |
| 103 uint32_t systemCount = MpiInterface::GetSize (); |
| 104 |
| 105 // Check for valid distributed parameters. |
| 106 // Must have 2 and only 2 Logical Processors (LPs) |
| 107 if (systemCount != 2) |
| 108 { |
| 109 std::cout << "This simulation requires 2 and only 2 logical processors." <
< std::endl; |
| 110 return 1; |
| 111 } |
| 112 |
| 113 |
101 NodeContainer p2pNodes; | 114 NodeContainer p2pNodes; |
102 Ptr<Node> p2pNode1 = CreateObject<Node> (0); // Create node with rank 0 | 115 Ptr<Node> p2pNode1 = CreateObject<Node> (0); // Create node with rank 0 |
103 Ptr<Node> p2pNode2 = CreateObject<Node> (1); // Create node with rank 1 | 116 Ptr<Node> p2pNode2 = CreateObject<Node> (1); // Create node with rank 1 |
104 p2pNodes.Add (p2pNode1); | 117 p2pNodes.Add (p2pNode1); |
105 p2pNodes.Add (p2pNode2); | 118 p2pNodes.Add (p2pNode2); |
106 | 119 |
107 PointToPointHelper pointToPoint; | 120 PointToPointHelper pointToPoint; |
108 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); | 121 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
109 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); | 122 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); |
110 | 123 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 Simulator::Run (); | 253 Simulator::Run (); |
241 Simulator::Destroy (); | 254 Simulator::Destroy (); |
242 // Exit the MPI execution environment | 255 // Exit the MPI execution environment |
243 MpiInterface::Disable (); | 256 MpiInterface::Disable (); |
244 return 0; | 257 return 0; |
245 | 258 |
246 #else | 259 #else |
247 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); | 260 NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); |
248 #endif | 261 #endif |
249 } | 262 } |
OLD | NEW |