60 #include "ns3/core-module.h"    61 #include "ns3/network-module.h"    62 #include "ns3/mpi-interface.h"    63 #include "ns3/ipv4-global-routing-helper.h"    64 #include "ns3/ipv4-static-routing-helper.h"    65 #include "ns3/ipv4-list-routing-helper.h"    66 #include "ns3/point-to-point-helper.h"    67 #include "ns3/internet-stack-helper.h"    68 #include "ns3/ipv4-nix-vector-helper.h"    69 #include "ns3/ipv4-address-helper.h"    70 #include "ns3/on-off-helper.h"    71 #include "ns3/packet-sink.h"    72 #include "ns3/packet-sink-helper.h"    97   MPI_Comm_rank (splitComm, &otherId);
    98   MPI_Comm_size (splitComm, &otherSize);
   110                     << 
", in splitComm: "    << otherId   << 
":" << otherSize
   116 main (
int argc, 
char *argv[])
   119   bool nullmsg = 
false;
   123   bool testing = 
false;
   127   cmd.AddValue (
"nix", 
"Enable the use of nix-vector or global routing", nix);
   128   cmd.AddValue (
"nullmsg", 
"Enable the use of null-message synchronization (instead of granted time window)", nullmsg);
   129   cmd.AddValue (
"tracing", 
"Enable pcap tracing", 
tracing);
   130   cmd.AddValue (
"init", 
"ns-3 should initialize MPI by calling MPI_Init", init);
   131   cmd.AddValue (
"verbose", 
"verbose output", 
verbose);
   132   cmd.AddValue (
"test", 
"Enable regression test output", testing);
   133   cmd.Parse (argc, argv);
   154       MPI_Init(&argc, &argv);
   167   if ( (!init) && (worldSize != 2))
   169       RANK0COUT (
"This simulation requires exactly 2 logical processors if --init is not set." << std::endl);
   175       RANK0COUT (
"This simulation requires 2  or more logical processors." << std::endl);
   185   bool freeComm = 
false;  
   187   MPI_Comm splitComm = MPI_COMM_WORLD;
   189   std::string ns3Ranks;
   191   int color = MPI_UNDEFINED;
   196       std::stringstream ss;
   198       ss << 
"MPI_COMM_WORLD (" << worldSize << 
" ranks)";
   199       ns3Ranks = ss.str ();
   200       splitComm = MPI_COMM_WORLD;
   208       if (worldRank == 1 || worldRank == 2)
   216       std::stringstream ss;
   217       ss << 
