Files
ns-3-dev/examples/mpi/third-distributed.cc
T
Tom Henderson c26396ec5d merge src/simulator into src/core; move src/core to new module layout
--HG--
rename : src/core/abort.h => src/core/model/abort.h
rename : src/core/assert.h => src/core/model/assert.h
rename : src/core/attribute-accessor-helper.h => src/core/model/attribute-accessor-helper.h
rename : src/core/attribute-helper.h => src/core/model/attribute-helper.h
rename : src/core/attribute-list.cc => src/core/model/attribute-list.cc
rename : src/core/attribute-list.h => src/core/model/attribute-list.h
rename : src/core/attribute.cc => src/core/model/attribute.cc
rename : src/core/attribute.h => src/core/model/attribute.h
rename : src/core/boolean.cc => src/core/model/boolean.cc
rename : src/core/boolean.h => src/core/model/boolean.h
rename : src/core/breakpoint.cc => src/core/model/breakpoint.cc
rename : src/core/breakpoint.h => src/core/model/breakpoint.h
rename : src/simulator/cairo-wideint-private.h => src/core/model/cairo-wideint-private.h
rename : src/simulator/cairo-wideint.c => src/core/model/cairo-wideint.c
rename : src/simulator/calendar-scheduler.cc => src/core/model/calendar-scheduler.cc
rename : src/simulator/calendar-scheduler.h => src/core/model/calendar-scheduler.h
rename : src/core/callback.cc => src/core/model/callback.cc
rename : src/core/callback.h => src/core/model/callback.h
rename : src/core/command-line.cc => src/core/model/command-line.cc
rename : src/core/command-line.h => src/core/model/command-line.h
rename : src/core/config.cc => src/core/model/config.cc
rename : src/core/config.h => src/core/model/config.h
rename : src/core/default-deleter.h => src/core/model/default-deleter.h
rename : src/simulator/default-simulator-impl.cc => src/core/model/default-simulator-impl.cc
rename : src/simulator/default-simulator-impl.h => src/core/model/default-simulator-impl.h
rename : src/core/deprecated.h => src/core/model/deprecated.h
rename : src/core/double.cc => src/core/model/double.cc
rename : src/core/double.h => src/core/model/double.h
rename : src/core/empty.h => src/core/model/empty.h
rename : src/core/enum.cc => src/core/model/enum.cc
rename : src/core/enum.h => src/core/model/enum.h
rename : src/simulator/event-id.cc => src/core/model/event-id.cc
rename : src/simulator/event-id.h => src/core/model/event-id.h
rename : src/simulator/event-impl.cc => src/core/model/event-impl.cc
rename : src/simulator/event-impl.h => src/core/model/event-impl.h
rename : src/core/fatal-error.h => src/core/model/fatal-error.h
rename : src/core/fatal-impl.cc => src/core/model/fatal-impl.cc
rename : src/core/fatal-impl.h => src/core/model/fatal-impl.h
rename : src/core/global-value.cc => src/core/model/global-value.cc
rename : src/core/global-value.h => src/core/model/global-value.h
rename : src/simulator/heap-scheduler.cc => src/core/model/heap-scheduler.cc
rename : src/simulator/heap-scheduler.h => src/core/model/heap-scheduler.h
rename : src/simulator/high-precision-128.cc => src/core/model/high-precision-128.cc
rename : src/simulator/high-precision-128.h => src/core/model/high-precision-128.h
rename : src/simulator/high-precision-cairo.cc => src/core/model/high-precision-cairo.cc
rename : src/simulator/high-precision-cairo.h => src/core/model/high-precision-cairo.h
rename : src/simulator/high-precision-double.h => src/core/model/high-precision-double.h
rename : src/simulator/high-precision.cc => src/core/model/high-precision.cc
rename : src/simulator/high-precision.h => src/core/model/high-precision.h
rename : src/core/int-to-type.h => src/core/model/int-to-type.h
rename : src/core/integer.cc => src/core/model/integer.cc
rename : src/core/integer.h => src/core/model/integer.h
rename : src/simulator/list-scheduler.cc => src/core/model/list-scheduler.cc
rename : src/simulator/list-scheduler.h => src/core/model/list-scheduler.h
rename : src/core/log.cc => src/core/model/log.cc
rename : src/core/log.h => src/core/model/log.h
rename : src/simulator/make-event.cc => src/core/model/make-event.cc
rename : src/simulator/make-event.h => src/core/model/make-event.h
rename : src/simulator/map-scheduler.cc => src/core/model/map-scheduler.cc
rename : src/simulator/map-scheduler.h => src/core/model/map-scheduler.h
rename : src/core/names.cc => src/core/model/names.cc
rename : src/core/names.h => src/core/model/names.h
rename : src/simulator/ns2-calendar-scheduler.cc => src/core/model/ns2-calendar-scheduler.cc
rename : src/simulator/ns2-calendar-scheduler.h => src/core/model/ns2-calendar-scheduler.h
rename : src/simulator/nstime.h => src/core/model/nstime.h
rename : src/core/object-base.cc => src/core/model/object-base.cc
rename : src/core/object-base.h => src/core/model/object-base.h
rename : src/core/object-factory.cc => src/core/model/object-factory.cc
rename : src/core/object-factory.h => src/core/model/object-factory.h
rename : src/core/object-vector.cc => src/core/model/object-vector.cc
rename : src/core/object-vector.h => src/core/model/object-vector.h
rename : src/core/object.cc => src/core/model/object.cc
rename : src/core/object.h => src/core/model/object.h
rename : src/core/pointer.cc => src/core/model/pointer.cc
rename : src/core/pointer.h => src/core/model/pointer.h
rename : src/core/ptr.h => src/core/model/ptr.h
rename : src/core/random-variable.cc => src/core/model/random-variable.cc
rename : src/core/random-variable.h => src/core/model/random-variable.h
rename : src/simulator/realtime-simulator-impl.cc => src/core/model/realtime-simulator-impl.cc
rename : src/simulator/realtime-simulator-impl.h => src/core/model/realtime-simulator-impl.h
rename : src/core/ref-count-base.cc => src/core/model/ref-count-base.cc
rename : src/core/ref-count-base.h => src/core/model/ref-count-base.h
rename : src/core/rng-stream.cc => src/core/model/rng-stream.cc
rename : src/core/rng-stream.h => src/core/model/rng-stream.h
rename : src/simulator/scheduler.cc => src/core/model/scheduler.cc
rename : src/simulator/scheduler.h => src/core/model/scheduler.h
rename : src/core/simple-ref-count.h => src/core/model/simple-ref-count.h
rename : src/simulator/simulation-singleton.h => src/core/model/simulation-singleton.h
rename : src/simulator/simulator-impl.cc => src/core/model/simulator-impl.cc
rename : src/simulator/simulator-impl.h => src/core/model/simulator-impl.h
rename : src/simulator/simulator.cc => src/core/model/simulator.cc
rename : src/simulator/simulator.h => src/core/model/simulator.h
rename : src/core/singleton.h => src/core/model/singleton.h
rename : src/core/string.cc => src/core/model/string.cc
rename : src/core/string.h => src/core/model/string.h
rename : src/simulator/synchronizer.cc => src/core/model/synchronizer.cc
rename : src/simulator/synchronizer.h => src/core/model/synchronizer.h
rename : src/core/system-condition.h => src/core/model/system-condition.h
rename : src/core/system-mutex.h => src/core/model/system-mutex.h
rename : src/core/system-thread.h => src/core/model/system-thread.h
rename : src/core/system-wall-clock-ms.h => src/core/model/system-wall-clock-ms.h
rename : src/core/test.cc => src/core/model/test.cc
rename : src/core/test.h => src/core/model/test.h
rename : src/simulator/time-base.cc => src/core/model/time-base.cc
rename : src/simulator/time-base.h => src/core/model/time-base.h
rename : src/simulator/time.cc => src/core/model/time.cc
rename : src/simulator/timer-impl.h => src/core/model/timer-impl.h
rename : src/simulator/timer.cc => src/core/model/timer.cc
rename : src/simulator/timer.h => src/core/model/timer.h
rename : src/core/trace-source-accessor.cc => src/core/model/trace-source-accessor.cc
rename : src/core/trace-source-accessor.h => src/core/model/trace-source-accessor.h
rename : src/core/traced-callback.h => src/core/model/traced-callback.h
rename : src/core/traced-value.h => src/core/model/traced-value.h
rename : src/core/type-id.cc => src/core/model/type-id.cc
rename : src/core/type-id.h => src/core/model/type-id.h
rename : src/core/type-name.cc => src/core/model/type-name.cc
rename : src/core/type-name.h => src/core/model/type-name.h
rename : src/core/type-traits.h => src/core/model/type-traits.h
rename : src/core/uinteger.cc => src/core/model/uinteger.cc
rename : src/core/uinteger.h => src/core/model/uinteger.h
rename : src/simulator/unix-fd-reader.cc => src/core/model/unix-fd-reader.cc
rename : src/simulator/unix-fd-reader.h => src/core/model/unix-fd-reader.h
rename : src/core/unix-system-condition.cc => src/core/model/unix-system-condition.cc
rename : src/core/unix-system-mutex.cc => src/core/model/unix-system-mutex.cc
rename : src/core/unix-system-thread.cc => src/core/model/unix-system-thread.cc
rename : src/core/unix-system-wall-clock-ms.cc => src/core/model/unix-system-wall-clock-ms.cc
rename : src/core/vector.cc => src/core/model/vector.cc
rename : src/core/vector.h => src/core/model/vector.h
rename : src/simulator/wall-clock-synchronizer.cc => src/core/model/wall-clock-synchronizer.cc
rename : src/simulator/wall-clock-synchronizer.h => src/core/model/wall-clock-synchronizer.h
rename : src/simulator/watchdog.cc => src/core/model/watchdog.cc
rename : src/simulator/watchdog.h => src/core/model/watchdog.h
rename : src/core/win32-system-wall-clock-ms.cc => src/core/model/win32-system-wall-clock-ms.cc
rename : src/core/attribute-test-suite.cc => src/core/test/attribute-test-suite.cc
rename : src/core/callback-test-suite.cc => src/core/test/callback-test-suite.cc
rename : src/core/names-test-suite.cc => src/core/test/names-test-suite.cc
rename : src/core/ptr-test-suite.cc => src/core/test/ptr-test-suite.cc
rename : src/core/rng-test-suite.cc => src/core/test/rng-test-suite.cc
rename : src/core/traced-callback-test-suite.cc => src/core/test/traced-callback-test-suite.cc
rename : src/core/type-traits-test-suite.cc => src/core/test/type-traits-test-suite.cc
2011-02-18 16:05:39 -08:00

