31#include "ns3/core-module.h" 
   32#include "ns3/internet-module.h" 
   33#include "ns3/mpi-interface.h" 
   34#include "ns3/network-module.h" 
   35#include "ns3/nix-vector-helper.h" 
   36#include "ns3/on-off-helper.h" 
   37#include "ns3/packet-sink-helper.h" 
   38#include "ns3/point-to-point-helper.h" 
   48main(
int argc, 
char* argv[])
 
   50    typedef std::vector<NodeContainer> vectorOfNodeContainer;
 
   51    typedef std::vector<vectorOfNodeContainer> vectorOfVectorOfNodeContainer;
 
   52    typedef std::vector<vectorOfVectorOfNodeContainer> vectorOfVectorOfVectorOfNodeContainer;
 
   54    typedef std::vector<Ipv4InterfaceContainer> vectorOfIpv4InterfaceContainer;
 
   55    typedef std::vector<vectorOfIpv4InterfaceContainer> vectorOfVectorOfIpv4InterfaceContainer;
 
   56    typedef std::vector<vectorOfVectorOfIpv4InterfaceContainer>
 
   57        vectorOfVectorOfVectorOfIpv4InterfaceContainer;
 
   59    typedef std::vector<NetDeviceContainer> vectorOfNetDeviceContainer;
 
   60    typedef std::vector<vectorOfNetDeviceContainer> vectorOfVectorOfNetDeviceContainer;
 
   78    cmd.AddValue(
"campuses", 
"Number of campus networks", nCN);
 
   79    cmd.AddValue(
"clients", 
"Number of client nodes per LAN", nLANClients);
 
   80    cmd.AddValue(
"packets", 
"Number of packets each on/off app should send", nPackets);
 
   81    cmd.AddValue(
"nix", 
"Toggle the use of nix-vector or global routing", nix);
 
   82    cmd.AddValue(
"stop", 
"Simulation run time", stop);
 
   83    cmd.AddValue(
"single", 
"Use single on/off app per campus network", single);
 
   84    cmd.AddValue(
"verbose", 
"Show extra timing information", 
verbose);
 
   85    cmd.AddValue(
"test", 
"Enable regression test output", testing);
 
   87    cmd.Parse(argc, argv);
 
   97    RANK0COUT(
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl);
 
  103        RANK0COUT(
"Number of total CNs (" << nCN << 
") lower than minimum of 2" << std::endl);
 
  106    if (systemCount > nCN)
 
  108        RANK0COUT(
"Number of total CNs (" << nCN << 
") should be >= systemCount (" << systemCount
 
  109                                          << 
")." << std::endl);
 
  113    RANK0COUT(
"Number of CNs: " << nCN << 
", LAN nodes: " << nLANClients << std::endl);
 
  115    vectorOfNodeContainer nodes_netLR(nCN);
 
  116    vectorOfVectorOfNodeContainer nodes_net0(nCN, vectorOfNodeContainer(3));
 
  117    vectorOfVectorOfNodeContainer nodes_net1(nCN, vectorOfNodeContainer(6));
 
  118    vectorOfVectorOfNodeContainer nodes_net2(nCN, vectorOfNodeContainer(14));
 
  119    vectorOfVectorOfNodeContainer nodes_net3(nCN, vectorOfNodeContainer(9));
 
  121    vectorOfVectorOfVectorOfNodeContainer nodes_net2LAN(
 
  123        vectorOfVectorOfNodeContainer(7, vectorOfNodeContainer(nLANClients)));
 
  124    vectorOfVectorOfVectorOfNodeContainer nodes_net3LAN(
 
  126        vectorOfVectorOfNodeContainer(5, vectorOfNodeContainer(nLANClients)));
 
  135    vectorOfVectorOfIpv4InterfaceContainer ifs0(nCN, vectorOfIpv4InterfaceContainer(3));
 
  136    vectorOfVectorOfIpv4InterfaceContainer ifs1(nCN, vectorOfIpv4InterfaceContainer(6));
 
  137    vectorOfVectorOfIpv4InterfaceContainer ifs2(nCN, vectorOfIpv4InterfaceContainer(14));
 
  138    vectorOfVectorOfIpv4InterfaceContainer ifs3(nCN, vectorOfIpv4InterfaceContainer(9));
 
  139    vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs2LAN(
 
  141        vectorOfVectorOfIpv4InterfaceContainer(7, vectorOfIpv4InterfaceContainer(nLANClients)));
 
  142    vectorOfVectorOfVectorOfIpv4InterfaceContainer ifs3LAN(
 
  144        vectorOfVectorOfIpv4InterfaceContainer(5, vectorOfIpv4InterfaceContainer(nLANClients)));
 
  147    std::ostringstream oss;
 
  158        stack.SetRoutingHelper(nixRouting); 
 
  164        RANK0COUT(
"Creating Campus Network " << z << 
":" << std::endl);
 
  167        for (
int i = 0; i < 3; ++i)
 
  170            nodes_net0[z][i].Add(node);
 
  171            stack.Install(nodes_net0[z][i]);
 
  173        nodes_net0[z][0].Add(nodes_net0[z][1].Get(0));
 
  174        nodes_net0[z][1].Add(nodes_net0[z][2].Get(0));
 
  175        nodes_net0[z][2].Add(nodes_net0[z][0].Get(0));
 
  177        for (
int i = 0; i < 3; ++i)
 
  179            ndc0[i] = p2p_1gb5ms.
