29#include "ns3/applications-module.h" 
   30#include "ns3/core-module.h" 
   31#include "ns3/internet-module.h" 
   32#include "ns3/network-module.h" 
   33#include "ns3/nix-vector-helper.h" 
   34#include "ns3/onoff-application.h" 
   35#include "ns3/packet-sink.h" 
   36#include "ns3/point-to-point-module.h" 
   37#include "ns3/simulator.h" 
   69        for (
size_t i = 0; i < 
m_xMax; i++)
 
 
   77        for (
size_t i = 0; i < 
m_xMax; i++)
 
 
 
  114    Array3D(
const size_t x, 
const size_t y, 
const size_t z)
 
  118        for (
size_t i = 0; i < 
m_xMax; i++)
 
 
  126        for (
size_t i = 0; i < 
m_xMax; i++)
 
 
 
  151main(
int argc, 
char* argv[])
 
  153    auto t0 = std::chrono::steady_clock::now();
 
  155    std::cout << 
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
 
  159    int nLANClients = 42;
 
  161    bool useIpv6 = 
false;
 
  164    cmd.AddValue(
"useIPv6", 
"Use IPv6 instead of IPv4", useIpv6);
 
  165    cmd.AddValue(
"CN", 
"Number of total CNs [2]", nCN);
 
  166    cmd.AddValue(
"LAN", 
"Number of nodes per LAN [42]", nLANClients);
 
  167    cmd.AddValue(
"NIX", 
"Toggle nix-vector routing", nix);
 
  168    cmd.Parse(argc, argv);
 
  172        std::cout << 
"This script can work in IPv6 only by using NIX" << std::endl;
 
  177        std::cout << 
"Number of total CNs (" << nCN << 
") lower than minimum of 2" << std::endl;
 
  181    std::cout << 
"Number of CNs: " << nCN << 
", LAN nodes: " << nLANClients << std::endl;
 
  200    std::ostringstream oss;
 
  214            stack.SetRoutingHelper(nixRouting); 
 
  219            stack.SetRoutingHelper(nixRouting); 
 
  224    for (
int z = 0; z < nCN; ++z)
 
  226        std::cout << 
"Creating Campus Network " << z << 
":" << std::endl;
 
  228        std::cout << 
"  SubNet [ 0";
 
  229        for (
int i = 0; i < 3; ++i)
 
  231            nodes_net0[z][i].Create(1);
 
  232            stack.Install(nodes_net0[z][i]);
 
  234        nodes_net0[z][0].Add(nodes_net0[z][1].Get(0));
 
  235        nodes_net0[z][1].Add(nodes_net0[z][2].Get(0));
 
  236        nodes_net0[z][2].Add(nodes_net0[z][0].Get(0));
 
  238        for (
int i = 0; i < 3; ++i)
 
  240            ndc0[i] = p2p_1gb5ms.
Install(nodes_net0[z][i]);
 
  244        for (
int i = 0; i < 6; ++i)
 
  246            nodes_net1[z][i].Create(1);
 
  247            stack.Install(nodes_net1[z][i]);
 
  249        nodes_net1[z][0].
Add(nodes_net1[z][1].Get(0));
 
  250        nodes_net1[z][2].Add(nodes_net1[z][0].Get(0));
 
  251        nodes_net1[z][3].Add(nodes_net1[z][0].Get(0));
 
  252        nodes_net1[z][4].Add(nodes_net1[z][1].Get(0));
 
  253        nodes_net1[z][5].Add(nodes_net1[z][1].Get(0));
 
  255        for (
int i = 0; i < 6; ++i)
 
  261            ndc1[i] = p2p_1gb5ms.
Install(nodes_net1[z][i]);
 
  265        net0_1.
Add(nodes_net0[z][2].Get(0));
 
  266        net0_1.
Add(nodes_net1[z][0].Get(0));
 
  268        ndc0_1 = p2p_1gb5ms.
Install(net0_1);
 
  272            oss << 10 + z << 
".1.252.0";
 
  273            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  274            addressHelperv4.
Assign(ndc0_1);
 
  278            oss << 2001 + z << 
":1:252::";
 
  280            addressHelperv6.
