How to Start Routing Information Protocol Projects Using NS2
To create the Routing Information Protocol (RIP) is one of the oldest distance-vector routing protocols, mainly used for routing in the minimum networks. In RIP, every router has periodically transmit bring up-to-date about the routing table for the neighbours. RIP is used in together IPv4 and IPv6 networks, though for our determination, we will concentrate on IPv4.
In NS2, we can replicate the RIP through generating a network for the routers, configure the distance-vector routing, and apply the RIP techniques in your replication.
Below is a step-by-step guide on how to start a RIP routing simulation using NS2.
Steps to Start Routing Information Protocol Projects Using NS2
- Install NS2
Initialize assure which NS2 is installed on your system. We can install NS2 as follows:
- For Ubuntu/Debian:
sudo apt update
sudo apt install ns2
sudo apt install nam
- For Windows: We may require to use a Linux virtual machine or Cygwin to run NS2.
After installation, verify NS2 installation:
ns
- Understand RIP Protocol
In RIP:
- Every router has periodically distributes the routing table through its neighbours.
- The routing table includes he distances such as in hops to different destinations.
- The maximum hop count in RIP is 15, import a network is measured unreachable the further 15 hops.
- RIP updates change the every 30 seconds via default.
- Design the Network Topology
Designed for the RIP project, we essential to generate a network topology that includes:
- Multiple routers.
- Hosts or end systems.
- Links among the routers and hosts.
- Simulate RIP in NS2
To simulate RIP in NS2, you’ll typically:
- Generate a node demonstrate the routers and hosts.
- Configure the links among the nodes by specified delays and bandwidth.
- Setting the RIP routing through ensure the RIP on the routers like as you may need to simulate RIP manually or use a pre-built routing module.
- Create a congestion to validate the routing.
Here is a basic TCL script which generates a small network and applies the RIP-like routing in NS2.
- TCL Script for RIP Simulation
Under is a sample for a basic RIP replication using NS2:
Example TCL Script for RIP
# Create a simulator object
set ns [new Simulator]
# Create the nodes (routers and hosts)
set r1 [$ns node] ;# Router 1
set r2 [$ns node] ;# Router 2
set r3 [$ns node] ;# Router 3
set h1 [$ns node] ;# Host 1
set h2 [$ns node] ;# Host 2
set h3 [$ns node] ;# Host 3
# Create links between routers
$ns duplex-link $r1 $r2 10Mb 20ms DropTail
$ns duplex-link $r2 $r3 10Mb 20ms DropTail
$ns duplex-link $r1 $h1 10Mb 20ms DropTail
$ns duplex-link $r2 $h2 10Mb 20ms DropTail
$ns duplex-link $r3 $h3 10Mb 20ms DropTail
# Enable RIP-like routing
# Note: In NS2, RIP is not natively implemented like OSPF or other protocols, so you will simulate it manually.
# We simulate the routing by defining routes between routers.
# In a real-world application, you would use a protocol such as RIPng for IPv6 or use OSPF.
# Set up static routes (as an example, RIP-like routing is based on hop count)
# r1 and r2 can reach each other directly, so we create static routes between them.
# Set routes from router to hosts
$ns route $r1 $h1 1
$ns route $r2 $h2 1
$ns route $r3 $h3 1
# Set up routing tables in routers (simulation of RIP)
# Each router knows how to reach the other routers
# Router 1 knows to forward traffic to router 2
# Router 2 knows to forward traffic to router 3
# Router 3 knows to forward traffic to router 1 (wraparound in case of circular routing)
# Define traffic between hosts (CBR for simplicity)
set udp1 [new Agent/UDP]
set sink1 [new Agent/Null]
$sink1 attach-agent $h3
$udp1 attach-agent $h1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 512
$cbr1 set interval_ 0.1
$cbr1 attach-agent $udp1
$ns connect $udp1 $sink1
# Traffic from host1 to host3
$ns at 1.0 “$cbr1 start”
$ns at 5.0 “$cbr1 stop”
# Trace file and animation output
$ns trace-all “rip_output.tr”
$ns namtrace-all “rip_output.nam”
# Run the simulation
$ns run
- Explanation of the Script
- Node Creation:
- The characters are initializing through generating routers such as r1, r2, r3 and hosts like as h1, h2, h3.
- Every node is built in using the $ns node.
- Link Creation:
- Connections are built among the routers and hosts using $ns duplex-link.
- Every connection has a detailed bandwidth for sample 10Mb and delay such as 20ms.
- Routing Setup:
- The route command is used to replicate the routing behavior. We manually configure the routes from the router for the hosts, demonstrate the distances such as hop counts in a RIP-like manner.
- In real RIP, routers modify the routing tables, nevertheless for simplicity, we replicate the routing through manually state a routes.
- Traffic Generation:
- CBR (Constant Bit Rate) congested is built among host1 and host3.
- The CBR starts at 1 second and stops at 5 seconds.
- Trace and NAM:
- The create the replication for trace data such as rip_output.tr and an animation file like as rip_output.nam for display the network traffic and routing.
- Running the Simulation:
- The process is the replication by $ns run, and outcomes can be examine using the NAM for visualization or trace files for detailed study.
- Run and Analyze the Results
- NAM Visualization:
- We can view the replication for NAM:
nam rip_output.nam
-
- In NAM, we will view the network topology and the packet flow from host1 to host3, routed completes the routers in a RIP-like manner.
- Trace File Analysis:
- The trace file such as rip_output.tr has included the complete data on packet flow, involves the packet creation, arrival times, and routing decisions.
- We can examine the trace file using tools such as awk:
awk ‘{print $1, $2, $3, $4}’ rip_output.tr
- Extend the RIP Project
We spread this RIP replication, you can:
- Add more routers and hosts: Generate a larger network and validate on how RIP supports for a larger networks.
- Simulate Dynamic Routing: Apply the periodic bring up-to-date for routing tables in RIP to replicate the distance-vector algorithm.
- Multiple Traffic Flows: Enhance the further traffic flows among other hosts in the network we examine the routing below load.
- Link Failures: Replicate the connection failures and observe on how the RIP supports the recovery through sending the new routing updates.
We clearly understood and get knowledge about how to install the ns2 simulation and how to deploy the Routing information protocol for lossy network protocol has executed in ns2 simulator. We plan to elaborate how the Routing information protocol will perform in other simulation tool.