60#include "ns3/core-module.h"
61#include "ns3/internet-stack-helper.h"
62#include "ns3/ipv4-address-helper.h"
63#include "ns3/ipv4-global-routing-helper.h"
64#include "ns3/ipv4-list-routing-helper.h"
65#include "ns3/ipv4-static-routing-helper.h"
66#include "ns3/mpi-interface.h"
67#include "ns3/network-module.h"
68#include "ns3/nix-vector-helper.h"
69#include "ns3/on-off-helper.h"
70#include "ns3/packet-sink-helper.h"
71#include "ns3/packet-sink.h"
72#include "ns3/point-to-point-helper.h"
100 MPI_Comm_rank(splitComm, &otherId);
101 MPI_Comm_size(splitComm, &otherSize);
112 RANK0COUTAPPEND(
"in MPI_COMM_WORLD: " << SinkTracer::GetWorldRank() <<
":"
113 << SinkTracer::GetWorldSize() <<
", in splitComm: "
114 << otherId <<
":" << otherSize << std::endl);
119main(
int argc,
char* argv[])
122 bool nullmsg =
false;
126 bool testing =
false;
130 cmd.AddValue(
"nix",
"Enable the use of nix-vector or global routing", nix);
131 cmd.AddValue(
"nullmsg",
132 "Enable the use of null-message synchronization (instead of granted time window)",
134 cmd.AddValue(
"tracing",
"Enable pcap tracing",
tracing);
135 cmd.AddValue(
"init",
"ns-3 should initialize MPI by calling MPI_Init", init);
136 cmd.AddValue(
"verbose",
"verbose output",
verbose);
137 cmd.AddValue(
"test",
"Enable regression test output", testing);
138 cmd.Parse(argc, argv);
145 GlobalValue::Bind(
"SimulatorImplementationType",
150 GlobalValue::Bind(
"SimulatorImplementationType",
159 MPI_Init(&argc, &argv);
164 MpiInterface::Enable(&argc, &argv);
169 auto worldSize = SinkTracer::GetWorldSize();
170 auto worldRank = SinkTracer::GetWorldRank();
172 if ((!init) && (worldSize != 2))
174 RANK0COUT(
"This simulation requires exactly 2 logical processors if --init is not set."
181 RANK0COUT(
"This simulation requires 2 or more logical processors." << std::endl);
191 bool freeComm =
false;
193 MPI_Comm splitComm = MPI_COMM_WORLD;
195 std::string ns3Ranks;
197 int color = MPI_UNDEFINED;
201 std::stringstream ss;
203 ss <<
"MPI_COMM_WORLD (" << worldSize <<
" ranks)";
205 splitComm = MPI_COMM_WORLD;
213 if (worldRank == 1 || worldRank == 2)
221 std::stringstream ss;
222 ss <<
"Split [1-2] (out of " << worldSize <<
" ranks) from MPI_COMM_WORLD";
226 MPI_Comm_split(MPI_COMM_WORLD, color, worldRank, &splitComm);
232 MpiInterface::Enable(splitComm);
239 RANK0COUT(
"Routing: " << (nix ?
"nix-vector" :
"global") <<
"\n");
240 RANK0COUT(
"Synchronization: " << (nullmsg ?
"null-message" :
"granted time window (YAWNS)")
243 << (init ?
"explicitly by this program" :
"implicitly by ns3::MpiInterface::Enable()")
245 RANK0COUT(
"ns-3 Communicator: " << ns3Ranks <<
"\n");
248 RANK0COUT(
"Rank assignments:" << std::endl);
266 MPI_Recv(&token, 1, MPI_INT, worldRank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
270 MPI_Send(&token, 1, MPI_INT, (worldRank + 1) % worldSize, 0, MPI_COMM_WORLD);
274 MPI_Recv(&token, 1, MPI_INT, worldSize - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
290 MpiInterface::Disable();
310 uint32_t systemId = MpiInterface::GetSystemId();
318 RANK0COUT(
"This simulation requires at least 2 logical processors." << std::endl);
329 leftLeafNodes.
Create(4, 0);
335 Ptr<Node> routerNode1 = CreateObject<Node>(0);
336 Ptr<Node> routerNode2 = CreateObject<Node>(1);
337 routerNodes.
Add(routerNode1);
338 routerNodes.
Add(routerNode2);
342 rightLeafNodes.
Create(4, 1);
354 routerDevices = routerLink.
Install(routerNodes);
362 leftLeafDevices.
Add(temp.
Get(0));
363 leftRouterDevices.
Add(temp.
Get(1));
372 rightLeafDevices.
Add(temp.
Get(0));
373 rightRouterDevices.
Add(temp.
Get(1));
381 list.Add(staticRouting, 0);
382 list.Add(nixRouting, 10);
398 leftAddress.
SetBase(
"10.1.1.0",
"255.255.255.0");
401 routerAddress.
SetBase(
"10.2.1.0",
"255.255.255.0");
404 rightAddress.
SetBase(
"10.3.1.0",
"255.255.255.0");
407 routerInterfaces = routerAddress.
Assign(routerDevices);
413 ndc.
Add(leftLeafDevices.
Get(i));
414 ndc.
Add(leftRouterDevices.
Get(i));
416 leftLeafInterfaces.
Add(ifc.
Get(0));
417 leftRouterInterfaces.
Add(ifc.
Get(1));
425 ndc.
Add(rightLeafDevices.
Get(i));
426 ndc.
Add(rightRouterDevices.
Get(i));
428 rightLeafInterfaces.
Add(ifc.
Get(0));
429 rightRouterInterfaces.
Add(ifc.
Get(1));
435 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
442 routerLink.
EnablePcap(
"router-left", routerDevices,
true);
443 leafLink.
EnablePcap(
"leaf-left", leftLeafDevices,
true);
448 routerLink.
EnablePcap(
"router-right", routerDevices,
true);
449 leafLink.
EnablePcap(
"leaf-right", rightLeafDevices,
true);
454 uint16_t
port = 50000;
462 auto apps = sinkHelper.Install(rightLeafNodes.
Get(i));
463 auto sink = DynamicCast<PacketSink>(apps.Get(0));
480 clientHelper.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
481 clientHelper.SetAttribute(
"OffTime",
482 StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
488 clientHelper.SetAttribute(
"Remote", remoteAddress);
499 Simulator::Destroy();
507 MPI_Comm_free(&splitComm);
512 SinkTracer::Verify(4);
517 MpiInterface::Disable();
a polymophic address class
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Parse command-line arguments.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address NewNetwork()
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class that adds ns3::Ipv4ListRouting objects.
Helper class that adds ns3::Ipv4StaticRouting objects.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Helper class that adds Nix-vector routing to nodes.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
Hold variables of type string.
Hold an unsigned integer type.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void SetDefault(std::string name, const AttributeValue &value)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define RANK0COUT(x)
Write to std::cout only from rank 0.
#define RANK0COUTAPPEND(x)
Append to std::cout only from rank 0.
Time Seconds(double value)
Construct a Time in the indicated unit.
Common methods for MPI examples.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
@ LOG_LEVEL_INFO
LOG_INFO and above.
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added.
void LogComponentEnable(const char *name, enum LogLevel level)
Enable the logging output associated with that log component.
void ReportRank(int color, MPI_Comm splitComm)
Report my rank, in both MPI_COMM_WORLD and the split communicator.
const int NS_COLOR
Tag for whether this rank should go into a new communicator ns-3 ranks will have color == 1.
const int NOT_NS_COLOR
Tag for whether this rank should go into a new communicator ns-3 ranks will have color == 1.
bool tracing
Flag to enable/disable generation of tracing files.
Ptr< PacketSink > sink
Pointer to the packet sink application.