Assign(ndc0_1);
 
  284        for (
int i = 0; i < 14; ++i)
 
  286            nodes_net2[z][i].Create(1);
 
  287            stack.Install(nodes_net2[z][i]);
 
  289        nodes_net2[z][0].Add(nodes_net2[z][1].Get(0));
 
  290        nodes_net2[z][2].Add(nodes_net2[z][0].Get(0));
 
  291        nodes_net2[z][1].Add(nodes_net2[z][3].Get(0));
 
  292        nodes_net2[z][3].Add(nodes_net2[z][2].Get(0));
 
  293        nodes_net2[z][4].Add(nodes_net2[z][2].Get(0));
 
  294        nodes_net2[z][5].Add(nodes_net2[z][3].Get(0));
 
  295        nodes_net2[z][6].Add(nodes_net2[z][5].Get(0));
 
  296        nodes_net2[z][7].Add(nodes_net2[z][2].Get(0));
 
  297        nodes_net2[z][8].Add(nodes_net2[z][3].Get(0));
 
  298        nodes_net2[z][9].Add(nodes_net2[z][4].Get(0));
 
  299        nodes_net2[z][10].Add(nodes_net2[z][5].Get(0));
 
  300        nodes_net2[z][11].Add(nodes_net2[z][6].Get(0));
 
  301        nodes_net2[z][12].Add(nodes_net2[z][6].Get(0));
 
  302        nodes_net2[z][13].Add(nodes_net2[z][6].Get(0));
 
  304        for (
int i = 0; i < 14; ++i)
 
  306            ndc2[i] = p2p_1gb5ms.
Install(nodes_net2[z][i]);
 
  309        for (
int i = 0; i < 7; ++i)
 
  314                oss << 10 + z << 
".4." << 15 + i << 
".0";
 
  315                addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  319                oss << 2001 + z << 
":4:" << 15 + i << 
"::";
 
  322            for (
int j = 0; j < nLANClients; ++j)
 
  324                nodes_net2LAN[z][i][j].Create(1);
 
  325                stack.Install(nodes_net2LAN[z][i][j]);
 
  326                nodes_net2LAN[z][i][j].Add(nodes_net2[z][i + 7].Get(0));
 
  327                ndc2LAN[i][j] = p2p_100mb1ms.
Install(nodes_net2LAN[z][i][j]);
 
  330                    ifs2LanRemoteAddress[z][i][j] =
 
  336                    ifs2LanRemoteAddress[z][i][j] =
 
  343        std::cout << 
" 3 ]" << std::endl;
 
  344        for (
int i = 0; i < 9; ++i)
 
  346            nodes_net3[z][i].Create(1);
 
  347            stack.Install(nodes_net3[z][i]);
 
  349        nodes_net3[z][0].Add(nodes_net3[z][1].Get(0));
 
  350        nodes_net3[z][1].Add(nodes_net3[z][2].Get(0));
 
  351        nodes_net3[z][2].Add(nodes_net3[z][3].Get(0));
 
  352        nodes_net3[z][3].Add(nodes_net3[z][1].Get(0));
 
  353        nodes_net3[z][4].Add(nodes_net3[z][0].Get(0));
 
  354        nodes_net3[z][5].Add(nodes_net3[z][0].Get(0));
 
  355        nodes_net3[z][6].Add(nodes_net3[z][2].Get(0));
 
  356        nodes_net3[z][7].Add(nodes_net3[z][3].Get(0));
 
  357        nodes_net3[z][8].Add(nodes_net3[z][3].Get(0));
 
  359        for (
int i = 0; i < 9; ++i)
 
  361            ndc3[i] = p2p_1gb5ms.
Install(nodes_net3[z][i]);
 
  364        for (
int i = 0; i < 5; ++i)
 
  369                oss << 10 + z << 
".5." << 10 + i << 
".0";
 
  370                addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  374                oss << 2001 + z << 
":5:" << 10 + i << 
"::";
 
  377            for (
int j = 0; j < nLANClients; ++j)
 
  379                nodes_net3LAN[z][i][j].Create(1);
 
  380                stack.Install(nodes_net3LAN[z][i][j]);
 
  381                nodes_net3LAN[z][i][j].Add(nodes_net3[z][i + 4].Get(0));
 
  382                ndc3LAN[i][j] = p2p_100mb1ms.
Install(nodes_net3LAN[z][i][j]);
 
  385                    ifs3LanRemoteAddress[z][i][j] =
 
  391                    ifs3LanRemoteAddress[z][i][j] =
 
  397        std::cout << 
"  Connecting Subnets..." << std::endl;
 
  399        nodes_netLR[z].Create(2);
 
  400        stack.Install(nodes_netLR[z]);
 
  402        ndcLR = p2p_1gb5ms.
Install(nodes_netLR[z]);
 
  410        net0_4.
Add(nodes_netLR[z].Get(0));
 
  411        net0_4.
Add(nodes_net0[z][0].Get(0));
 
  412        net0_5.
Add(nodes_netLR[z].Get(1));
 
  413        net0_5.
Add(nodes_net0[z][1].Get(0));
 
  414        net2_4a.
Add(nodes_netLR[z].Get(0));
 
  415        net2_4a.
Add(nodes_net2[z][0].Get(0));
 
  416        net2_4b.
Add(nodes_netLR[z].Get(1));
 
  417        net2_4b.
Add(nodes_net2[z][1].Get(0));
 
  418        net3_5a.
