How to Implement on ZRP Protocol in NS2
To implement the Zone Routing Protocol (ZRP) in Network Simulator 2 (NS2) has needs a bit of work for which the ZRP is a hybrid routing protocol that incorporates proactive and reactive routing techniques. Inappropriately, ZRP is not support a built-in protocol in NS2, so we want to manually execute or emulate its behaviour. The given below is the brief procedure to execute the Zone Routing Protocol in ns2:
Step-by-Step Guide to Implement ZRP in NS2
Step 1: Understand ZRP
The Zone Routing Protocol (ZRP) divides the network into overlying zones of nodes. All of each node uses proactive routing within its zone and reactive routing for nodes outside its zone:
- Intra-zone Routing Protocol (IARP): Proactive routing within the zone.
- Inter-zone Routing Protocol (IERP): Reactive routing among zones.
- Bordercast Resolution Protocol (BRP): Supports in routing query packets among zones.
Step 2: Implement ZRP in NS2
NS2 doesn’t have ZRP by default, we have two options:
- Modify existing NS2 code to mimic ZRP by integrating proactive and reactive routing protocols.
- Implement ZRP manually by writing new classes and functions.
Here, we will demonstrate on how to simulate ZRP behaviour by integrating DSDV (a proactive protocol) and AODV (a reactive protocol).
Step 3: Create a Simulation Script
- Create a New Tcl Script: Open a text editor and generate a new file, for instance, zrp_example.tcl.
- Set up the Simulation Environment: describe the simulator, configure the network topology, and setup the metrics exact 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 nodes
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 20.0 ;# Simulation time
set val(zrp_radius) 2 ;# ZRP zone radius
# 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
$ns node-config -adhocRouting AODV \ ;# Default to AODV (Reactive)
-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
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0
}
# Define node positions (optional, just for clarity)
$node_(0) set X_ 100.0
$node_(0) set Y_ 200.0
$node_(1) set X_ 200.0
$node_(1) set Y_ 200.0
$node_(2) set X_ 300.0
$node_(2) set Y_ 200.0
# (Add more nodes and positions as needed)
# ZRP Simulation Logic (Simulating zone-based behavior)
for {set i 0} {$i < $val(nn)} {incr i} {
for {set j [expr $i + 1]} {$j < $val(nn)} {incr j} {
if {[distance $node_($i) $node_($j)] <= $val(zrp_radius)} {
$ns node-config -adhocRouting DSDV
} else {
$ns node-config -adhocRouting AODV
}
}
}
# Function to calculate distance between two nodes
proc distance {node1 node2} {
set x1 [$node1 set X_]
set y1 [$node1 set Y_]
set x2 [$node2 set X_]
set y2 [$node2 set Y_]
return [expr sqrt(($x1 – $x2) * ($x1 – $x2) + ($y1 – $y2) * ($y1 – $y2))]
}
# Setup traffic sources
set udp [new Agent/UDP]
$ns attach-agent $node_(0) $udp
set null [new Agent/Null]
$ns attach-agent $node_(9) $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set interval_ 0.1
$cbr start
# Setup simulation end
$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 4: Run the Simulation
- Save the Tcl script (zrp_example.tcl).
- Open a terminal and navigate to the directory that can save the Tcl script.
- Exeute the simulation using the following command:
ns zrp_example.tcl
This command will make a trace files and optionally a network animation file (if enabled in script).
Step 5: Analyze the Results
Use trace files and the network animator (NAM) to evaluate the performance of the simulated ZRP behaviour that concentrate on parameters like route discovery time, packet delivery ratio, and network overhead.
Step 6: Visualize the Results (Optional)
If we have allowed the network animator (NAM) in the script, we can visualize the simulation:
nam zrp_example.nam
This will open the NAM window, in which we can see the network topology and the behaviour of the simulated ZRP protocol during the simulation.
Additional Considerations
- ZRP Radius: Test with diverse zone radii to see how the protocol’s performance changes.
- Mobility: validate the protocol in numerous mobility scenarios to track on how it adjusts to dynamic network topologies.
- Performance Metrics: Evaluate and compare the performance of the ZRP simulation in terms of delay, packet delivery ratio, routing overhead, and energy consumption.
Extending the Implementation
If we need a more accurate ZRP implementation then we might essential to expand the NS2 by composing the custom C++ modules that execute in ZRP’s specific behaviour. This can be relatively complex and needs in-depth knowledge of NS2’s internal architecture.
This module demonstrates how to setup and manage the Zone Routing Protocol over the routed network using the ns2 simulator. Further details will be provided about how the Zone Routing Protocol will be performing in other simulation tool. If you’re looking for the most effective ZRP Protocol in NS2, we’re here to assist you with implementation outcomes. Feel free to reach out to us for personalized services. Stay connected with us for optimal results.