How to Implement on Reactive Protocol in NS2
To implement a reactive routing protocol in Network Simulator 2 (NS2) has numerous steps that contain to setting up the network simulation to utilize a protocol that determines routes only while they are essential. The Reactive protocols, like an Ad hoc On-Demand Distance Vector (AODV) and Dynamic Source Routing (DSR), are often used in mobile ad hoc networks (MANETs) in which the network topology commonly changes. For best implementation results you can approach us, we give you tailored services. The given below is the implementation procedure for reactive routing protocol, like AODV, in NS2:
Step-by-Step Implementation:
Step 1: Install NS2
Make sure NS2 is installed on the system.
Step 2: Create a Simulation Script
Generate a Tcl script to setup network and mimic routing using the chosen reactive protocol.
Example: Implementing AODV in NS2
- Create a New Tcl Script: Open a text editor and create a new file, for instance, reactive_aodv_example.tcl.
- Set Up the Simulation Environment: Describe the simulator, configure the network topology, and setup the metric specific to the simulation.
# Create a simulator object
set ns [new Simulator]
# Define options for the simulation
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 type
set val(ifq) Queue/DropTail/PriQueue ;# Interface Queue type
set val(ll) LL ;# Link layer type
set val(ant) Antenna/OmniAntenna ;# Antenna type
set val(ifqlen) 50 ;# Max packet in ifq
set val(nn) 10 ;# Number of mobile nodes
set val(rp) AODV ;# Routing Protocol (AODV)
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 100.0 ;# Simulation time
# Initialize the topology object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create the God object
create-god $val(nn)
# Configure the nodes (mobile nodes)
$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 \
-movementTrace ON
# Create nodes (mobile nodes)
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
}
# Define node positions and movement (optional for mobile nodes)
$node_(0) set X_ 50.0
$node_(0) set Y_ 100.0
$node_(1) set X_ 150.0
$node_(1) set Y_ 200.0
$node_(2) set X_ 250.0
$node_(2) set Y_ 300.0
# Set node mobility (random waypoint mobility model)
$ns at 0.0 “$node_(0) setdest 300 300 10”
$ns at 5.0 “$node_(1) setdest 100 100 15”
$ns at 10.0 “$node_(2) setdest 200 200 5”
Step 3: Set Up Traffic Sources
Configure the communication among nodes using UDP and CBR (Constant Bit Rate) traffic.
# Setup a UDP agent and attach it to the first node
set udp [new Agent/UDP]
$ns attach-agent $node_(0) $udp
# Setup a CBR application to generate traffic
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set interval_ 0.1
$cbr start
# Setup a Null agent (sink) on another node
set null [new Agent/Null]
$ns attach-agent $node_(9) $null
# Connect the agents (Node 0 sends data to Node 9)
$ns connect $udp $null
Step 4: Define Simulation End
# Define simulation end time
$ns at $val(stop) “stop”
$ns at $val(stop) “$ns nam-end-wireless $val(stop)”
$ns at $val(stop) “exit 0”
proc stop {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
}
# Run the simulation
$ns run
Step 5: Run the Simulation
- Save the Tcl script (reactive_aodv_example.tcl).
- Open a terminal and navigate to the directory in which we saved the Tcl script.
- Execute the simulation using the following command:
ns reactive_aodv_example.tcl
This command will make trace files and optionally a network animation file (if enabled in script).
Step 6: Analyse the Results
Use trace files and the network animator (NAM) to evaluate the performance of the AODV protocol that concentrates on parameters like route discovery time, packet delivery ratio, end-to-end delay, and network overhead.
Step 7: Visualize the Results (Optional)
If we have allowed the network animator (NAM) in script, we can visualize the simulation:
nam reactive_aodv_example.nam
This will generate the NAM window, in which we can see the network topology and the behaviour of the AODV protocol during the simulation.
Additional Considerations
- Mobility Models: Validate with diverse mobility models to denote more realistic node movements.
- Protocol Selection: Moreover AODV, we can mimic other reactive protocols such as DSR by simply varying the rp variable:
set val(rp) DSR
- Performance Metrics: Evaluate and relate the performance of diverse reactive protocols in terms of delay, packet delivery ratio, routing overhead, and scalability.
In this manual, we entirely see how to implement the simple setup simulation and to know how to execute the reactive routing protocol in ns2 simulator tool. If you have any query regarding this process we also help to clarify it.