43 #include "ns3/core-module.h"    44 #include "ns3/internet-module.h"    45 #include "ns3/network-module.h"    46 #include "ns3/on-off-helper.h"    47 #include "ns3/packet-sink-helper.h"    48 #include "ns3/point-to-point-helper.h"    49 #include "ns3/mpi-interface.h"    50 #include "ns3/ipv4-nix-vector-helper.h"    60 main (
int argc, 
char *argv[])
    62   typedef std::vector<NodeContainer> vectorOfNodeContainer;
    63   typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
    64   typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;  
    66   typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
    67   typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
    68   typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer> vectorOfVectorOfVectorOfIpv4InterfaceContainer;
    70   typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
    71   typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
    87   RANK0COUT (
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl);
    93   uint32_t nLANClients = 10;
   102   cmd.AddValue (
"campuses", 
"Number of campus networks", nCN);
   103   cmd.AddValue (
"clients", 
"Number of client nodes per LAN", nLANClients);
   104   cmd.AddValue (
"packets", 
"Number of packets each on/off app should send", nPackets);
   105   cmd.AddValue (
"nix", 
"Toggle the use of nix-vector or global routing", nix);
   106   cmd.AddValue (
"stop", 
"Simulation run time", stop);
   107   cmd.AddValue (
"single", 
"Use single on/off app per campus network", single);
   108   cmd.AddValue (
"verbose", 
"Show extra timing information", 
verbose);
   109   cmd.AddValue (
"test", 
"Enable regression test output", testing);
   111   cmd.Parse (argc,argv);
   115       RANK0COUT (
"Number of total CNs (" << nCN << 
") lower than minimum of 2"   119   if (systemCount > nCN)
   121       RANK0COUT (
"Number of total CNs (" << nCN << 
") should be >= systemCount ("   122                << systemCount << 
")." << std::endl);
   126   RANK0COUT (
"Number of CNs: " << nCN << 
", LAN nodes: " << nLANClients << std::endl);
   128   vectorOfNodeContainer nodes_netLR(nCN);
   129   vectorOfVectorOfNodeContainer nodes_net0(nCN,vectorOfNodeContainer(3));
   130   vectorOfVectorOfNodeContainer nodes_net1(nCN,vectorOfNodeContainer(6));
   131   vectorOfVectorOfNodeContainer nodes_net2(nCN,vectorOfNodeContainer(14));
   132   vectorOfVectorOfNodeContainer nodes_net3(nCN,vectorOfNodeContainer(9));
   134   vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(nCN,vectorOfVectorOfNodeContainer(7,vectorOfNodeContainer(nLANClients)));
   135   vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(nCN,vectorOfVectorOfNodeContainer(5,vectorOfNodeContainer(nLANClients)));
   142   vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN,vectorOfIpv4InterfaceContainer(3));
   143   vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN,vectorOfIpv4InterfaceContainer(6));
   144   vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN,vectorOfIpv4InterfaceContainer(14));
   145   vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN,vectorOfIpv4InterfaceContainer(9));
   146   vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(7,vectorOfIpv4InterfaceContainer(nLANClients)));
   147   vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(nCN,vectorOfVectorOfIpv4InterfaceContainer(5,vectorOfIpv4InterfaceContainer(nLANClients)));
   150   std::ostringstream oss;
   161       stack.SetRoutingHelper (nixRouting); 
   165   for (uint32_t z = 0; z < nCN; ++z)
   167       RANK0COUT (
"Creating Campus Network " << z << 
":" << std::endl);
   170       for (
int i = 0; i < 3; ++i)
   172           Ptr<Node> node = CreateObject<Node> (z % systemCount);
   173           nodes_net0[z][i].Add (node);
   174           stack.Install (nodes_net0[z][i]);
   176       nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
   177       nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
   178       nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
   180       for (
int i = 0; i < 3; ++i)
   182           ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
   186       for (
int i = 0; i < 6; ++i)
   188           Ptr<Node> node = CreateObject<Node> (z % systemCount);
   189           nodes_net1[z][i].Add (node);
   190           stack.Install (nodes_net1[z][i]);
   192       nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
   193       nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
   194       nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
   195       nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
   196       nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
   198       for (
int i = 0; i < 6; ++i)
   204           ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
   208       net0_1.
Add (nodes_net0[z][2].Get (0));
   209       net0_1.
Add (nodes_net1[z][0].Get (0));
   211       ndc0_1 = p2p_1gb5ms.
Install (net0_1);
   213       oss << 10 + z << 
".1.252.0";
   214       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   218       for (
int i = 0; i < 14; ++i)
   220           Ptr<Node> node = CreateObject<Node> (z % systemCount);
   221           nodes_net2[z][i].Add (node);
   222           stack.Install (nodes_net2[z][i]);
   224       nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
   225       nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
   226       nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
   227       nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
   228       nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
   229       nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
   230       nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
   231       nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
   232       nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
   233       nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
   234       nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
   235       nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
   236       nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
   237       nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
   239       for (
int i = 0; i < 14; ++i)
   241           ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
   243       vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
   244       for (
int i = 0; i < 7; ++i)
   247           oss << 10 + z << 
