Skip to main content

AODV simulation in NS2 (Part 1) - NS2 Tutorial # 11

Lecture 11 - AODV - Part 1
Todays topic on AODV protocol

AODV - Adhoc Ondemand Distance Vector
the location of the source code for Aodv is in the folder

~ns-2.35/aodv/

My suggestion is
Always try to understand the header file first.. later you can move on to source file (.cc files)
I will go through aodv.h file first and then aodv.cc file next....
let me explain....

I should know where my work is residing, for example in AODV

should I work on


  • Routing Table
  • Energy Management
  • Quality oif Service
  • Link Failure
  • Logs or tracing
  • Neighbour management
  • Attacks (Black hole, gray hole, etc...)
  • Security

so prefer to stay at the header files first...
Now the action begins.
how do i modify the AODV protocol as per my small piece of algorithm...
I would like to print the nodes that are forwarding the packets.
Two information will be recorded in a text file separately..

Name of the file: aodv_output.dat data recorded will be: forwarded packet, node index (node number).

For this, please open the aodv.h and aodv.cc file.

Step 1:
add a variable called as pkt_count as an integer in protected scope inside the aodv.h file.

int pkt_count;
Step 2:

Initialize pkt_count with a value 0 in the aodv.cc file (preferably in the constructor)

pkt_count=0;

Step 3:

Since I am going to get the packet counts in a file, i need to create a file pointer. But first let me get the data in the terminal itself. later i will create it in the file.

Also, only during the forwarding of packets, i am going to get the count, so my code will be running inside the forward() function.

Add the following line to the forward() function of aodv.cc

printf("I am packet no %d and from node number %d\n",pkt_count++,index);


Step 4:
Now recompile ns2 using the command make

$] cd ns-allinone-2.35/ns-2.35/

$] make


Once, there are no errors, your code is compiled successfully....

Then, run any wireless tcl script that has the routing protocol as AODV.
I am running AODV.tcl file that was generated in LEcture number 9.

to run that just
$] ns AODV.tcl

$] nam AODV.nam

I need to get this output in a file called as aodv_output.dat
How to do that... Again the same step open, aodv.cc and aodv.h

Declare a file pointer inside the aodv.h file

FILE *fp;

Initialize this file pointer in aodv.cc constructor

fp = fopen ("aodv_output.dat","w");

include the following line in the forward() function of aodv.cc


fprintf(fp,"I am packet no %d and from node number %d\n",pkt_count++,index);

and run the AODV.tcl file and check for a file called aodv_output.dat is created in the same folder where the AODV.tcl is residing.


Thank you for watching..
To download the codes, visit https://www.nsnam.com

and share and subscribe to my youtube channel
Youtube.com/tspradeepkumar
Stay Tuned for more lectures...

T S Pradeep Kumar

Comments

  1. Hello ,
    I' do not see the printf in the terminal, can you help me please

    ReplyDelete
  2. Sir, I can not find the codes. Please help me out with a link.

    ReplyDelete
    Replies
    1. i also cannot find codes here. Please help me out to find codes

      Delete
    2. there is no source code for AODV simulation ns2

      Delete
  3. how can i adding function into AODV.cc file

    ReplyDelete
  4. sorry to not answer your question but i am comming with another problem which is: how to implement the tesla protocol in ad hoc network in ns2.

    ReplyDelete
  5. Why the whole procedure so error while each step i take perfectly.

    ReplyDelete
  6. Sir fprintf text file not create while its recompile successfully. Any solution??

    ReplyDelete

Post a Comment

Popular posts from this blog

Installing ns-3.34 in Ubuntu 20.04

This post shows how to install ns 3.34 in Ubuntu 20.04 LTS Prerequisites: Fresh installation of Ubuntu Version 20.04 LTS  ns3.34 can be downloaded from here Follow the video link for complete step by step instructions on the installation.  This version fixes the compilation issues of vanet-routing-compare.cc (bug in ns3.33)  Issue the following commands after opening a terminal  $ sudo apt update $ sudo apt install g++ python3 python3-dev python-dev pkg-config sqlite3 python3-setuptools git qt5-default gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar openmpi-bin openmpi-common openmpi-doc libopenmpi-dev tcpdump wireshark libxml2 libxml2-dev Unzip or untar the ns-allinone-3.34.tar.bz2 in the home folder (in my case its /home/pradeepkumar) $ cd ns-allinone-3.34/ $ ./build.py --enable-examples --enable-tests  Once the installation is completed, you may get an output show

Installation of ns3 in Windows 10 and Windows 11 OS using WSL (Windows Subsystem for Linux)

This post shows how to install ns-3.33 in Windows 10 through WSL (Windows Subsystem for Linux) This posts works for Windows 11 also (I have tested it on a Windows 11 ISO and it works the Same way as mentioned in the following post.) This post will work for ns-3.3x version. Prerequisites : Install Windows Subsystem for Linux with GUI: Please refer the following video  System Information: OS used: Windows 10 and WSL (Ubuntu 20.04) GUI: XServer for Windows NS3 Version: ns-3.33 See the following complete video on how to install ns3 in Windows 10 Step 0 : Open XLaunch Step 1 :  Open WSL using PowerShell and open it as Administrator Command:/  wsl $ xfce4-session The GUI of Ubuntu Opens within Windows 10 OS. Step 2 : Download ns3 from nsnam.org website through Mozilla Firefox browser Step 3: Open a Terminal  $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev python3-pygraphviz cvs mercurial bzr git cmake p7zip-full python3-matplotlib python-tk python3-dev qt5-q

Installing NS-3.32 in Ubuntu 20.04

This is about installing ns version 3.32 in Ubuntu 20.04 LTS. #ns3 #ns3 .32 #networksimulation The commands used in the video are given here. $] sudo apt update $] sudo apt install build-essential autoconf automake libxmu-dev python3-pygraphviz cvs mercurial bzr git cmake p7zip-full python3-matplotlib python-tk python3-dev qt5-qmake qt5-default gnuplot-x11 wireshark Download the ns-allinone-3.32.tar.bz2 package from nsnam.org and copy it to /home/ folder See the full video for detailed instructions Extract it either in GUI or using command $] tar jxvf ns-allinone-3.32.tar.bz2 $] cd ns-allinone-3.32/ $] ./build.py --enable-examples --enable-tests The above command will take some time to install all the packages  You can see the output as shown below ns3 To check whether ns3 installed successfully, use the following commands. $] cd ns-3.32/ $] ./waf --run hello-simulator You should get the output as Hello Simulator $] ./waf --run first This is the example from the ns-3.32/exa