Install(nodes_net0[z][i]);
 
  183        for (
int i = 0; i < 6; ++i)
 
  186            nodes_net1[z][i].Add(node);
 
  187            stack.Install(nodes_net1[z][i]);
 
  189        nodes_net1[z][0].Add(nodes_net1[z][1].Get(0));
 
  190        nodes_net1[z][2].Add(nodes_net1[z][0].Get(0));
 
  191        nodes_net1[z][3].Add(nodes_net1[z][0].Get(0));
 
  192        nodes_net1[z][4].Add(nodes_net1[z][1].Get(0));
 
  193        nodes_net1[z][5].Add(nodes_net1[z][1].Get(0));
 
  195        for (
int i = 0; i < 6; ++i)
 
  201            ndc1[i] = p2p_1gb5ms.
Install(nodes_net1[z][i]);
 
  205        net0_1.
Add(nodes_net0[z][2].Get(0));
 
  206        net0_1.
Add(nodes_net1[z][0].Get(0));
 
  208        ndc0_1 = p2p_1gb5ms.
Install(net0_1);
 
  210        oss << 10 + z << 
".1.252.0";
 
  211        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  215        for (
int i = 0; i < 14; ++i)
 
  218            nodes_net2[z][i].Add(node);
 
  219            stack.Install(nodes_net2[z][i]);
 
  221        nodes_net2[z][0].Add(nodes_net2[z][1].Get(0));
 
  222        nodes_net2[z][2].Add(nodes_net2[z][0].Get(0));
 
  223        nodes_net2[z][1].Add(nodes_net2[z][3].Get(0));
 
  224        nodes_net2[z][3].Add(nodes_net2[z][2].Get(0));
 
  225        nodes_net2[z][4].Add(nodes_net2[z][2].Get(0));
 
  226        nodes_net2[z][5].Add(nodes_net2[z][3].Get(0));
 
  227        nodes_net2[z][6].Add(nodes_net2[z][5].Get(0));
 
  228        nodes_net2[z][7].Add(nodes_net2[z][2].Get(0));
 
  229        nodes_net2[z][8].Add(nodes_net2[z][3].Get(0));
 
  230        nodes_net2[z][9].Add(nodes_net2[z][4].Get(0));
 
  231        nodes_net2[z][10].Add(nodes_net2[z][5].Get(0));
 
  232        nodes_net2[z][11].Add(nodes_net2[z][6].Get(0));
 
  233        nodes_net2[z][12].Add(nodes_net2[z][6].Get(0));
 
  234        nodes_net2[z][13].Add(nodes_net2[z][6].Get(0));
 
  236        for (
int i = 0; i < 14; ++i)
 
  238            ndc2[i] = p2p_1gb5ms.
