How to Implement on Wireless Routing Protocol in NS2

To implement a wireless routing protocol in Network Simulator 2 (NS2) has needs to setup the network simulation to utilize the one of the wireless ad hoc routing protocols accessible in NS2, like an Ad hoc On-Demand Distance Vector (AODV), Dynamic Source Routing (DSR), or Destination-Sequenced Distance Vector (DSDV) and these protocols are often utilized in wireless ad hoc networks, in which the each node can act as a router. The given below are the steps to execute the wireless routing protocol in NS2:

Step-by-Step Implementation:

Step 1: Install NS2

Make sure that NS2 is installed on the system.

Step 2: Choose a Wireless Routing Protocol

NS2 supports numerous wireless routing protocols that involve:

  • AODV (Ad hoc On-Demand Distance Vector)
  • DSR (Dynamic Source Routing)
  • DSDV (Destination-Sequenced Distance Vector)

Select the protocol that we want to simulate.

Step 3: Create a Simulation Script

Generate a Tcl script to setup the network and emulate wireless routing using the selected protocol.

Example: Implementing AODV in NS2

  1. Create a new Tcl script: Open a text editor and make a new file, for instance, wireless_routing_example.tcl.
  2. Set up the simulation environment: Describe the simulator, configure the network topology, and setup the parameters specific to 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)   10.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

$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

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

$node_($i) random-motion 0

}

# Define node movement (Optional for mobile nodes)

$node_(0) set X_ 50.0

$node_(0) set Y_ 50.0

$node_(0) set Z_ 0.0

$node_(1) set X_ 150.0

$node_(1) set Y_ 100.0

$node_(1) set Z_ 0.0

# (Add more movement patterns or use mobility models if needed)

  1. Setup traffic sources:

# Setup a UDP agent and attach it to node 0

set udp [new Agent/UDP]

$ns attach-agent $node_(0) $udp

# Setup CBR (Constant Bit Rate) 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 node 1

set null [new Agent/Null]

$ns attach-agent $node_(1) $null

# Connect the agents

$ns connect $udp $null

  1. Setup 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

Example: Implementing DSR in NS2

If we need to use DSR as an alternative of AODV, we can simply change the routing protocol setting:

set val(rp)     DSR  ;# Use DSR as the routing protocol

Example: Implementing DSDV in NS2

For DSDV, we would configure it similarly:

set val(rp)     DSDV ;# Use DSDV as the routing protocol

Step 4: Run the Simulation

  1. Save the Tcl script (wireless_routing_example.tcl or desired protocol script).
  2. Open a terminal and navigate to the directory in which we saved the Tcl script.
  3. Execute the simulation using the following command:

ns wireless_routing_example.tcl

This command will make a trace files and optionally a network animation file (if enabled in script).

Step 5: Analyse the Results

Use trace files and the network animator (NAM) to evaluate the performance of the wireless routing protocol that concentrates on the parameters like route discovery time, packet delivery ratio, and network overhead.

Step 6: Visualize the Results (Optional)

If we have permitted the network animator (NAM) in the script, we can visualize the simulation:

nam wireless_routing_example.nam

This will open the NAM window, in which we can see the network topology and the features of the wireless routing protocol during the simulation.

Additional Considerations

  • Mobility: Validate the protocol in numerous mobility scenarios to see how it manage dynamic topologies.
  • Network Size: changing the number of nodes to monitor on how the protocol scales.
  • Traffic Patterns: Test with diverse traffic patterns like CBR, FTP, and TCP to see how the protocol performs in diverse conditions.
  • Performance Metrics: Evaluate and compare the performance of diverse wireless routing protocols in terms of delay, packet delivery ratio, routing overhead, and energy usage.

In this module, we had clearly understood the implementation procedures, sample snippets were given to enforce the wireless routing protocol with the help of ns2 tool. We also deliver further significant information regarding the wireless routing protocol will be provided.

Looking for the most effective Wireless Routing Protocol in NS2, we are here to assist you with implementation results tailored to your needs. Reach out to us for personalized services. Explore innovative research ideas on Ad hoc On-Demand Distance Vector (AODV), Dynamic Source Routing (DSR), or Destination-Sequenced Distance Vector (DSDV) at ns2project.com, so stay connected with us for optimal outcomes