How to Implement Routing Information Protocol in NS2

 

To implement the Routing Information Protocol (RIP) in NS2 has needed to mimic a distance vector routing protocol, by way of RIP is based on distance vector algorithms and the NS2 doesn’t have a built-in RIP implementation, however it is probable to mimic the behaviour of RIP by generating custom logic or adjusting an existing protocol such as DSDV (Destination-Sequenced Distance Vector) that performs on similar principles.

Get engaging project concepts from our researchers featuring innovative topics. Receive customized support for the implementation of Routing Information Protocol in NS2. We provide you with detailed comparative analysis for your projects; simply send us your project information for further assistance.

Here’s how to simulate RIP-like behavior in NS2:

Steps to Simulate RIP in NS2:

  1. Understand RIP and Distance Vector Routing:
    • RIP is a distance vector routing protocol that uses hop count as the routing parameters. Each router intermittently sends out updates to its neighbours, and it follows the principle of Bellman-Ford to regulate the shortest path to each destination.
    • RIP limits the maximum number of hops to stop loops (default is 15 hops).
  2. Modify or Extend DSDV for RIP-like Behavior: DSDV is a distance vector routing protocol executed in NS2. We can use DSDV as the base and adjust it to implement RIP’s behavior.
  3. Basic TCL Script Configuration: we need to mimic the routing behaviour with DSDV, adjusting its metrics to act such as RIP. Here’s an sample of TCL script for configuring a simple simulation:

Example TCL Script for Simulating RIP Behavior

# Create a simulator instance

set ns [new Simulator]

# Create a trace file

set tracefile [open “rip_trace.tr” w]

$ns trace-all $tracefile

# Create a nam file

set namfile [open “rip.nam” w]

$ns namtrace-all-wireless $namfile

# Set up the network topology

set topo [new Topography]

$topo load_flatgrid 500 500

# Configure the nodes with DSDV (similar to RIP)

$ns node-config -adhocRouting DSDV \

-llType LL \

-macType Mac/802_11 \

-ifqType Queue/DropTail/PriQueue \

-ifqLen 50 \

-antType Antenna/OmniAntenna \

-propType Propagation/TwoRayGround \

-phyType Phy/WirelessPhy \

-channelType Channel/WirelessChannel \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON

# Create the nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

# Define the connections (topology) between nodes (4 nodes in total)

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

$ns duplex-link $n1 $n2 1Mb 10ms DropTail

$ns duplex-link $n2 $n3 1Mb 10ms DropTail

# Setup traffic

set udp0 [new Agent/UDP]

set sink [new Agent/Null]

$ns attach-agent $n0 $udp0

$ns attach-agent $n3 $sink

$ns connect $udp0 $sink

# Setup a CBR (Constant Bit Rate) traffic generator

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 500

$cbr set interval_ 0.2

$cbr attach-agent $udp0

# Schedule the traffic to start and stop

$ns at 0.5 “$cbr start”

$ns at 4.5 “$cbr stop”

# End simulation at time 5.0 seconds

$ns at 5.0 “finish”

# Define finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam rip.nam &

exit 0

}

# Run the simulation

$ns run

Key Elements in the TCL Script:

  • node-config -adhocRouting DSDV: Setup the nodes to use DSDV, that is similar to RIP in terms of using a distance vector approach. Since DSDV is proactive and RIP is periodic, this delivers a close approximation of how RIP performs.
  • Traffic setup: A UDP agent and a CBR application are used to create traffic in the simulation.
  • Link setup: The duplex-link commands generate the network connections among the nodes.
  1. Modify the C++ Code for RIP Behavior (Optional)

If we need to mimic RIP-specific characteristics more precisely like periodic updates, split horizon, route poisoning we will need to adjust the C++ source code. we can initiate by using the existing DSDV code as a template.

C++ Files to Modify:

  1. DSDV files (dsdv.h, dsdv.cc):
    • These files include the logic for DSDV. We need to adjust them to add periodic updates such as RIP, and implement RIP-specific behaviours such as split horizon and route poisoning.

Example of C++ Modifications:

  • Periodic Updates: Adjust the update interval to implement RIP’s periodic updates.
  • Split Horizon: Avoid nodes from advertising routes back to the node from which they were learned.

Here is a simplified view of where to initiate in the dsdv.cc file:

void DSDV::recvHello(Packet* p) {

// Add logic for receiving RIP-like periodic updates

}

void DSDV::sendHello() {

// Add logic for sending periodic RIP updates (routing table advertisements)

}

Steps for Modifying:

  1. Navigate to the NS2 directory:

cd ns-allinone-2.35/ns-2.35/

  1. Adapt the dsdv.cc and dsdv.h files to include RIP-like behaviours.
  2. Recompile NS2 after adjusting the source code:

./configure

make clean

make

  1. Visualize and Analyse the Simulation

After running the TCL script, open the NAM (Network Animator) file to visualize the simulation. We need to evaluate on how packets traverse the network and how routing updates are managed.

  1. Execute the TCL script:

ns rip_simulation.tcl

  1. Open the NAM file to visualize the simulation:

nam rip.nam

  1. Trace File Analysis

The trace file (rip_trace.tr) will include the information about packet transmissions, routing table updates, and other events. We need to evaluate it to see how the routing protocol performs.

For Instance, we can write a Python or AWK script to evaluate the trace file for routing updates or packet delivery ratios.

We demonstrate and show how the Routing Information Protocol will generate the network then applies the Routing Information Protocol logic that was executed in ns2 tool. We plan to provide the detailed information regarding the Routing Information Protocol implementation process in further scripts.