Install(nodes_net2[z][i]);
 
  240        vectorOfVectorOfNetDeviceContainer ndc2LAN(7, vectorOfNetDeviceContainer(nLANClients));
 
  241        for (
int i = 0; i < 7; ++i)
 
  244            oss << 10 + z << 
".4." << 15 + i << 
".0";
 
  245            address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  246            for (
uint32_t j = 0; j < nLANClients; ++j)
 
  249                nodes_net2LAN[z][i][j].Add(node);
 
  250                stack.Install(nodes_net2LAN[z][i][j]);
 
  251                nodes_net2LAN[z][i][j].Add(nodes_net2[z][i + 7].Get(0));
 
  252                ndc2LAN[i][j] = p2p_100mb1ms.
Install(nodes_net2LAN[z][i][j]);
 
  253                ifs2LAN[z][i][j] = 
address.Assign(ndc2LAN[i][j]);
 
  258        for (
int i = 0; i < 9; ++i)
 
  261            nodes_net3[z][i].Add(node);
 
  262            stack.Install(nodes_net3[z][i]);
 
  264        nodes_net3[z][0].Add(nodes_net3[z][1].Get(0));
 
  265        nodes_net3[z][1].Add(nodes_net3[z][2].Get(0));
 
  266        nodes_net3[z][2].Add(nodes_net3[z][3].Get(0));
 
  267        nodes_net3[z][3].Add(nodes_net3[z][1].Get(0));
 
  268        nodes_net3[z][4].Add(nodes_net3[z][0].Get(0));
 
  269        nodes_net3[z][5].Add(nodes_net3[z][0].Get(0));
 
  270        nodes_net3[z][6].Add(nodes_net3[z][2].Get(0));
 
  271        nodes_net3[z][7].Add(nodes_net3[z][3].Get(0));
 
  272        nodes_net3[z][8].Add(nodes_net3[z][3].Get(0));
 
  274        for (
int i = 0; i < 9; ++i)
 
  276            ndc3[i] = p2p_1gb5ms.
Install(nodes_net3[z][i]);
 
  278        vectorOfVectorOfNetDeviceContainer ndc3LAN(5, vectorOfNetDeviceContainer(nLANClients));
 
  279        for (
int i = 0; i < 5; ++i)
 
  282            oss << 10 + z << 
".5." << 10 + i << 
".0";
 
  283            address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  284            for (
uint32_t j = 0; j < nLANClients; ++j)
 
  287                nodes_net3LAN[z][i][j].Add(node);
 
  288                stack.Install(nodes_net3LAN[z][i][j]);
 
  289                nodes_net3LAN[z][i][j].Add(nodes_net3[z][i + 4].Get(0));
 
  290                ndc3LAN[i][j] = p2p_100mb1ms.
Install(nodes_net3LAN[z][i][j]);
 
  291                ifs3LAN[z][i][j] = 
address.Assign(ndc3LAN[i][j]);
 
  294        RANK0COUT(
"  Connecting Subnets..." << std::endl);
 
  298        nodes_netLR[z].Add(node1);
 
  299        nodes_netLR[z].Add(node2);
 
  300        stack.Install(nodes_netLR[z]);
 
  302        ndcLR = p2p_1gb5ms.
Install(nodes_netLR[z]);
 
  310        net0_4.
Add(nodes_netLR[z].Get(0));
 
  311        net0_4.
Add(nodes_net0[z][0].Get(0));
 
  312        net0_5.
Add(nodes_netLR[z].Get(1));
 
  313        net0_5.
Add(nodes_net0[z][1].Get(0));
 
  314        net2_4a.
Add(nodes_netLR[z].Get(0));
 
  315        net2_4a.
Add(nodes_net2[z][0].Get(0));
 
  316        net2_4b.
Add(nodes_netLR[z].Get(1));
 
  317        net2_4b.
Add(nodes_net2[z][1].Get(0));
 
  318        net3_5a.
Add(nodes_netLR[z].Get(1));
 
  319        net3_5a.
Add(nodes_net3[z][0].Get(0));
 
  320        net3_5b.
Add(nodes_netLR[z].Get(1));
 
  321        net3_5b.
Add(nodes_net3[z][1].Get(0));
 
  328        ndc0_4 = p2p_1gb5ms.