Add(nodes_netLR[z].Get(1));
 
  419        net3_5a.
Add(nodes_net3[z][0].Get(0));
 
  420        net3_5b.
Add(nodes_netLR[z].Get(1));
 
  421        net3_5b.
Add(nodes_net3[z][1].Get(0));
 
  428        ndc0_4 = p2p_1gb5ms.
Install(net0_4);
 
  429        ndc0_5 = p2p_1gb5ms.
Install(net0_5);
 
  430        ndc2_4a = p2p_1gb5ms.
Install(net2_4a);
 
  431        ndc2_4b = p2p_1gb5ms.
Install(net2_4b);
 
  432        ndc3_5a = p2p_1gb5ms.
Install(net3_5a);
 
  433        ndc3_5b = p2p_1gb5ms.
Install(net3_5b);
 
  441            oss << 10 + z << 
".1.253.0";
 
  442            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  443            addressHelperv4.
Assign(ndc0_4);
 
  446            oss << 10 + z << 
".1.254.0";
 
  447            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  448            addressHelperv4.
Assign(ndc0_5);
 
  451            oss << 10 + z << 
".4.253.0";
 
  452            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  453            addressHelperv4.
Assign(ndc2_4a);
 
  456            oss << 10 + z << 
".4.254.0";
 
  457            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  458            addressHelperv4.
Assign(ndc2_4b);
 
  461            oss << 10 + z << 
".5.253.0";
 
  462            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  463            addressHelperv4.
Assign(ndc3_5a);
 
  466            oss << 10 + z << 
".5.254.0";
 
  467            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  468            addressHelperv4.
Assign(ndc3_5b);
 
  474            oss << 2001 + z << 
":1:253::";
 
  476            addressHelperv6.
Assign(ndc0_4);
 
  479            oss << 2001 + z << 
":1:254::";
 
  481            addressHelperv6.
Assign(ndc0_5);
 
  484            oss << 2001 + z << 
":4:253::";
 
  486            addressHelperv6.
Assign(ndc2_4a);
 
  489            oss << 2001 + z << 
":4:254::";
 
  491            addressHelperv6.
Assign(ndc2_4b);
 
  494            oss << 2001 + z << 
":5:253::";
 
  496            addressHelperv6.
Assign(ndc3_5a);
 
  499            oss << 2001 + z << 
":5:254::";
 
  501            addressHelperv6.
Assign(ndc3_5b);
 
  504        std::cout << 
"  Assigning IP addresses..." << std::endl;
 
  505        for (
int i = 0; i < 3; ++i)
 
  510                oss << 10 + z << 
".1." << 1 + i << 
".0";
 
  511                addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  512                addressHelperv4.
Assign(ndc0[i]);
 
  516                oss << 2001 + z << 
":1:" << 1 + i << 
"::";
 
  518                addressHelperv6.
Assign(ndc0[i]);
 
  521        for (
int i = 0; i < 6; ++i)
 
  530                oss << 10 + z << 
".2." << 1 + i << 
".0";
 
  531                addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  532                addressHelperv4.
Assign(ndc1[i]);
 
  536                oss << 2001 + z << 
":2:" << 1 + i << 
"::";
 
  538                addressHelperv6.
Assign(ndc1[i]);
 
  544            oss << 10 + z << 
".3.1.0";
 
  545            addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  546            addressHelperv4.
Assign(ndcLR);
 
  550            oss << 2001 + z << 
":3:1::";
 
  552            addressHelperv6.
Assign(ndcLR);
 
  554        for (
int i = 0; i < 14; ++i)
 
  559                oss << 10 + z << 
".4." << 1 + i << 
".0";
 
  560                addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  561                addressHelperv4.
Assign(ndc2[i]);
 
  565                oss << 2001 + z << 
":4:" << 1 + i << 
"::";
 
  567                addressHelperv6.
Assign(ndc2[i]);
 
  570        for (
int i = 0; i < 9; ++i)
 
  575                oss << 10 + z << 
".5." << 1 + i << 
".0";
 
  576                addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  577                addressHelperv4.
Assign(ndc3[i]);
 
  581                oss << 2001 + z << 
":5:" << 1 + i << 
"::";
 
  583                addressHelperv6.
Assign(ndc3[i]);
 
  590        std::cout << 
"Forming Ring Topology..." << std::endl;
 
  592        for (
int z = 0; z < nCN - 1; ++z)
 
  594            nodes_ring[z].Add(nodes_net0[z][0].Get(0));
 
  595            nodes_ring[z].Add(nodes_net0[z + 1][0].Get(0));
 
  597        nodes_ring[nCN - 1].
