To simulate reactive routing protocols in NS2 has needs to follow series of steps that usually concentrate on protocols like Ad-hoc On-Demand Distance Vector (AODV), Dynamic Source Routing (DSR), and Temporally Ordered Routing Algorithm (TORA). These protocols are termed reactive as they explore routes only when required, unlike proactive protocols that sustain routes all the time.
Here’s a step-by-step guide to simulate reactive routing protocols using NS2.
Steps to Simulate Reactive Protocol Projects in NS2
- Install NS2
Make sure that NS2 is installed. If not, download it from the NS2 website and follow the installation instructions.
- Understanding Reactive Protocols
- AODV: Discovers routes on-demand and sustains them only as long as required.
- DSR: Utilizes source routing in which the complete route to the destination is contained in the packet header.
- TORA: A distributed technique based on link reversal to identify routes reactively.
- Simulating AODV in NS2
Below is an instance of a simulation script for AODV:
# Create a new simulator instance
set ns [new Simulator]
# Define trace and nam files for logging and visualization
set tracefile [open aodv_reactive.tr w]
$ns trace-all $tracefile
set namfile [open aodv_reactive.nam w]
$ns namtrace-all $namfile
# Set up nodes
for {set i 0} {$i < 10} {incr i} {
set n($i) [$ns node]
}
# Configure routing protocol to AODV (reactive protocol)
$ns node-config -adhocRouting AODV
# Configure wireless channel parameters
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
# Configure links between nodes
for {set i 0} {$i < 9} {incr i} {
$ns duplex-link $n($i) $n([expr $i + 1]) 2Mb 10ms DropTail
}
# Traffic: TCP communication
set tcp0 [new Agent/TCP]
set sink0 [new Agent/TCPSink]
$ns attach-agent $n(0) $tcp0
$ns attach-agent $n(9) $sink0
$ns connect $tcp0 $sink0
# Start traffic generation
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 2.0 “$ftp0 start”
# Stop the simulation at 50 seconds
$ns at 50.0 “finish”
# Run the simulation
$ns run
- Simulating DSR in NS2
For DSR, we simply required to change the routing protocol configuration to DSR.
# Configure routing protocol to DSR (Dynamic Source Routing)
$ns node-config -adhocRouting DSR
The rest of the script remains largely the same. DSR operate by discovering the full path from source to destination and storing it in the packet header.
- Simulating TORA in NS2
If we need to replicate TORA, follow the same steps however set up the protocol to TORA.
# Configure routing protocol to TORA (Temporally Ordered Routing Algorithm)
$ns node-config -adhocRouting TORA
Make sure that version of NS2 has TORA has involves (NS-2.35 has support for TORA by default).
- Define Traffic Sources (TCP/UDP)
We can describe both TCP and UDP traffic in network. For instance, to create CBR (Constant Bit Rate) traffic over UDP:
# Set up UDP communication
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(9) $null0
# Connect UDP to Null Agent
$ns connect $udp0 $null0
# Generate CBR traffic over UDP
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set rate_ 100kb
$cbr0 attach-agent $udp0
$ns at 1.0 “$cbr0 start”
- Add Node Mobility (Optional)
Reactive protocols are especially appropriated for networks with mobile nodes. We can incorporate mobility to replicate nodes moving via a given area:
# Define mobility for nodes
for {set i 0} {$i < 10} {incr i} {
set n($i) [$ns node]
$n($i) random-motion 1
}
# Move node n0 to a new destination at speed 10 m/s
$ns at 5.0 “$n(0) setdest 200 300 10.0”
- Run the Simulation
Once the TCL script is ready, execute it in NS2:
ns reactive_protocol.tcl
This will create a trace file (.tr) and a NAM file (.nam) that we can visualize using the NAM (Network Animator) tool.
- Analyse the Simulation Results
We can evaluate key parameters like:
- Packet Delivery Ratio (PDR)
- End-to-End Delay
- Routing Overhead
- Throughput
We can utilize AWK scripts or Python to measure the trace file. Here’s an instance AWK script to estimate the Packet Delivery Ratio (PDR):
BEGIN { sent = 0; received = 0; }
{
if ($1 == “s” && $4 == “AGT”) { sent++; }
if ($1 == “r” && $4 == “AGT”) { received++; }
}
END { print “Packet Delivery Ratio = “, received/sent*100, “%”; }
- Example Project Ideas Using Reactive Protocols
- Comparison of AODV and DSR:
- Relate the performance of AODV and DSR based on packet delivery ratio, end-to-end delay, and routing overhead.
- Impact of Node Mobility on TORA:
- Measure the effect of node speed and mobility on TORA’s performance in a dynamic scenario.
- Energy-Efficient Routing Using AODV:
- Adapt AODV to includes energy parameter and measure its performance in a mobile network with limited battery resources.
- Scalability of Reactive Protocols:
- Measure how reactive protocols such as AODV and DSR scale in large networks with changing node densities.
In this simulation setup, we have been clearly understood the concepts and learn the essential procedures to simulate the reactive routing protocols project that has contain the installation procedures and generating the network topology and then visualized the outcomes through ns2 analysis too. Further details will be provided later.
Share the details of your Reactive Protocol Projects with us. We will provide you with excellent simulation support and great research ideas and project topics. If you need top-notch guidance on protocols such as Ad-hoc On-Demand Distance Vector (AODV), Dynamic Source Routing (DSR), and Temporally Ordered Routing Algorithm (TORA), phdprime.com is here to help you.