Install(net0_4);
 
  330        oss << 10 + z << 
".1.253.0";
 
  331        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  333        ndc0_5 = p2p_1gb5ms.
Install(net0_5);
 
  335        oss << 10 + z << 
".1.254.0";
 
  336        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  338        ndc2_4a = p2p_1gb5ms.
Install(net2_4a);
 
  340        oss << 10 + z << 
".4.253.0";
 
  341        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  343        ndc2_4b = p2p_1gb5ms.
Install(net2_4b);
 
  345        oss << 10 + z << 
".4.254.0";
 
  346        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  348        ndc3_5a = p2p_1gb5ms.
Install(net3_5a);
 
  350        oss << 10 + z << 
".5.253.0";
 
  351        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  353        ndc3_5b = p2p_1gb5ms.
Install(net3_5b);
 
  355        oss << 10 + z << 
".5.254.0";
 
  356        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  359        RANK0COUT(
"  Assigning IP addresses..." << std::endl);
 
  360        for (
int i = 0; i < 3; ++i)
 
  363            oss << 10 + z << 
".1." << 1 + i << 
".0";
 
  364            address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  365            ifs0[z][i] = 
address.Assign(ndc0[i]);
 
  367        for (
int i = 0; i < 6; ++i)
 
  374            oss << 10 + z << 
".2." << 1 + i << 
".0";
 
  375            address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  376            ifs1[z][i] = 
address.Assign(ndc1[i]);
 
  379        oss << 10 + z << 
".3.1.0";
 
  380        address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  382        for (
int i = 0; i < 14; ++i)
 
  385            oss << 10 + z << 
".4." << 1 + i << 
".0";
 
  386            address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  387            ifs2[z][i] = 
address.Assign(ndc2[i]);
 
  389        for (
int i = 0; i < 9; ++i)
 
  392            oss << 10 + z << 
".5." << 1 + i << 
".0";
 
  393            address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  394            ifs3[z][i] = 
address.Assign(ndc3[i]);
 
  400        RANK0COUT(
"Forming Ring Topology..." << std::endl);
 
  401        vectorOfNodeContainer nodes_ring(nCN);
 
  402        for (
uint32_t z = 0; z < nCN - 1; ++z)
 
  404            nodes_ring[z].Add(nodes_net0[z][0].Get(0));
 
  405            nodes_ring[z].Add(nodes_net0[z + 1][0].Get(0));
 
  407        nodes_ring[nCN - 1].Add(nodes_net0[nCN - 1][0].Get(0));
 
  408        nodes_ring[nCN - 1].Add(nodes_net0[0][0].Get(0));
 
  409        vectorOfNetDeviceContainer ndc_ring(nCN);
 
  412            ndc_ring[z] = p2p_2gb200ms.
Install(nodes_ring[z]);
 
  414            oss << 
"254.1." << z + 1 << 
".0";
 
  415            address.SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  416            ifs = 
address.Assign(ndc_ring[z]);
 
  421    RANK0COUT(
"Creating UDP Traffic Flows:" << std::endl);
 
  424                       StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
 
  426                       StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
 
  430        if (systemCount == 1)
 
  438                sinkApp.