Add(nodes_net0[nCN - 1][0].Get(0));
 
  598        nodes_ring[nCN - 1].Add(nodes_net0[0][0].Get(0));
 
  600        for (
int z = 0; z < nCN; ++z)
 
  602            ndc_ring[z] = p2p_2gb200ms.
Install(nodes_ring[z]);
 
  606                oss << 
"254.1." << z + 1 << 
".0";
 
  607                addressHelperv4.
SetBase(oss.str().c_str(), 
"255.255.255.0");
 
  608                addressHelperv4.
Assign(ndc_ring[z]);
 
  612                oss << 
"254:1:" << z + 1 << 
"::";
 
  614                addressHelperv6.
Assign(ndc_ring[z]);
 
  622    std::cout << 
"Creating TCP Traffic Flows:" << std::endl;
 
  625                       StringValue(
"ns3::ConstantRandomVariable[Constant=1.0]"));
 
  627                       StringValue(
"ns3::ConstantRandomVariable[Constant=0.0]"));
 
  644    for (
int z = 0; z < nCN; ++z)
 
  652        std::cout << 
"  Campus Network " << z << 
" Flows [ Net2 ";
 
  653        for (
int i = 0; i < 7; ++i)
 
  655            for (
int j = 0; j < nLANClients; ++j)
 
  662                r1 = 2 + (int)(4 * urng->GetValue());
 
  663                r2 = 10 * urng->GetValue();
 
  666                client.SetAttribute(
"Remote", remoteAddress);
 
  668                clientApp.
Add(
client.Install(nodes_net1[x][r1].Get(0)));
 
  673        std::cout << 
"Net3 ]" << std::endl;
 
  674        for (
int i = 0; i < 5; ++i)
 
  676            for (
int j = 0; j < nLANClients; ++j)
 
  683                r1 = 2 + (int)(4 * urng->GetValue());
 
  684                r2 = 10 * urng->GetValue();
 
  687                client.SetAttribute(
"Remote", remoteAddress);
 
  689                clientApp.
Add(
client.Install(nodes_net1[x][r1].Get(0)));
 
  696    auto routingStart = std::chrono::steady_clock::now();
 
  701        std::cout << 
"Using Nix-vectors..." << std::endl;
 
  706        std::cout << 
"Populating Global Static Routing Tables..." << std::endl;
 
  710    auto routingEnd = std::chrono::steady_clock::now();
 
  712        << 
"Routing tables population took " 
  713        << std::chrono::duration_cast<std::chrono::milliseconds>(routingEnd - routingStart).count()
 
  714        << 
"ms" << std::endl;
 
  717    std::cout << 
"Running simulator..." << std::endl;
 
  718    auto t1 = std::chrono::steady_clock::now();
 
  721    auto t2 = std::chrono::steady_clock::now();
 
  722    std::cout << 
"Simulator finished." << std::endl;
 
  725    auto d1 = std::chrono::duration_cast<std::chrono::seconds>(t1 - t0);
 
  726    auto d2 = std::chrono::duration_cast<std::chrono::seconds>(t2 - t1);
 
  728    std::cout << 
"-----" << std::endl << 
"Runtime Stats:" << std::endl;
 
  729    std::cout << 
"Simulator init time: " << d1.count() << 
"s" << std::endl;
 
  730    std::cout << 
"Simulator run time: " << d2.count() << 
"s" << std::endl;
 
  731    std::cout << 
"Total elapsed time: " << (d1 + d2).count() << 
"s" << std::endl;
 
  733    delete[] nodes_netLR;
 
2D array used in nix-vector-routing example "nms-p2p-nix.cc"
 
Array2D(const size_t x, const size_t y)
Constructor.
 
T * operator[](const size_t i)
Accessor operator.
 
const size_t m_xMax
maximum number of rows
 
3D array used in nix-vector-routing example "nms-p2p-nix.cc"
 
Array3D(const size_t x, const size_t y, const size_t z)
Constructor.
 
const size_t m_xMax
maximum number of rows
 
Array2D< T > ** p
Stored elements.
 
Array2D< T > & operator[](const size_t i)
Accessor operator.
 
a polymophic address class
 
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.
 
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
 
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.
 
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
 
static Ipv4Address GetAny()
 
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
 
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
 
Helper class to auto-assign global IPv6 unicast addresses.
 
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
 
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
 
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
 
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
 
Describes an IPv6 prefix.
 
holds a vector of ns3::NetDevice pointers
 
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
 
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 EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
 
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
 
static void Run()
Run the simulation.
 
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
 
static void Stop()
Tell the Simulator the calling event should be the last one executed.
 
Hold variables of type string.
 
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.
 
NixVectorHelper< Ipv6RoutingHelper > Ipv6NixVectorHelper
Create the typedef Ipv6NixVectorHelper with T as Ipv6RoutingHelper.
 
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.
 
Every class exported by the ns3 library is enclosed in the ns3 namespace.