39 #include "ns3/core-module.h" 
   40 #include "ns3/internet-module.h" 
   41 #include "ns3/network-module.h" 
   42 #include "ns3/point-to-point-module.h" 
   43 #include "ns3/applications-module.h" 
   44 #include "ns3/onoff-application.h" 
   45 #include "ns3/packet-sink.h" 
   46 #include "ns3/simulator.h" 
   47 #include "ns3/ipv4-static-routing-helper.h" 
   48 #include "ns3/ipv4-list-routing-helper.h" 
   49 #include "ns3/ipv4-nix-vector-helper.h" 
   54 #define TIMER_NOW(_t) gettimeofday (&_t,NULL); 
   55 #define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6) 
   56 #define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS (_t1)-TIMER_SECONDS (_t2)) 
   69     Array2D (
const size_t x, 
const size_t y) : p (new T*[x]), m_xMax (x) 
 
   71         for (
size_t i = 0; i < m_xMax; i++)
 
   77         for (
size_t i = 0; i < m_xMax; i++)
 
   83     T* operator[] (
const size_t i)
 
   96     Array3D (
const size_t x, 
const size_t y, 
const size_t z)
 
   97       : p (new 
Array2D<T>*[x]), m_xMax (x)
 
   99         for (
size_t i = 0; i < m_xMax; i++)
 
  105         for (
size_t i = 0; i < m_xMax; i++)
 
  128   std::cout << 
" ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << std::endl;
 
  131   int nCN = 2, nLANClients = 42;
 
  135   cmd.
AddValue (
"CN", 
"Number of total CNs [2]", nCN);
 
  136   cmd.
AddValue (
"LAN", 
"Number of nodes per LAN [42]", nLANClients);
 
  137   cmd.
AddValue (
"NIX", 
"Toggle nix-vector routing", nix);
 
  138   cmd.
Parse (argc,argv);
 
  142       std::cout << 
"Number of total CNs (" << nCN << 
") lower than minimum of 2" 
  147   std::cout << 
"Number of CNs: " << nCN << 
", LAN nodes: " << nLANClients << std::endl;
 
  168   std::ostringstream oss;
 
  181   list.
Add (staticRouting, 0);
 
  182   list.
Add (nixRouting, 10);
 
  190   for (
int z = 0; z < nCN; ++z) 
 
  192       std::cout << 
"Creating Campus Network " << z << 
":" << std::endl;
 
  194       std::cout << 
"  SubNet [ 0";
 
  195       for (
int i = 0; i < 3; ++i) 
 
  197           nodes_net0[z][i].Create (1);
 
  198           stack.
Install (nodes_net0[z][i]);
 
  200       nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
 
  201       nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
 
  202       nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
 
  204       for (
int i = 0; i < 3; ++i) 
 
  206           ndc0[i] = p2p_1gb5ms.
Install (nodes_net0[z][i]);
 
  210       for (
int i = 0; i < 6; ++i) 
 
  212           nodes_net1[z][i].Create (1);
 
  213           stack.
Install (nodes_net1[z][i]);
 
  215       nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
 
  216       nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
 
  217       nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
 
  218       nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
 
  219       nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
 
  221       for (
int i = 0; i < 6; ++i) 
 
  227           ndc1[i] = p2p_1gb5ms.
Install (nodes_net1[z][i]);
 
  231       net0_1.
Add (nodes_net0[z][2].Get (0));
 
  232       net0_1.
Add (nodes_net1[z][0].Get (0));
 
  234       ndc0_1 = p2p_1gb5ms.
Install (net0_1);
 
  236       oss << 10 + z << 
".1.252.0";
 
  237       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  238       ifs = address.
Assign (ndc0_1);
 
  241       for (
int i = 0; i < 14; ++i) 
 
  243           nodes_net2[z][i].Create (1);
 
  244           stack.
Install (nodes_net2[z][i]);
 
  246       nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
 
  247       nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
 
  248       nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
 
  249       nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
 
  250       nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
 
  251       nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
 
  252       nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
 
  253       nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
 
  254       nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
 
  255       nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
 
  256       nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
 
  257       nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
 
  258       nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
 
  259       nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
 
  261       for (
int i = 0; i < 14; ++i) 
 
  263           ndc2[i] = p2p_1gb5ms.
Install (nodes_net2[z][i]);
 
  267       for (
int i = 0; i < 7; ++i) 
 
  270           oss << 10 + z << 
".4." << 15 + i << 
".0";
 
  271           address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  272           for (
int j = 0; j < nLANClients; ++j) 
 
  274               nodes_net2LAN[z][i][j].Create (1);
 
  275               stack.
Install (nodes_net2LAN[z][i][j]);
 
  276               nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
 
  277               ndc2LAN[i][j] = p2p_100mb1ms.
Install (nodes_net2LAN[z][i][j]);
 
  278               ifs2LAN[z][i][j] = address.
Assign (ndc2LAN[i][j]);
 
  282       std::cout << 