".4." << 15 + i << 
".0";
   248           address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   249           for (uint32_t j = 0; j < nLANClients; ++j)
   251               Ptr<Node> node = CreateObject<Node> (z % systemCount);
   252               nodes_net2LAN[z][i][j].Add (node);
   253               stack.Install (nodes_net2LAN[z][i][j]);
   254               nodes_net2LAN[z][i][j].Add (nodes_net2[z][i + 7].Get (0));
   255               ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
   256               ifs2LAN[z][i][j] = 
address.Assign (ndc2LAN[i][j]);
   261       for (
int i = 0; i < 9; ++i)
   263           Ptr<Node> node = CreateObject<Node> (z % systemCount);
   264           nodes_net3[z][i].Add (node);
   265           stack.Install (nodes_net3[z][i]);
   267       nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
   268       nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
   269       nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
   270       nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
   271       nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
   272       nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
   273       nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
   274       nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
   275       nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
   277       for (
int i = 0; i < 9; ++i)
   279           ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
   281       vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
   282       for (
int i = 0; i < 5; ++i)
   285           oss << 10 + z << 
".5." << 10 + i << 
".0";
   286           address.SetBase (oss.str ().c_str (), 
"255.255.255.255");
   287           for (uint32_t j = 0; j < nLANClients; ++j)
   289               Ptr<Node> node = CreateObject<Node> (z % systemCount);
   290               nodes_net3LAN[z][i][j].Add (node);
   291               stack.Install (nodes_net3LAN[z][i][j]);
   292               nodes_net3LAN[z][i][j].Add (nodes_net3[z][i + 4].Get (0));
   293               ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
   294               ifs3LAN[z][i][j] = 
address.Assign (ndc3LAN[i][j]);
   297       RANK0COUT (
"  Connecting Subnets..." << std::endl);
   299       Ptr<Node> node1 = CreateObject<Node> (z % systemCount);
   300       Ptr<Node> node2 = CreateObject<Node> (z % systemCount);
   301       nodes_netLR[z].Add (node1);
   302       nodes_netLR[z].Add (node2);
   303       stack.Install (nodes_netLR[z]);
   305       ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
   307       NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
   308       net0_4.
Add (nodes_netLR[z].Get (0));
   309       net0_4.
Add (nodes_net0[z][0].Get (0));
   310       net0_5.
Add (nodes_netLR[z].Get (1));
   311       net0_5.
Add (nodes_net0[z][1].Get (0));
   312       net2_4a.
Add (nodes_netLR[z].Get (0));
   313       net2_4a.
Add (nodes_net2[z][0].Get (0));
   314       net2_4b.
Add (nodes_netLR[z].Get (1));
   315       net2_4b.
Add (nodes_net2[z][1].Get (0));
   316       net3_5a.
Add (nodes_netLR[z].Get (1));
   317       net3_5a.
Add (nodes_net3[z][0].Get (0));
   318       net3_5b.
Add (nodes_netLR[z].Get (1));
   319       net3_5b.
Add (nodes_net3[z][1].Get (0));
   321       ndc0_4 = p2p_1gb5ms.
Install (net0_4);
   323       oss << 10 + z << 
".1.253.0";
   324       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   326       ndc0_5 = p2p_1gb5ms.
Install (net0_5);
   328       oss << 10 + z << 
".1.254.0";
   329       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   331       ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
   333       oss << 10 + z << 
".4.253.0";
   334       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   335       ifs = 
address.Assign (ndc2_4a);
   336       ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
   338       oss << 10 + z << 
".4.254.0";
   339       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   340       ifs = 
address.Assign (ndc2_4b);
   341       ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
   343       oss << 10 + z << 
".5.253.0";
   344       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   345       ifs = 
address.Assign (ndc3_5a);
   346       ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
   348       oss << 10 + z << 
".5.254.0";
   349       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   350       ifs = 
address.Assign (ndc3_5b);
   352       RANK0COUT (
"  Assigning IP addresses..." << std::endl);
   353       for (
int i = 0; i < 3; ++i)
   356           oss << 10 + z << 
".1." << 1 + i << 
".0";
   357           address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   358           ifs0[z][i] = 
address.Assign (ndc0[i]);
   360       for (
int i = 0; i < 6; ++i)
   367           oss << 10 + z << 
".2." << 1 + i << 
".0";
   368           address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   369           ifs1[z][i] = 
address.Assign (ndc1[i]);
   372       oss << 10 + z << 
".3.1.0";
   373       address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   375       for (
int i = 0; i < 14; ++i)
   378           oss << 10 + z << 
".4." << 1 + i << 
".0";
   379           address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   380           ifs2[z][i] = 
address.Assign (ndc2[i]);
   382       for (
int i = 0; i < 9; ++i)
   385           oss << 10 + z << 
