|
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 |
|
17 |
#include "ns3/core-module.h" |
18 |
#include "ns3/network-module.h" |
19 |
#include "ns3/internet-module.h" |
20 |
#include "ns3/point-to-point-module.h" |
21 |
#include "ns3/applications-module.h" |
22 |
#include "ns3/dce-module.h" |
23 |
#include "ns3/mpi-interface.h" |
24 |
|
25 |
using namespace ns3; |
26 |
|
27 |
// Run Hint : $ mpirun -np 2 dce-mpi-udp |
28 |
|
29 |
int |
30 |
main (int argc, char *argv[]) |
31 |
{ |
32 |
// Distributed simulation setup |
33 |
MpiInterface::Enable (&argc, &argv); |
34 |
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::DistributedSimulatorImpl")); |
35 |
|
36 |
uint32_t systemId = MpiInterface::GetSystemId (); |
37 |
uint32_t systemCount = MpiInterface::GetSize (); |
38 |
|
39 |
|
40 |
// Check for valid distributed parameters. |
41 |
// Must have 2 and only 2 Logical Processors (LPs) |
42 |
|
43 |
if (systemCount != 2) |
44 |
{ |
45 |
std::cout << "This simulation requires 2 and only 2 logical processors." << std::endl; |
46 |
return 1; |
47 |
} |
48 |
|
49 |
//------------------------------------------------- |
50 |
|
51 |
|
52 |
CommandLine cmd; |
53 |
cmd.Parse (argc, argv); |
54 |
|
55 |
NodeContainer nodes; |
56 |
Ptr<Node> node1 = CreateObject<Node> (0); // <------ for MPI, it goes to run in core_1 (process 1) |
57 |
Ptr<Node> node2 = CreateObject<Node> (1); // <------ for MPI, " _2 2 |
58 |
nodes.Add (node1); |
59 |
nodes.Add (node2); |
60 |
|
61 |
InternetStackHelper stack; |
62 |
stack.Install (nodes); |
63 |
|
64 |
PointToPointHelper pointToPoint; |
65 |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("100Mbps")); |
66 |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ms")); |
67 |
|
68 |
NetDeviceContainer devices; |
69 |
devices = pointToPoint.Install (nodes); |
70 |
|
71 |
Ipv4AddressHelper address; |
72 |
address.SetBase ("10.1.1.0", "255.255.255.252"); |
73 |
Ipv4InterfaceContainer interfaces = address.Assign (devices); |
74 |
|
75 |
// setup ip routes |
76 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
77 |
|
78 |
DceManagerHelper dceManager; |
79 |
dceManager.Install (nodes); |
80 |
|
81 |
DceApplicationHelper dce; |
82 |
ApplicationContainer apps; |
83 |
|
84 |
dce.SetStackSize (1<<20); |
85 |
|
86 |
if (0==systemId) |
87 |
{ |
88 |
dce.SetBinary ("udp-server"); |
89 |
dce.ResetArguments(); |
90 |
apps = dce.Install (node1); |
91 |
apps.Start (Seconds (4.0)); |
92 |
} |
93 |
|
94 |
if (1==systemId) |
95 |
{ |
96 |
dce.SetBinary ("udp-client"); |
97 |
dce.ResetArguments(); |
98 |
dce.AddArgument ("10.1.1.1"); |
99 |
apps = dce.Install (node2); |
100 |
apps.Start (Seconds (4.5)); |
101 |
} |
102 |
|
103 |
|
104 |
Simulator::Stop (Seconds(1050.0)); |
105 |
Simulator::Run (); |
106 |
Simulator::Destroy (); |
107 |
|
108 |
//------------------------------------------------- |
109 |
|
110 |
// Exit the MPI execution environment |
111 |
MpiInterface::Disable (); |
112 |
return 0; |
113 |
|
114 |
} |