244 lines
8.1 KiB
C++

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ns3/core-module.h"
#include "ns3/core-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/mpi-interface.h"
#include "ns3/ipv4-global-routing-helper.h"
#ifdef NS3_MPI
#include <mpi.h>
#endif
// Default Network Topology (same as third.cc from tutorial)
// Distributed simulation, split along the p2p link
// Number of wifi or csma nodes can be increased up to 250
//
// Wifi 10.1.3.0
// AP
// * * * *
// | | | | 10.1.1.0
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// | LAN 10.1.2.0
// |
// Rank 0 | Rank 1
// -------------------------|----------------------------
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdExampleDistributed");
int
main (int argc, char *argv[])
{
#ifdef NS3_MPI
// Distributed simulation setup
MpiInterface::Enable (&argc, &argv);
GlobalValue::Bind ("SimulatorImplementationType",
StringValue ("ns3::DistributedSimulatorImpl"));
uint32_t systemId = MpiInterface::GetSystemId ();
uint32_t systemCount = MpiInterface::GetSize ();
// Check for valid distributed parameters.
// Must have 2 and only 2 Logical Processors (LPs)
if (systemCount != 2)
{
std::cout << "This simulation requires 2 and only 2 logical processors." << std::endl;
return 1;
}
bool verbose = true;
uint32_t nCsma = 3;
uint32_t nWifi = 3;
bool tracing = false;
CommandLine cmd;
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
cmd.Parse (argc,argv);
// Check for valid number of csma or wifi nodes
// 250 should be enough, otherwise IP addresses
// soon become an issue
if (nWifi > 250 || nCsma > 250)
{
std::cout << "Too many wifi or csma nodes, max 200 each." << std::endl;
return 1;
}
if (verbose)
{
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
NodeContainer p2pNodes;
Ptr<Node> p2pNode1 = CreateObject<Node> (0); // Create node with rank 0
Ptr<Node> p2pNode2 = CreateObject<Node> (1); // Create node with rank 1
p2pNodes.Add (p2pNode1);
p2pNodes.Add (p2pNode2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma, 1); // Create csma nodes with rank 1
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi, 0); // Create wifi nodes with rank 0
NodeContainer wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (5.0),
"GridWidth", UintegerValue (10),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-250, 250, -250, 250)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (csmaNodes);
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
address.SetBase ("10.1.3.0", "255.255.255.0");
address.Assign (staDevices);
address.Assign (apDevices);
// If this simulator has system id 1, then
// it should contain the server application,
// since it is on one of the csma nodes
if (systemId == 1)
{
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
}
// If the simulator has system id 0, then
// it should contain the client application,
// since it is on one of the wifi nodes
if (systemId == 0)
{
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps =
echoClient.Install (wifiStaNodes.Get (nWifi - 1));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
}
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
if (tracing == true)
{
// Depending on the system Id (rank), the pcap information
// traced will be different. For example, the ethernet pcap
// will be empty for rank0, since these nodes are placed on
// on rank 1. All ethernet traffic will take place on rank 1.
// Similar differences are seen in the p2p and wirless pcaps.
if (systemId == 0)
{
pointToPoint.EnablePcapAll ("third-distributed-rank0");
phy.EnablePcap ("third-distributed-rank0", apDevices.Get (0));
csma.EnablePcap ("third-distributed-rank0", csmaDevices.Get (0), true);
}
else
{
pointToPoint.EnablePcapAll ("third-distributed-rank1");
phy.EnablePcap ("third-distributed-rank1", apDevices.Get (0));
csma.EnablePcap ("third-distributed-rank1", csmaDevices.Get (0), true);
}
}
Simulator::Run ();
Simulator::Destroy ();
return 0;
#else
NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in");
#endif
}