To simulate the Dynamic Source Routing (DSR) protocol in NS2 is comparatively straightforward because NS2 already has built-in support for DSR, a conspicuous routing protocol for Mobile Ad-hoc Networks (MANETs). The DSR is an on-demand routing protocol which utilized for source routing, in which the complete route to the destination is kept in the packet’s header. Nodes explore the routes only when required, and once a route is establish, it is cached for upcoming use.
Here’s a step-by-step guide to simulate DSR protocol projects using NS2.
Steps to Simulate DSR Protocol in NS2
- Install NS2:
- Make sure that NS2 is installed appropriately on system. NS2 comes with built-in support for DSR, so no additional modules or patches are required.
- Define the Network Topology:
- Describe a simple network topology with mobile nodes that will contribute in the DSR-based communication. In a MANET environment, nodes are usually mobile and communicate without any fixed infrastructure.
Example of a Simple Network Topology:
# Create a simulator object
set ns [new Simulator]
# Open a trace file to log the simulation
set tracefile [open dsr.tr w]
$ns trace-all $tracefile
# Open a NAM file to visualize the simulation
set namfile [open dsr.nam w]
$ns namtrace-all $namfile
# Define topography for nodes (500×500 area)
set topo [new Topography]
$topo load_flatgrid 500 500
# Define the type of mobile nodes and setup channel properties
set val(chan) Channel/WirelessChannel ;# Channel type
set val(prop) Propagation/TwoRayGround ;# Propagation model
set val(netif) Phy/WirelessPhy ;# Network interface type
set val(mac) Mac/802_11 ;# MAC layer protocol
set val(ifq) Queue/DropTail/PriQueue ;# Interface queue
set val(ll) LL ;# Link layer
set val(ant) Antenna/OmniAntenna ;# Antenna model
set val(ifqlen) 50 ;# Interface queue length
set val(rp) DSR ;# Routing protocol (DSR)
# Node configuration for MANET using DSR
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON
- Create Mobile Nodes:
- Generate the mobile nodes that will share in the DSR network. Describe their initial positions and movement patterns.
Example of Creating Nodes:
set n0 [$ns node] ;# Node 0
set n1 [$ns node] ;# Node 1
set n2 [$ns node] ;# Node 2
set n3 [$ns node] ;# Node 3
- Set Mobility for Nodes:
- Describe the mobility pattern for each node. We can utilize a predefined mobility model such as random waypoint model, random walk model or set certain movements for each node.
Example of Setting Node Mobility:
# Initial position of nodes
$n0 set X_ 100
$n0 set Y_ 100
$n0 set Z_ 0.0
$n1 set X_ 150
$n1 set Y_ 200
$n1 set Z_ 0.0
$n2 set X_ 200
$n2 set Y_ 300
$n2 set Z_ 0.0
$n3 set X_ 250
$n3 set Y_ 400
$n3 set Z_ 0.0
# Define node movements (speed, direction, and timing)
$ns at 10.0 “$n0 setdest 300 400 10”
$ns at 15.0 “$n1 setdest 250 350 10”
$ns at 20.0 “$n2 setdest 200 300 15”
$ns at 25.0 “$n3 setdest 150 250 12”
- Set Traffic Patterns:
- Configure the traffic among the nodes. This can be completed by using CBR (Constant Bit Rate) or FTP over TCP traffic sources. In the DSR simulation, traffic can initiate among any pair of nodes once routes are introduced.
Example: Defining Traffic Pattern (CBR over UDP):
# Create a UDP agent and attach it to node 0 (source)
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a Null agent and attach it to node 3 (destination)
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
# Connect the UDP agent on node 0 to the Null agent on node 3
$ns connect $udp0 $null0
# Create a CBR traffic source and attach it to the UDP agent
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.2
$cbr0 attach-agent $udp0
# Start CBR traffic at 1 second
$ns at 1.0 “$cbr0 start”
- Set Simulation Time and End Conditions:
- Set the simulation end time and describe a finish procedure to close the trace files and terminate the simulation.
Example: Setting Simulation Time and Finishing:
# Set the simulation end time to 50 seconds
$ns at 50.0 “finish”
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam dsr.nam &
exit 0
}
# Run the simulation
$ns run
- Run the Simulation:
- Once the script is configured, execute the simulation. The simulation will log events such as route requests, route replies, and packet forwarding in the trace file. We can also visualize node movements and packet transmissions in NAM (Network Animator).
- Analyse the Trace File:
- After the simulation is done, evaluate the trace file (dsr.tr) for performance metrics like:
- Packet Delivery Ratio (PDR)
- End-to-End Delay
- Routing Overhead
- Route Discovery Time
- After the simulation is done, evaluate the trace file (dsr.tr) for performance metrics like:
Example: Analysing Packet Delivery Ratio:
awk ‘{
if($1 == “s”) { sent++ }
if($1 == “r”) { received++ }
} END { printf(“Packet Delivery Ratio: %.2f%\n”, (received/sent)*100) }’ dsr.tr
Advanced Simulation Ideas for DSR Projects
- Node Mobility and Scalability:
- Learn on how DSR performs in different node mobility patterns and speeds. We can replicate larger networks with changing node densities to measure on how scalability impacts the routing performance.
- Traffic Load Variations:
- Replicate different traffic loads such as changing packet sizes, multiple traffic flows, high and low traffic rates to track the impact on DSR’s route discovery and maintenance performance.
- Energy-aware Routing:
- Execute an energy model for nodes to learn on how energy consumption impacts the DSR protocol’s performance and relate it to energy-aware routing protocols.
- Security Enhancements:
- Replicate potential attacks on the DSR protocol, like wormhole attacks, blackhole attacks, or route tampering, and measure their impacts on the network performance.
- Route Recovery Mechanisms:
- Execute and evaluate the performance of route recovery mechanisms when link failures or node failures happens. Measure the time DSR takes to recover and introduce new routes.
- Comparison with Other Protocols:
- Relate the performance of DSR with other routing protocols such as AODV, OLSR, and DSDV based on the parameters such as packet delivery ratio, end-to-end delay, routing overhead, and route discovery time.
Metrics for DSR Performance Evaluation
- Packet Delivery Ratio (PDR): The ratio of packets successfully delivered to the destination to the total number of packets transmits by the source.
- End-to-End Delay: The average time taken for a data packet to travel from the source to the destination.
- Routing Overhead: The number of control traffic like route requests, route replies, and route errors created by the protocol.
- Route Discovery Time: The time it takes to explore a route from the source to the destination when required.
In this simulation setup, we offered the simple approaches that were demonstrated using the sample code snippets related to the Dynamic Source Routing project which were simulated and evaluated through ns2 tool. Some specific details regarding this process will be provided later.
Contact us to explore engaging DSR Protocol project topics and ideas designed for your requirements. Our team specializes in on-demand routing protocols, so reach out for the best outcomes. You can always rely on us for top-notch guidance on DSR Protocol project simulations. At phdprime.com, we offer personalized support to address your unique needs.