How to Simulate Distance Routing Projects Using NS2

To simulate distance routing projects within NS2, we will usually utilize the protocols, which compute the shortest path according to the distance metric among the nodes, like Distance Vector Routing (DVR) or Link State Routing (LSR). The Distance Vector Routing protocol is depends on the Bellman-Ford algorithm in which each router maintains a table, which holds the best-known distance to each destination and periodically distributes this information with its neighbours.

Here’s how we can simulate a Distance Vector Routing (DVR) project using NS2, which depends on distance-based routing decisions.

Steps to Simulate Distance Routing in NS2

  1. Install NS2

Make sure NS2 is installed on the machine. If we haven’t installed it yet, we can download it from the NS2 Official Website.

  1. Create a TCL Script for Distance Vector Routing (DVR)

The following script configures a simple network in which nodes are utilizing the Distance Vector Routing to communicate. Nodes exchange distance vectors to find out the shortest path to each other.

Example TCL Script for Distance Vector Routing Simulation:

# Create a simulator object

set ns [new Simulator]

# Define trace and NAM files for analysis and visualization

set tracefile [open “distance_routing_trace.tr” w]

set namfile [open “distance_routing_simulation.nam” w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Create nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

# Define links between nodes with bandwidth and delay (costs)

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

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

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

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

$ns duplex-link $n0 $n2 1Mb 25ms DropTail

$ns duplex-link $n1 $n3 1Mb 15ms DropTail

# Enable Distance Vector Routing (uses Bellman-Ford Algorithm)

for {set i 0} {$i < 5} {incr i} {

$ns at 0.0 “$n$i start-dv-routing”

# Create an UDP agent and attach it to node 0 (source)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

# Define a CBR (Constant Bit Rate) traffic generator for the UDP agent

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 1Mb

$cbr0 attach-agent $udp0

# Attach a UDP sink agent to node 4 (destination)

set udp1 [new Agent/UDP]

$ns attach-agent $n4 $udp1

# Connect the source and destination agents

$ns connect $udp0 $udp1

# Schedule the traffic flow

$ns at 1.0 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

# Define the finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exit 0

}

# End the simulation at 5 seconds

$ns at 5.0 “finish”

# Run the simulation

$ns run

  1. Run the Simulation

We can save this script as distance_routing_simulation.tcl and then execute it using NS2 with the following command:

ns distance_routing_simulation.tcl

  1. Visualize the Simulation Using NAM

We need to open the generated .nam file to envision the network topology and monitor how packets are routed according to the distance:

nam distance_routing_simulation.nam

  1. Analyze the Trace File

The trace file (distance_routing_trace.tr) will include details of packet transmissions and the routing decisions. We can examine:

  • The paths taken by the packets rely on the distance.
  • Packet delivery ratio.
  • End-to-end delay and throughput.
  1. Modify the Simulation
  • Link Costs: Alter the delays (representing cost or distance) on the links to monitor how the routing protocol modifies the paths depend on the new distances.
  • Traffic Sources: Insert more traffic sources to observe how distance-based routing manages several flows.
  • Node Mobility: If utilizing a wireless network then we can be replicated node mobility and monitor how the routing algorithm adjusts.

Optional Enhancements:

  • Link Failures: Launch link failures in the course of the simulation to check how the distance-based routing protocol reacts and recalculates the routes.
  • Comparison: Replicate other distance-based routing protocols like OSPF (Link State Routing) and relate the performance with Distance Vector Routing.
  • Energy-Aware Distance Routing: In wireless networks, replicate the distance routing, which gets energy consumption into account for routing decisions.

In this demonstration, we thoroughly known on how to simulate and find out the Distance Routing projects over the NS2 analysis tool. If you did like to know more details about this process, we will share it too.

We’re here to help you with the Distance Vector Routing protocol for your project. If you need assistance with any Distance Routing simulations, just send us your project details, and we’ll deliver the best results. For in-depth network analysis, check out phdprime.com, where we provide thorough explanations.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2