Get(0)->TraceConnectWithoutContext(
"RxWithAddresses",
 
  444            RANK0COUT(
"Remote Address is " << ifs1[0][2].GetAddress(0) << std::endl);
 
  445            client.SetAttribute(
"Remote", remoteAddress);
 
  448            clientApp.
Add(
client.Install(nodes_net2LAN[0][0][0].Get(0)));
 
  451        else if (systemId == 1)
 
  459                sinkApp.
Get(0)->TraceConnectWithoutContext(
"RxWithAddresses",
 
  463        else if (systemId == 0)
 
  468            RANK0COUT(
"Remote Address is " << ifs1[1][0].GetAddress(0) << std::endl);
 
  469            client.SetAttribute(
"Remote", remoteAddress);
 
  472            clientApp.
Add(
client.Install(nodes_net2LAN[0][0][0].Get(0)));
 
  489            RANK0COUT(
"  Campus Network " << z << 
" Flows [ Net2 ");
 
  490            for (
int i = 0; i < 7; ++i)
 
  492                for (
uint32_t j = 0; j < nLANClients; ++j)
 
  495                    if (systemCount == 1)
 
  501                            sinkHelper.Install(nodes_net2LAN[z][i][j].Get(0));
 
  506                            sinkApp.
Get(0)->TraceConnectWithoutContext(
 
  511                    else if (systemId == z % systemCount)
 
  517                            sinkHelper.Install(nodes_net2LAN[z][i][j].Get(0));
 
  522                            sinkApp.
Get(0)->TraceConnectWithoutContext(
 
  528                    if (systemCount == 1)
 
  530                        r1 = 2 + (int)(4 * urng->GetValue());
 
  531                        r2 = 10 * urng->GetValue();
 
  537                        client.SetAttribute(
"Remote", remoteAddress);
 
  539                        clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
 
  542                    else if (systemId == 
x % systemCount)
 
  544                        r1 = 2 + (int)(4 * urng->GetValue());
 
  545                        r2 = 10 * urng->GetValue();
 
  551                        client.SetAttribute(
"Remote", remoteAddress);
 
  553                        clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
 
  560            for (
int i = 0; i < 5; ++i)
 
  562                for (
uint32_t j = 0; j < nLANClients; ++j)
 
  565                    if (systemCount == 1)
 
  571                            sinkHelper.Install(nodes_net3LAN[z][i][j].Get(0));
 
  575                            sinkApp.
Get(0)->TraceConnectWithoutContext(
 
  580                    else if (systemId == z % systemCount)
 
  586                            sinkHelper.Install(nodes_net3LAN[z][i][j].Get(0));
 
  591                            sinkApp.
Get(0)->TraceConnectWithoutContext(
 
  597                    if (systemCount == 1)
 
  599                        r1 = 2 + (int)(4 * urng->GetValue());
 
  600                        r2 = 10 * urng->GetValue();
 
  606                        client.SetAttribute(
"Remote", remoteAddress);
 
  608                        clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
 
  611                    else if (systemId == 
x % systemCount)
 
  613                        r1 = 2 + (int)(4 * urng->GetValue());
 
  614                        r2 = 10 * urng->GetValue();
 
  620                        client.SetAttribute(
"Remote", remoteAddress);
 
  622                        clientApp.
Add(
client.Install(nodes_net1[
x][r1].Get(0)));
 
  637        RANK0COUT(
"Using Nix-vectors..." << std::endl);
 
  642        RANK0COUT(
"Populating Routing tables..." << std::endl);
 
  653    RANK0COUT(
"Running simulator..." << std::endl);
 
  658    RANK0COUT(
"Simulator finished." << std::endl);
 
  663        const int numberNodesSending =
 
  664            nCN * (nLANClients * (7 + 5)); 
 
  665        const int expectedPacketCount = numberNodesSending * nPackets;
 
  680                  << 
"Total elapsed time:  " << t0.
GetElapsedReal() << 
"ms" << std::endl);
 
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
a polymophic address class
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
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...
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static uint32_t GetSystemId()
Get the id number of this rank.
static uint32_t GetSize()
Get the number of ranks used by ns-3.
static void Disable()
Clean up the ns-3 parallel communications interface.
static void Enable(int *pargc, char ***pargv)
Setup the parallel communication interface.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
static uint32_t GetNNodes()
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.
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)
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
static void SinkTrace(const ns3::Ptr< const ns3::Packet > packet, const ns3::Address &srcAddress, const ns3::Address &destAddress)
PacketSink receive trace callback.
static void Verify(unsigned long expectedCount)
Verify the sink trace count observed matches the expected count.
static void Init()
PacketSink Init.
Hold variables of type string.
Measure elapsed wall clock time in milliseconds.
int64_t End()
Stop measuring the time since Start() was called.
int64_t GetElapsedReal() const
void Start()
Start a measure.
Simulation virtual time values and global simulation resolution.
Hold an unsigned integer type.
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.
NixVectorHelper< Ipv4RoutingHelper > Ipv4NixVectorHelper
Create the typedef Ipv4NixVectorHelper with T as Ipv4RoutingHelper.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
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...