How to Implement Distributed Routing in NS2
To implement the Distributed Routing in Network Simulator 2 (ns2), we have to support distributed routing mechanisms by simulating routing protocol. It means that every node in the network individualistically makes routing decisions according to their local information. The protocols which are often used the distributed routing in NS2 includes Distance Vector (DV) protocols like AODV (Ad-hoc On-demand Distance Vector) or Link State protocols like OLSR (Optimized Link State Routing). Refer the following approach to know about the implementation process of distributed routing in ns2:
Steps to Implement Distributed Routing in NS2:
- Use a Distributed Routing Protocol
You can simulate distributed routing by using a protocol like AODV, DSDV, or DSR. These protocols inherently work in a distributed manner, where nodes find routes dynamically based on local information or by interacting with neighbouring nodes.
Example: Implementing Distributed Routing Using AODV in NS2
Use AODV to replicate the distributed routing using AODV, which is a commonly used distributed routing protocol in ad-hoc networks.
TCL Script for AODV-based Distributed Routing:
# Create the simulator object
set ns [new Simulator]
# Open a trace file to record the simulation
set tracefile [open distributed_trace.tr w]
$ns trace-all $tracefile
# Open a nam file for network animation
set namfile [open distributed_routing.nam w]
$ns namtrace-all $namfile
# Define the finish procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam distributed_routing.nam &
exit 0
}
# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Create links between the nodes (distributed routing decision will occur)
$ns duplex-link $n0 $n1 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2Mb 10ms DropTail
$ns duplex-link $n3 $n4 2Mb 10ms DropTail
$ns duplex-link $n0 $n4 2Mb 20ms DropTail ;# Alternative link with higher delay
# Setup AODV as the distributed routing protocol
set opt(adhocRouting) AODV
# Create traffic: UDP agents
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null0 [new Agent/Null]
$ns attach-agent $n4 $null0
# Connect the UDP agents
$ns connect $udp0 $null0
# Create CBR traffic source
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.1
$cbr0 attach-agent $udp0
# Schedule the traffic start and stop
$ns at 1.0 “$cbr0 start”
$ns at 5.0 “$cbr0 stop”
# Schedule the end of the simulation
$ns at 10.0 “finish”
# Run the simulation
$ns run
- Explanation of the Script:
- Nodes and Links: The script creates five nodes (n0 to n4) and launches duplex links amongst them. One link (n0 to n4) has a higher delay (20ms) to explain how the distributed routing algorithm picks the lower-cost path.
- Routing Protocol: The AODV protocol is used to replicate distributed routing. In AODV, each node dynamically finds the best route based on local information and route requests propagated over the network.
- Traffic Setup: A UDP agent is included to node n0 as the source, and a Null agent is attached to node n4 as the sink. CBR traffic is designed to deliver data packets from n0 to n4.
- Running the Simulation:
- Store the script as distributed_routing.tcl.
- Execute the script using the following command:
ns distributed_routing.tcl
This will produce a trace file (distributed_trace.tr) and a NAM file (distributed_routing.nam) for visualization. Visualize the simulation by opening the NAM file using the below command:
nam distributed_routing.nam
- Distributed Routing Mechanism:
- In distributed routing, every node makes routing decisions according to the local information. For AODV:
- Route Discovery: A node begins a route discovery process by broadcasting a Route Request (RREQ) when it required to send a packet to a destination for which it doesn’t have a route.
- Route Reply: The destination or intermediate node with a valid route to the destination replies with a Route Reply (RREP).
- Route Maintenance: Nodes continuously observe the link status of active routes and alert the network when a link failure is identified.
- Using Other Distributed Routing Protocols
You can execute other distributed routing protocols includes DSDV (Distance-Vector), OLSR (Optimized Link State Routing), or DSR (Dynamic Source Routing) in NS2 by altering the routing option in the script:
- For DSDV:
set opt(adhocRouting) DSDV
- For DSR:
set opt(adhocRouting) DSR
- For OLSR:
set opt(adhocRouting) OLSR
- Trace File Analysis
Aggregate the metrics by assessing the created trace file (distributed_trace.tr), after executing the simulation such as:
- Packet Delivery Ratio
- End-to-End Delay
- Routing Overhead
This can be complete using awk or custom scripts for post-simulation analysis.
Overall, we have seen how the distributed routing is implemented and work in ns2 environment through this manual and how to execute the distributed algorithm to establish it. We also provided the AODV-based routing with examples. If needed, we will clarify the doubts whenever it rises.
Connect with ns2project.com, where we stand poised to deliver unparalleled implementation of Distributed Routing in NS2. We also offer a curated selection of exceptional thesis ideas and topics, meticulously designed to align with your project aspirations. Our commitment to timely execution ensures that you receive nothing short of outstanding results.