To simulate classful routing protocols in NS2, we want to familiarize that classful routing protocols are those which don’t transmit subnet mask information in routing updates. Example of classful routing protocols takes account of RIP (Routing Information Protocol) version 1 and IGRP (Interior Gateway Routing Protocol). These protocols are inadequate to the older class-based IP addressing system (Class A, B, and C), dissimilar classless routing protocols such as RIP version 2 or OSPF.
In NS2, we can simulate RIP v1 as an instance of a classful routing protocol. The process contain to describing network topology, configure IP addressing for different classes (A, B, or C), and generating traffic flows. Get in touch with us we will share with you interesting project topics and ideas tailored to your needs.
Here’s how you can simulate a classful protocol like RIP v1 in NS2.
Steps to Simulate Classful Routing Protocol in NS2
- Install NS2
Make sure that NS2 is installed on the system. If not, we can install it on Linux-based systems using:
sudo apt-get install ns2
For Windows, use Cygwin or a pre-compiled version of NS2.
- Create the TCL Script for Classful Protocol Simulation
Below is an instance of a TCL script to replicate RIP v1 in NS2. RIP v1 is a simple classful routing protocol, in which subnet masks are not containing in routing updates.
Example TCL Script for Simulating RIP v1
# Define the simulator object
set ns [new Simulator]
# Open trace file to log the simulation results
set tracefile [open rip_classful.tr w]
$ns trace-all $tracefile
# Open NAM file to visualize the simulation
set namfile [open rip_classful.nam w]
$ns namtrace-all $namfile
# Define parameters
set val(nn) 4 ;# Number of nodes (routers)
set val(stop) 20.0;# Simulation stop time
set val(routing) DV ;# RIP v1 uses Distance Vector routing (DV)
# Create nodes for the simulation
set node_(0) [$ns node] ;# Router 1 (Class A network)
set node_(1) [$ns node] ;# Router 2 (Class B network)
set node_(2) [$ns node] ;# Router 3 (Class C network)
set node_(3) [$ns node] ;# Router 4 (Class C network)
# Create network links (wired network)
$ns duplex-link $node_(0) $node_(1) 10Mb 10ms DropTail
$ns duplex-link $node_(1) $node_(2) 10Mb 10ms DropTail
$ns duplex-link $node_(2) $node_(3) 10Mb 10ms DropTail
# Define RIP-based routing (Distance Vector for RIP v1)
$ns rtproto $val(routing)
# Assign Classful IP addresses
# Class A: 10.x.x.x
$node_(0) set classful_address “10.0.0.1” ;# Router 1 in Class A network
# Class B: 172.x.x.x
$node_(1) set classful_address “172.16.0.1” ;# Router 2 in Class B network
# Class C: 192.x.x.x
$node_(2) set classful_address “192.168.1.1” ;# Router 3 in Class C network
$node_(3) set classful_address “192.168.2.1” ;# Router 4 in Class C network
# Set up traffic between nodes (UDP traffic)
set udp0 [new Agent/UDP]
$ns attach-agent $node_(0) $udp0
set null0 [new Agent/Null]
$ns attach-agent $node_(3) $null0
$ns connect $udp0 $null0
# Configure a CBR (Constant Bit Rate) traffic source over UDP
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.01
$cbr0 attach-agent $udp0
# Start CBR traffic at 1 second
$ns at 1.0 “$cbr0 start”
$ns at 19.0 “$cbr0 stop”
# End the simulation at 20 seconds
$ns at $val(stop) “finish”
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam rip_classful.nam &
exit 0
}
# Start the simulation
$ns run
- Explanation of the Script
- Simulator Object: This is the object ($ns) used to generate and execute the simulation.
- Nodes: Four nodes are generated to denoted routers. Each node is assigned a classful IP address based on the class-based addressing system (Class A, B, or C).
- Class A: Address starts with 10.x.x.x.
- Class B: Address starts with 172.x.x.x.
- Class C: Address starts with 192.x.x.x.
- Links: Duplex links with bandwidth of 10 Mbps and a latency of 10 ms are generated among the nodes.
- RIP (Distance Vector Routing): RIP v1 is executed by using the rtproto DV command, where “DV” denotes to Distance Vector routing.
- Traffic: A UDP traffic source (CBR) is configured among nodes, and packets flow from one node to another.
- End Simulation: The simulation executes for 20 seconds, after which the trace file and NAM file are closed.
- Running the Simulation
Save the script as rip_classful.tcl, and execute it in the end by using NS2:
ns rip_classful.tcl
- Visualizing the Simulation
After the simulation processed, we can envision the packet flow and routing behaviour using the NAM (Network Animator) tool:
nam rip_classful.nam
NAM will open a window in which we can track the network topology, data packet flow, and how the nodes interact by using RIP v1.
- Analysing the Trace File
The trace file (rip_classful.tr) encompasses detailed information about packet transmissions, drops, and routing updates. We need to evaluate this file to extract parameters such as:
- Throughput: Total data successfully routed via the network.
- Packet Delivery Ratio: Ratio of packets successfully delivered to the destination.
- End-to-End Delay: Time taken for packets to reach the destination.
- Modifying and Extending the Simulation
We can adjust this simple simulation to incorporate different environment or features:
- Add More Nodes: Mimic larger networks by incorporate more routers with classful addressing.
- Change Traffic Type: Utilize TCP or other traffic sources to replicate different application-layer protocols.
- Measure Performance: Evaluate throughput, packet delivery ratio, delay, and other parameters according to network load or topology changes.
- Routing Comparisons: Relate classful RIP v1 to classless routing protocols such as RIP v2, OSPF, or BGP to measure performance in numerous environments.
Through the entire process, you can acquire the simulation and execution process regarding the classful routing protocols project offered in it using ns2 tool. We will plan to offer the more information regarding the classful routing protocols in another manual.