How to Develop Distance Vector Routing Projects Using NS3

To develop Distance Vector Routing (DVR) in NS3 which is a routing mechanism in which every node modernises their routing table according to the data that can be received from its neighbors. The most general DVR’s implementation is Routing Information Protocol (RIP).

We will implement a Distance Vector Routing (DVR) simulation by applying the built-in RIP module in NS3.

Steps to Develop a Distance Vector Routing Project in NS3

  1. Setup NS3 Environment

We make sure that NS3 is installed on the computer:

sudo apt update

sudo apt install git

git clone https://gitlab.com/nsnam/ns-3-dev.git

cd ns-3-dev

./ns3 configure

./ns3 build

  1. Define Network Topology

We will design a normal DVR-based network topology that has several routes, which interchange the routing data.

Example Topology

[Node 1] — [Router 1] — [Router 2] — [Router 3] — [Node 2]

  • Every single router sustains the routing table.
  • Routers periodically interchange the updates of distance vector.
  1. Enable Distance Vector Routing in NS3

Allow RIP (a Distance Vector Routing protocol) in the simulation network NS3, utilising:

  • RipHelper (permitting RIP on the routers)
  • Ipv4StaticRoutingHelper (for manual routing comparison)
  1. NS3 Code Implementation for Distance Vector Routing

(a) Setup Network Topology

#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/ipv4-global-routing-helper.h”

#include “ns3/rip-helper.h”

using namespace ns3;

int main () {

NodeContainer nodes;

nodes.Create (5); // Two hosts + Three routers

NodeContainer n1r1 = NodeContainer (nodes.Get(0), nodes.Get(1));

NodeContainer r1r2 = NodeContainer (nodes.Get(1), nodes.Get(2));

NodeContainer r2r3 = NodeContainer (nodes.Get(2), nodes.Get(3));

NodeContainer r3n2 = NodeContainer (nodes.Get(3), nodes.Get(4));

PointToPointHelper p2p;

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

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

NetDeviceContainer d1r1 = p2p.Install(n1r1);

NetDeviceContainer dr1r2 = p2p.Install(r1r2);

NetDeviceContainer dr2r3 = p2p.Install(r2r3);

NetDeviceContainer dr3n2 = p2p.Install(r3n2);

InternetStackHelper internet;

RipHelper ripRouting;

Ipv4ListRoutingHelper listRouting;

listRouting.Add(ripRouting, 100);

internet.SetRoutingHelper(listRouting);

internet.Install(nodes);

Ipv4AddressHelper ipv4;

ipv4.SetBase (“192.168.1.0”, “255.255.255.0”);

ipv4.Assign(d1r1);

ipv4.SetBase (“192.168.2.0”, “255.255.255.0”);

ipv4.Assign(dr1r2);

ipv4.SetBase (“192.168.3.0”, “255.255.255.0”);

ipv4.Assign(dr2r3);

ipv4.SetBase (“192.168.4.0”, “255.255.255.0”);

ipv4.Assign(dr3n2);

Ipv4GlobalRoutingHelper::PopulateRoutingTables();

Simulator::Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Traffic Generation (Data Transfer)

We can utilise UDP traffic to replicate the data transfer by analysing distance vector routing.

(a) Add UDP Server

uint16_t port = 9;

UdpServerHelper server(port);

ApplicationContainer serverApp = server.Install(nodes.Get(4));

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(9.0));

(b) Add UDP Client

UdpClientHelper client(Ipv4Address(“192.168.4.2”), port);

client.SetAttribute(“MaxPackets”, UintegerValue(10));

client.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

client.SetAttribute(“PacketSize”, UintegerValue(512));

ApplicationContainer clientApp = client.Install(nodes.Get(0));

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(8.0));

  1. Performance Analysis

We want to examine the performance with metrics such as routing table updates, packet loss, and delay using FlowMonitor.

FlowMonitorHelper flowmon;

Ptr<FlowMonitor> monitor = flowmon.InstallAll();

monitor->SerializeToXmlFile(“distance-vector-routing-results.xml”, true, true);

  1. Visualization & Debugging

(a) Use NetAnim for Network Visualization

sudo apt install netanim

Execute the simulation script using:

./waf –run your-script-name

After that, we can launch:

netanim

(b) Use Routing Table Dump

Debug routing updates with the support of Routing Table Dump:

./waf –run your-script-name > routing_table.txt

  1. Advanced Extensions
  • Equate the performance of Distance Vector (RIP) with Link-State (OSPF) Routing.
  • In large networks, examine the Route Convergence Time.
  • Execute QoS-aware Distance Vector Routing.
  • Replicate DVR including the Dynamic Network Failures.

This approach will support you to know the essential concepts and the way how to develop the Distance Vector Routing projects using built-in RIP module in NS3 tool and how to analyse, visualize the performance. If needed, we can share advanced extension of this topic.