How to Implement AODV Protocol in NS2

 

To implement the AODV (Ad hoc On-Demand Distance Vector) protocol within NS2 (Network Simulator 2) that has needs to encompass making a simulation script that set up the network to use AODV as the routing protocol. Similar DSR, AODV is also pre-implemented in NS2, thus we don’t want to execute the protocol from scratch. Instead, we will set up a simulation scenario using the protocol AODV.

Step-by-Step Implementation:

Step 1: Install NS2

Make sure that have NS2 installed on the system. We can download it from the NS2 web page and pursue the installation instructions.

Step 2: Create an AODV Simulation Script

  1. Create a new Tcl script: Open a text editor and make a new file, for instance, aodv_example.tcl.
  2. Set up the simulation environment: Starting by describing the simulator, setting up the network topology, and set up the metrics particular 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

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

  1. Create nodes and define mobility:

# Create mobile nodes

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

set node_($i) [$ns node]

$node_($i) random-motion 1

}

# Define node movement

$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 movement patterns or use mobility models as needed)

  1. Setup traffic sources:

# Create a TCP agent and attach it to node 0

set tcp [new Agent/TCP]

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

set sink [new Agent/TCPSink]

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

$ns connect $tcp $sink

# Create a FTP application and attach it to TCP agent

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set type_ FTP

$ftp start

  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

Step 3: Run the Simulation

  1. We can save the Tcl script like aodv_example.tcl.
  2. Open a terminal and navigate to the directory in which we can be saved the Tcl script.
  3. Run the simulation using the below command:

ns aodv_example.tcl

This will produce trace files and optionally a network animation file if permitted in the script.

Step 4: Analyse the Results

We can use tools such as awk, perl, or other scripting languages to process the trace files generated by NS2 to consider the performance of the AODV protocol.

Step 5: Visualize the Results (Optional)

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

nam aodv_example.nam

It will open the NAM window in which we can observe the network topology and the behaviour of AODV while the simulation.

Additional Tips:

  • Modify the number of nodes, simulation time, and other parameters to analyse the AODV under various scenarios.
  • Investigate NS2’s AODV execution details if we need to know the internal workings of the protocol. The source code is obtainable in the aodv directory in the NS2 installation.

Overall, we have given an outline about the AODV protocol that were executed and analysed in ns2. If you want more informations regarding this protocol we will be provided. Receive customized assistance from our team for the implementation of the AODV Protocol in NS2. We will provide guidance at every stage of the process, and you can find excellent project topics at ns2project.com.