Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to implement global routing in ns3

To implement the global routing in ns3, we can use built-in global routing protocol in ns3 tool. In ns3 offers a GlobalRoutingHelper class to enable the custom use of global routing protocol that evaluates routes that based on global network topology.

Steps to Implement Global Routing in ns3

  1. Install ns3:  make sure ns3 is installed in the computer.
  2. Set Up ns3 Workspace: for the project create the working directory.
  3. Create a Simulation Script:
    • Describe the network topology.
    • Download the Internet stack.
    • Use the GlobalRoutingHelper to enable global routing.
    • Configure applications and execute it.

Example Simulation Script

We provide the complete script to setup a basic network with global routing in ns3 simulator:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

#include “ns3/global-routing-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“GlobalRoutingExample”);

int main (int argc, char *argv[])

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create (4);

// Create point-to-point links

PointToPointHelper p2p;

p2p.SetDeviceAttribute (“DataRate”, StringValue (“1Mbps”));

p2p.SetChannelAttribute (“Delay”, StringValue (“10ms”));

NetDeviceContainer devices01 = p2p.Install (nodes.Get (0), nodes.Get (1));

NetDeviceContainer devices12 = p2p.Install (nodes.Get (1), nodes.Get (2));

NetDeviceContainer devices23 = p2p.Install (nodes.Get (2), nodes.Get (3));

NetDeviceContainer devices30 = p2p.Install (nodes.Get (3), nodes.Get (0));

// Install the Internet stack

InternetStackHelper stack;

stack.Install (nodes);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces01 = address.Assign (devices01);

address.SetBase (“10.1.2.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces12 = address.Assign (devices12);

address.SetBase (“10.1.3.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces23 = address.Assign (devices23);

address.SetBase (“10.1.4.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces30 = address.Assign (devices30);

// Enable global routing

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Create a packet sink to receive packets

uint16_t sinkPort = 8080;

Address sinkAddress (InetSocketAddress (interfaces23.GetAddress (1), sinkPort));

PacketSinkHelper packetSinkHelper (“ns3::TcpSocketFactory”, sinkAddress);

ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (3));

sinkApps.Start (Seconds (1.0));

sinkApps.Stop (Seconds (10.0));

// Create a TCP client to send packets

OnOffHelper clientHelper (“ns3::TcpSocketFactory”, sinkAddress);

clientHelper.SetAttribute(“OnTime”,StringValue(“ns3::ConstantRandomVariable[Constant=1]”));

clientHelper.SetAttribute(“OffTime”,StringValue(“ns3::ConstantRandomVariable[Constant=0]”));

clientHelper.SetAttribute (“DataRate”, DataRateValue (DataRate (“1Mbps”)));

clientHelper.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = clientHelper.Install (nodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Enable tracing

AsciiTraceHelper ascii;

p2p.EnableAsciiAll (ascii.CreateFileStream (“global-routing.tr”));

p2p.EnablePcapAll (“global-routing”);

// Run the simulation

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation

Below are the description for global routing protocol

  1. Create Nodes and Links: The script creates four nodes and connects them with point-to-point links.
  2. Install Internet Stack: The Internet stack is installed on the nodes using the InternetStackHelper.
  3. Assign IP Addresses: IP addresses are assigned to the interfaces on the nodes.
  4. Enable Global Routing: The Ipv4GlobalRoutingHelper::PopulateRoutingTables function is called to enable global routing and populate the routing tables based on the global network topology.
  5. Create Applications: A packet sink application is installed on node 3 to receive packets. An OnOff application is installed on node 0 to send packets to node 3.
  6. Enable Tracing: ASCII and pcap tracing are enabled to capture the simulation output.
  7. Run the Simulation: The simulation is run and then destroyed.

Running the Simulation

To run the simulation, compile the script and execute it:

./waf configure –enable-examples

./waf build

./waf –run global-routing

Finally, here we discussed about how to implement the global routing how it calculates the routes by integrating with ns3. Comparative analysis on global routing in ns3 for various concepts are assisted by ns3simulation.com.