".5." << 1 + i << 
".0";
   386           address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   387           ifs3[z][i] = 
address.Assign (ndc3[i]);
   393       RANK0COUT (
"Forming Ring Topology..." << std::endl);
   394       vectorOfNodeContainer nodes_ring(nCN);
   395       for (uint32_t z = 0; z < nCN - 1; ++z)
   397           nodes_ring[z].Add (nodes_net0[z][0].Get (0));
   398           nodes_ring[z].Add (nodes_net0[z + 1][0].Get (0));
   400       nodes_ring[nCN - 1].Add (nodes_net0[nCN - 1][0].Get (0));
   401       nodes_ring[nCN - 1].Add (nodes_net0[0][0].Get (0));
   402       vectorOfNetDeviceContainer ndc_ring(nCN);
   403       for (uint32_t z = 0; z < nCN; ++z)
   405           ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
   407           oss << 
"254.1." << z + 1 << 
".0";
   408           address.SetBase (oss.str ().c_str (), 
"255.255.255.0");
   409           ifs = 
address.Assign (ndc_ring[z]);
   414   RANK0COUT (
"Creating UDP Traffic Flows:" << std::endl);
   418                       StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
   420                       StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
   425       if (systemCount == 1)
   439           RANK0COUT (
"Remote Address is " << ifs1[0][2].GetAddress (0) << std::endl);
   440           client.SetAttribute (
"Remote", remoteAddress);
   443           clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
   446       else if (systemId == 1)
   452             sinkHelper.Install (nodes_net1[1][0].Get (0));
   459       else if (systemId == 0)
   465           RANK0COUT (
"Remote Address is " << ifs1[1][0].GetAddress (0) << std::endl);
   466           client.SetAttribute (
"Remote", remoteAddress);
   469           clientApp.
Add (client.Install (nodes_net2LAN[0][0][0].Get (0)));
   478       for (uint32_t z = 0; z < nCN; ++z)
   486           RANK0COUT (
"  Campus Network " << z << 
" Flows [ Net2 ");
   487           for (
int i = 0; i < 7; ++i)
   489               for (uint32_t j = 0; j < nLANClients; ++j)
   492                   if (systemCount == 1)
   495                         (
"ns3::UdpSocketFactory",
   499                         sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
   507                   else if (systemId == z % systemCount)
   510                         (
"ns3::UdpSocketFactory",
   514                         sinkHelper.Install (nodes_net2LAN[z][i][j].Get (0));
   523                   if (systemCount == 1)
   525                       r1 = 2 + (int)(4 * urng->
GetValue ());
   532                       client.SetAttribute (
"Remote", remoteAddress);
   534                       clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
   537                   else if (systemId == 
x % systemCount)
   539                       r1 = 2 + (int)(4 * urng->
GetValue ());
   546                       client.SetAttribute (
"Remote", remoteAddress);
   548                       clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
   555           for (
int i = 0; i < 5; ++i)
   557               for (uint32_t j = 0; j < nLANClients; ++j)
   560                   if (systemCount == 1)
   563                         (
"ns3::UdpSocketFactory",
   567                         sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
   574                   else if (systemId == z % systemCount)
   577                         (
"ns3::UdpSocketFactory",
   581                         sinkHelper.Install (nodes_net3LAN[z][i][j].Get (0));
   590                   if (systemCount == 1)
   592                       r1 = 2 + (int)(4 * urng->
GetValue ());
   599                       client.SetAttribute (
"Remote", remoteAddress);
   601                       clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
   604                   else if (systemId == 
x % systemCount)
   606                       r1 = 2 + (int)(4 * urng->
GetValue ());
   613                       client.SetAttribute (
"Remote", remoteAddress);
   615                       clientApp.
Add (client.Install (nodes_net1[
x][r1].Get (0)));
   629       RANK0COUT (
"Using Nix-vectors..." << std::endl);
   634       RANK0COUT (
"Populating Routing tables..." << std::endl);
   641       RANK0COUT (
"Routing tables population took "   645   RANK0COUT (
"Running simulator..." << std::endl);
   650   RANK0COUT (
"Simulator finished." << std::endl);
   655       const int numberNodesSending = nCN * ( nLANClients * (7 + 5)); 
   656       const int expectedPacketCount = numberNodesSending * nPackets;
 holds a vector of ns3::Application pointers. 
Simulation virtual time values and global simulation resolution. 
static Ipv4Address GetAny(void)
static uint32_t GetNNodes(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 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. 
int64_t GetElapsedReal(void) const
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 
Measure elapsed wall clock time in milliseconds. 
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. 
void Start(void)
Start a measure. 
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 RANK0COUTAPPEND(x)
  AttributeValue implementation for Address. 
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. 
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)
A helper class to make life easier while doing simple IPv4 address assignment in scripts. 
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback. 
int64_t End(void)
Stop measuring the time since Start() was called. 
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...
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index. 
#define RANK0COUT(x)
Write to std::cout only from rank 0.