" 3 ]" << std::endl;
 
  283       for (
int i = 0; i < 9; ++i) 
 
  285           nodes_net3[z][i].Create (1);
 
  286           stack.
Install (nodes_net3[z][i]);
 
  288       nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
 
  289       nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
 
  290       nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
 
  291       nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
 
  292       nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
 
  293       nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
 
  294       nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
 
  295       nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
 
  296       nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
 
  298       for (
int i = 0; i < 9; ++i) 
 
  300           ndc3[i] = p2p_1gb5ms.
Install (nodes_net3[z][i]);
 
  304       for (
int i = 0; i < 5; ++i) 
 
  307           oss << 10 + z << 
".5." << 10 + i << 
".0";
 
  308           address.
SetBase (oss.str ().c_str (), 
"255.255.255.255");
 
  309           for (
int j = 0; j < nLANClients; ++j) 
 
  311               nodes_net3LAN[z][i][j].Create (1);
 
  312               stack.
Install (nodes_net3LAN[z][i][j]);
 
  313               nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
 
  314               ndc3LAN[i][j] = p2p_100mb1ms.
Install (nodes_net3LAN[z][i][j]);
 
  315               ifs3LAN[z][i][j] = address.
Assign (ndc3LAN[i][j]);
 
  318       std::cout << 
"  Connecting Subnets..." << std::endl;
 
  320       nodes_netLR[z].
Create (2);
 
  321       stack.
Install (nodes_netLR[z]);
 
  323       ndcLR = p2p_1gb5ms.
Install (nodes_netLR[z]);
 
  325       NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
 
  326       net0_4.
Add (nodes_netLR[z].Get (0));
 
  327       net0_4.
Add (nodes_net0[z][0].Get (0));
 
  328       net0_5.
Add (nodes_netLR[z].Get  (1));
 
  329       net0_5.
Add (nodes_net0[z][1].Get (0));
 
  330       net2_4a.
Add (nodes_netLR[z].Get (0));
 
  331       net2_4a.
Add (nodes_net2[z][0].Get (0));
 
  332       net2_4b.
Add (nodes_netLR[z].Get (1));
 
  333       net2_4b.
Add (nodes_net2[z][1].Get (0));
 
  334       net3_5a.
Add (nodes_netLR[z].Get (1));
 
  335       net3_5a.
Add (nodes_net3[z][0].Get (0));
 
  336       net3_5b.
Add (nodes_netLR[z].Get (1));
 
  337       net3_5b.
Add (nodes_net3[z][1].Get (0));
 
  339       ndc0_4 = p2p_1gb5ms.
Install (net0_4);
 
  341       oss << 10 + z << 
".1.253.0";
 
  342       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  343       ifs = address.
Assign (ndc0_4);
 
  344       ndc0_5 = p2p_1gb5ms.
Install (net0_5);
 
  346       oss << 10 + z << 
".1.254.0";
 
  347       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  348       ifs = address.
Assign (ndc0_5);
 
  349       ndc2_4a = p2p_1gb5ms.
Install (net2_4a);
 
  351       oss << 10 + z << 
".4.253.0";
 
  352       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  353       ifs = address.
Assign (ndc2_4a);
 
  354       ndc2_4b = p2p_1gb5ms.
Install (net2_4b);
 
  356       oss << 10 + z << 
".4.254.0";
 
  357       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  358       ifs = address.
Assign (ndc2_4b);
 
  359       ndc3_5a = p2p_1gb5ms.
Install (net3_5a);
 
  361       oss << 10 + z << 
".5.253.0";
 
  362       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  363       ifs = address.
Assign (ndc3_5a);
 
  364       ndc3_5b = p2p_1gb5ms.
Install (net3_5b);
 
  366       oss << 10 + z << 
".5.254.0";
 
  367       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  368       ifs = address.
Assign (ndc3_5b);
 
  370       std::cout << 
"  Assigning IP addresses..." << std::endl;
 
  371       for (
int i = 0; i < 3; ++i) 
 
  374           oss << 10 + z << 
".1." << 1 + i << 
".0";
 
  375           address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  376           ifs0[z][i] = address.
Assign (ndc0[i]);
 
  378       for (
int i = 0; i < 6; ++i) 
 
  385           oss << 10 + z << 
".2." << 1 + i << 
".0";
 
  386           address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  387           ifs1[z][i] = address.
Assign (ndc1[i]);
 
  390       oss << 10 + z << 
".3.1.0";
 
  391       address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  392       ifs = address.
Assign (ndcLR);
 
  393       for (
int i = 0; i < 14; ++i) 
 
  396           oss << 10 + z << 
".4." << 1 + i << 
".0";
 
  397           address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  398           ifs2[z][i] = address.
Assign (ndc2[i]);
 
  400       for (
int i = 0; i < 9; ++i) 
 
  403           oss << 10 + z << 
".5." << 1 + i << 
".0";
 
  404           address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  405           ifs3[z][i] = address.
