AODV Routing Protocol Network Simulation

Abhinav Dubey
Nerd For Tech
Published in
4 min readJul 27, 2021

--

Ad-hoc On-demand Distance Vector Routing Protocol is used for mobile or wireless ad-hoc networks (MANETs or WANETs). An ad-hoc network is a temporary distributed network that is built by two or more nodes, to transfer packets without requiring typical infrastructures such as routers and access points. Nodes in the ad-hoc network follow a peer-to-peer network (P2P). The AODV protocol was developed by joint efforts of the Nokia Research Center, University of California, and the University of Cincinnati.

Made by me ^u^

There are various simulators that can be used to simulate network protocols such as NS2, NS3, OMNeT++, NetSim. Here I am using NS2, an open-source event-driven simulator. NS2 is written in C++ and Otcl, and the simulation has to be written in TCL Script. NS2 is a really old simulator, began as a revision of NS-1 in 1995. Though I am using version 2.35 which was released in 2011 on Ubuntu 20.04.1, and it works really fine, So no worries there :)

NS2 executes the TCL script and generates a trace file and a network animator file. The trace file is used for the analysis of the simulation like throughput, energy consumption. The network animator file is executed by Nam (version 1.15) which produces the simulation as an animation.

Nodes discover routes using defined messages by AODV, which are Route Requests - RREQ, Route Reply - RREP, Route Error - RERR. Originating node broadcasts RREQ messages to all its neighbors, nodes that have a route to the destination node broadcasts RREP message along the reverse route to the originating node. In case, the neighboring node to originating node does not have a route to the destination, it, in turn, broadcasts RREQ messages keeping a reverse route to the originating node. If a node loses connection to its next-hop node destination, it broadcasts RERR messages to all nodes which received RREP messages.

Routing Table Entries maintained by AODV

  • Destination IP Address
  • Destination Sequence Number
  • Valid Destination Sequence number flag
  • Other state and routing flags
  • Network Interface
  • Hop Count
  • Next Hop
  • List of Precursors
  • Lifetime

Implementing the Simulation

First of all set up some variables, which will be used later on for node configuration. val here is an array with non-number indices. val(stop) is the end time of the simulation. val(x), val(y) will be used to define topography. val(nn) denotes no. of nodes used. val(rp) contains the type of routing protocol, which is AODV in this case.

val(ifq) is the interface queue that gives priority to routing protocol packets and val(ifqlen) is the max length of the queue. val(ant) defines antenna type as Omni-direction which means it can receive and transmit in all directions. var(prop) is set as TwoRayGround which is the attenuation model during radio propagation (1/r⁴). val(netif) contains value for network interface. The Network Interface layer serves as a hardware interface that is used by the mobile node to access the channel and it is set as Phy/WirelessPhy.

Line 1 generates the NS simulator object instance and assigns it to variable ns. Line 2 creates an empty trace file ns_aodv.tr and assigns it to variable tf. trace-all command traces all the events in a specific format. Line 6 creates the NAM visualization file ns_aodv.nam and assigns it to nf. Line 7 tells the simulator to record traces in NAM format. Line 10 sets the topography to flatgrid. god object stores the table of shortest no. of hops required from one node to another.

The above configures the node with the variable that we defined in the beginning. Some other parameters such as agentTrace trace UDP in our case, routerTrace traces packets involved in routing, macTrace traces MAC protocol packets, movementTrace traces the motion of nodes.

Here the first loop is assigning the initial location of nodes and the second loop is providing the random movement of nodes within the topography.

In the above code, we are creating an object of UDP and attaching it to our node no. 5, which will be the originating node. Also, creating a Sink and attaching it to the destination node, node no. 2. CBR (Constant Bit Rate) is our traffic source that will generate packets to send over UDP.

The first ‘for loop’ initialize all nodes with initial positions for nam and the second ‘for loop’ resets all nodes at the end of the simulation.

The keyword global is used because we are using variables that were declared outside the scope of proc finish (procedure). flush-trace command saves all traces to respective files. The simulation begins at $ns run.

Simulation

Get the complete code, trace-file analysis, simulation video here on GitHub

Connect with me on LinkedIn — Abhinav Dubey

--

--

Abhinav Dubey
Nerd For Tech

Ex-R&D Associate, Indian Space Association | Data Scientist | IIT Madras | IIIT Delhi | UnivOfDel | LinkedIn - https://www.linkedin.com/in/abhinav-dubey-007001