"Split [1-2] (out of " << worldSize << 
" ranks) from MPI_COMM_WORLD";
   218       ns3Ranks = ss.str ();
   221       MPI_Comm_split (MPI_COMM_WORLD, color, worldRank, &splitComm);
   235   RANK0COUT (
"Routing:           " << (nix ? 
"nix-vector" : 
"global") << 
"\n");
   236   RANK0COUT (
"Synchronization:   " << (nullmsg ? 
"null-message" : 
"granted time window (YAWNS)") << 
"\n");
   237   RANK0COUT (
"MPI_Init called:   " << (init ? 
"explicitly by this program" : 
"implicitly by ns3::MpiInterface::Enable()") << 
"\n" );
   238   RANK0COUT (
"ns-3 Communicator: " << ns3Ranks << 
"\n");
   241   RANK0COUT (
"Rank assignments:" << std::endl);
   259           MPI_Recv (&token, 1, MPI_INT, worldRank - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
   263       MPI_Send (&token, 1, MPI_INT, (worldRank + 1) % worldSize, 0, MPI_COMM_WORLD);
   267           MPI_Recv (&token, 1, MPI_INT, worldSize - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
   311       RANK0COUT (
"This simulation requires at least 2 logical processors." << std::endl);
   322   leftLeafNodes.
Create (4, 0);
   328   Ptr<Node> routerNode1 = CreateObject<Node> (0);
   329   Ptr<Node> routerNode2 = CreateObject<Node> (1);
   330   routerNodes.
Add (routerNode1);
   331   routerNodes.
Add (routerNode2);
   335   rightLeafNodes.
Create (4, 1);
   347   routerDevices = routerLink.
Install (routerNodes);
   352   for (uint32_t i = 0; i < 4; ++i)
   355       leftLeafDevices.
Add (temp.
Get (0));
   356       leftRouterDevices.
Add (temp.
Get (1));
   362   for (uint32_t i = 0; i < 4; ++i)
   365       rightLeafDevices.
Add (temp.
Get (0));
   366       rightRouterDevices.
Add (temp.
Get (1));
   374   list.Add (staticRouting, 0);
   375   list.Add (nixRouting, 10);
   391   leftAddress.
SetBase (
"10.1.1.0", 
"255.255.255.0");
   394   routerAddress.
SetBase (
"10.2.1.0", 
"255.255.255.0");
   397   rightAddress.
SetBase (
"10.3.1.0", 
"255.255.255.0");
   400   routerInterfaces = routerAddress.
Assign (routerDevices);
   403   for (uint32_t i = 0; i < 4; ++i)
   406       ndc.
Add (leftLeafDevices.
Get (i));
   407       ndc.
Add (leftRouterDevices.
Get (i));
   409       leftLeafInterfaces.
Add (ifc.
Get (0));
   410       leftRouterInterfaces.
Add (ifc.
Get (1));
   415   for (uint32_t i = 0; i < 4; ++i)
   418       ndc.
Add (rightLeafDevices.
Get (i));
   419       ndc.
Add (rightRouterDevices.
Get (i));
   421       rightLeafInterfaces.
Add (ifc.
Get (0));
   422       rightRouterInterfaces.
Add (ifc.
Get (1));
   435           routerLink.
EnablePcap(
"router-left", routerDevices, 
true);
   436           leafLink.
EnablePcap(
"leaf-left", leftLeafDevices, 
true);
   441           routerLink.
EnablePcap(
"router-right", routerDevices, 
true);
   442           leafLink.
EnablePcap(
"leaf-right", rightLeafDevices, 
true);
   447   uint16_t 
port = 50000;
   453       for (uint32_t i = 0; i < 4; ++i)
   455           auto apps = sinkHelper.Install (rightLeafNodes.
Get (i));
   456           auto sink = DynamicCast<PacketSink> (apps.Get (0));
   472       clientHelper.SetAttribute
   473         (
"OnTime", 
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
   474       clientHelper.SetAttribute
   475         (
"OffTime", 
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
   478       for (uint32_t i = 0; i < 4; ++i)
   482           clientHelper.SetAttribute (
"Remote", remoteAddress);
   483           clientApps.Add (clientHelper.Install (leftLeafNodes.
Get (i)));
   501       MPI_Comm_free (&splitComm);
 
holds a vector of ns3::Application pointers. 
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index. 
static int GetWorldRank(void)
Get the MPI rank in the world communicator. 
static Ipv4Address GetAny(void)
holds a vector of std::pair of Ptr<Ipv4> and interface index. 
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation. 
Hold variables of type string. 
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static int GetWorldSize(void)
Get the MPI size of the world communicator. 
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours. 
static void Run(void)
Run the simulation. 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
Helper class that adds Nix-vector routing to nodes. 
aggregate IP/TCP/UDP functionality to existing Nodes. 
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
static void Disable()
Clean up the ns-3 parallel communications interface. 
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. 
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes. 
Common methods for MPI examples. 
static void Init(void)
PacketSink receive trace callback. 
a polymophic address class 
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component. 
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container. 
static void Enable(int *pargc, char ***pargv)
Setup the parallel communication interface. 
Hold an unsigned integer type. 
holds a vector of ns3::NetDevice pointers 
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count. 
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments. 
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy(). 
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context. 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
keep track of a set of node pointers. 
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper. 
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define RANK0COUTAPPEND(x)
  AttributeValue implementation for Address. 
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container. 
static uint32_t GetSystemId()
Get the id number of this rank. 
Helper class that adds ns3::Ipv4StaticRouting objects. 
static void Stop(void)
Tell the Simulator the calling event should be the last one executed. 
Time Seconds(double value)
Construct a Time in the indicated unit. 
void SetDefault(std::string name, const AttributeValue &value)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index. 
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
Helper class that adds ns3::Ipv4ListRouting objects. 
A helper class to make life easier while doing simple IPv4 address assignment in scripts. 
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer. 
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device. 
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...
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback. 
static uint32_t GetSize()
Get the number of ranks used by ns-3. 
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
bool tracing
Flag to enable/disable generation of tracing files. 
void ReportRank(int color, MPI_Comm splitComm)
Report my rank, in both MPI_COMM_WORLD and the split communicator. 
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address. 
#define RANK0COUT(x)
Write to std::cout only from rank 0.