To simulate Dynamic Source Routing (DSR) projects using NS2, we can use the built-in DSR protocol, which comes with NS2. DSR is a reactive routing protocol generally utilized within mobile ad hoc networks (MANETs). It permits nodes to dynamically find routes to a destination and uses source routing in which the sender find out the whole path the packet will take. Drop a message to phdprime.com we are glad to guide you with best outcome at each and every stap of your project.
Here’s a series of simulation steps to replicating DSR in NS2.
Steps to Simulate DSR Routing in NS2
- Install NS2
Make certain that NS2 is installed on the machine. If we haven’t installed it yet, we can download it from the NS2 Official Website and then follow the installation steps for the operating system.
- Create a TCL Script for DSR Routing
The simulation platform NS2 has built-in support for the DSR protocol, thus we can directly allow it in the simulation. The following script configures a basic wireless network with DSR as the routing protocol.
Example TCL Script for DSR Routing Simulation:
# Create a simulator object
set ns [new Simulator]
# Define trace and NAM files for analysis and visualization
set tracefile [open “dsr_trace.tr” w]
set namfile [open “dsr_simulation.nam” w]
$ns trace-all $tracefile
$ns namtrace-all $namfile
# Define a topography for the wireless network
set topo [new Topography]
$topo load_flatgrid 500 500
# Configure the wireless nodes with DSR as the routing protocol
create-god 10 ;# Number of nodes
$ns node-config -adhocRouting DSR \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF
# Create nodes and assign them random positions
for {set i 0} {$i < 10} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0 ;# Disable random mobility
}
# Optionally, you can manually set node positions
$node_(0) set X_ 50
$node_(0) set Y_ 50
$node_(1) set X_ 100
$node_(1) set Y_ 150
# Continue setting positions for other nodes…
# Create UDP agents for sending and receiving traffic
set udp0 [new Agent/UDP]
set udp1 [new Agent/UDP]
# Attach UDP agents to the source and destination nodes
$ns attach-agent $node_(0) $udp0
$ns attach-agent $node_(9) $udp1
# Define a Constant Bit Rate (CBR) traffic generator
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set rate_ 1Mb
$cbr0 attach-agent $udp0
# 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”
# Set up 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
- Run the Simulation
We can save the script as dsr_simulation.tcl and then execute it in NS2:
ns dsr_simulation.tcl
- Visualize the Simulation Using NAM
We can open the .nam file in the Network Animator (NAM) to envision the DSR-based packet transmissions:
nam dsr_simulation.nam
- Analyze the Trace File
The trace file (dsr_trace.tr) will include details regarding the packet exchanges, route discovery, and route maintenance processes in DSR. We can examine:
- Route discovery and route caching.
- Packet delivery ratio.
- End-to-end delay and throughput.
- Modify the Simulation
- Node Mobility: Allow node mobility to replicate dynamic networks and monitor how DSR manages route discoveries when nodes move.
- Multiple Traffic Flows: Insert more traffic sources and destinations to replicate several data flows in the network.
- Scalability: Maximizes the number of nodes to check DSR’s performance in larger networks.
Optional Enhancements:
- Performance Metrics: Assess the performance parameters such as routing overhead, end-to-end delay, and packet delivery ratio under diverse network conditions.
- Failure Handling: Replicate node or link failures and monitor how DSR retrieves routes.
- Comparison with Other Protocols: Mimic protocols such as AODV or DSDV and compare their performance versus DSR.
The above are the entire procedures, which will help you to replicate and analyse the Dynamic Source Routing (DSR) routing projects within NS2 tool that has includes the simulation process and core concepts. Further details regarding these projects will be shared if needed.