Assign (ndc3[i]);
 
  411       std::cout << 
"Forming Ring Topology..." << std::endl;
 
  413       for (
int z = 0; z < nCN-1; ++z) 
 
  415           nodes_ring[z].
Add (nodes_net0[z][0].Get (0));
 
  416           nodes_ring[z].
Add (nodes_net0[z+1][0].Get (0));
 
  418       nodes_ring[nCN-1].
Add (nodes_net0[nCN-1][0].Get (0));
 
  419       nodes_ring[nCN-1].
Add (nodes_net0[0][0].Get (0));
 
  421       for (
int z = 0; z < nCN; ++z) 
 
  423           ndc_ring[z] = p2p_2gb200ms.
Install (nodes_ring[z]);
 
  425           oss << 
"254.1." << z + 1 << 
".0";
 
  426           address.
SetBase (oss.str ().c_str (), 
"255.255.255.0");
 
  427           ifs = address.
Assign (ndc_ring[z]);
 
  434   std::cout << 
"Creating TCP Traffic Flows:" << std::endl;
 
  437                       StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"));
 
  439                       StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
 
  445   for (
int z = 0; z < nCN; ++z) 
 
  453       std::cout << 
"  Campus Network " << z << 
" Flows [ Net2 ";
 
  454       for (
int i = 0; i < 7; ++i) 
 
  456           for (
int j = 0; j < nLANClients; ++j) 
 
  462                   nodes_net2LAN[z][i][j].Get (0));
 
  463               sinkApp.
Start (Seconds (0.0));
 
  465               r1 = 2 + (int)(4 * urng->
GetValue ());
 
  469                                             ifs2LAN[z][i][j].GetAddress (0), 9999));
 
  472               clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
 
  473               clientApp.
Start (Seconds (r2));
 
  477       std::cout << 
"Net3 ]" << std::endl;
 
  478       for (
int i = 0; i < 5; ++i) 
 
  480           for (
int j = 0; j < nLANClients; ++j) 
 
  486                   nodes_net3LAN[z][i][j].Get (0));
 
  487               sinkApp.
Start (Seconds (0.0));
 
  489               r1 = 2 + (int)(4 * urng->
GetValue ());
 
  493                                             ifs3LAN[z][i][j].GetAddress (0), 9999));
 
  496               clientApp.
Add (client.
Install (nodes_net1[x][r1].Get (0)));
 
  497               clientApp.
Start (Seconds (r2));
 
  509       std::cout << 
"Using Nix-vectors..." << std::endl;
 
  514       std::cout << 
"Populating Global Static Routing Tables..." << std::endl;
 
  520   std::cout << 
"Routing tables population took "  
  521        << 
TIMER_DIFF (routingEnd, routingStart) << std::endl;
 
  524   std::cout << 
"Running simulator..." << std::endl;
 
  529   std::cout << 
"Simulator finished." << std::endl;
 
  533   std::cout << 
"-----" << std::endl << 
"Runtime Stats:" << std::endl;
 
  534   std::cout << 
"Simulator init time: " << d1 << std::endl;
 
  535   std::cout << 
"Simulator run time: " << d2 << std::endl;
 
  536   std::cout << 
"Total elapsed time: " << d1+d2 << std::endl;
 
  538   delete[] nodes_netLR;
 
holds a vector of ns3::Application pointers. 
 
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. Makes all nodes in the simulation into routers. 
 
hold variables of type string 
 
NetDeviceContainer Install(NodeContainer c)
 
Array2D(const size_t x, const size_t y)
 
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
 
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...
 
Build a set of PointToPointNetDevice objects. 
 
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
 
void SetDeviceAttribute(std::string name, const AttributeValue &value)
 
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes. 
 
a polymophic address class 
 
Array3D(const size_t x, const size_t y, const size_t z)
 
Hold an unsigned integer type. 
 
holds a vector of ns3::NetDevice pointers 
 
#define TIMER_DIFF(_t1, _t2)
 
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)
 
void SetDefault(std::string name, const AttributeValue &value)
 
keep track of a set of node pointers. 
 
void Install(std::string nodeName) const 
 
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
 
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
 
void SetChannelAttribute(std::string name, const AttributeValue &value)
 
hold objects of type ns3::Address 
 
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
 
struct timeval TIMER_TYPE
 
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container. 
 
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
 
int main(int argc, char *argv[])
 
Helper class that adds ns3::Ipv4StaticRouting objects. 
 
void AddValue(const std::string &name, const std::string &help, T &value)
 
Helper class that adds ns3::Ipv4ListRouting objects. 
 
ApplicationContainer Install(NodeContainer c) const 
 
void Parse(int argc, char *argv[])
 
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. 
 
ApplicationContainer Install(NodeContainer c) const 
 
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
 
void SetAttribute(std::string name, const AttributeValue &value)
 
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address. 
 
void LogComponentEnable(char const *name, enum LogLevel level)