Skip to main content

MANET Routing Protocols using ns3


Download the Code here:

Check the Video for Detailed instruction and how to use the plots, graphs and source code.

Comparison of MANET routing Protocols

3. DSR
using NS3 (Network Simulator 3)
B.Tech, M.Tech, PhD...
1. Reactive Vs Proactive routing
2. PErformance comparison of MANET protocols
3. AODV Vs DSDV Comparison and also at my channel.

What Version: ns-3.29
My Ubunut OS is: Ubuntu 18.04

This file we are going to use for our simulation:

Once you under stand the code, now lets run this example

Step 1: Copy the above file in to ~ns-3.29/scratch/ folder

Step 2: Understand this code.
Step 3: Run this code
Open the terminal, Go to ns-3.29 and run the following command

$] ./waf --run scratch/manet-routing-compare

enable the following header file

#include "ns3/flow-monitor-helper.h"

four files got generated

Number of nodes: 50
No of sinks : 10
Mobility Model:
Propagation Model: ConstantSpeedPropagationDelay
Propagation Loss Model: Friis
Position Allocator: RandomRectangularPositionAllocator
Mac: AdhocWifiMAC
Mac Standard: 802.11B
Bps: 2Kbps
Total Simulation Time: 200 seconds
Node speed: 20m/s
Node pause time: 0
Protocol: AODV

To run the flowmon file, use of is advised.

to run the file, use the following

$] python AODV.flowmon

Find the python script here.

#beginning of Script

from xml.etree import ElementTree as ET
import sys
import matplotlib.pyplot as pylab
for flow in et.findall("FlowStats/Flow"):
for tpl in et.findall("Ipv4FlowClassifier/Flow"):
if tpl.get('flowId')==flow.get('flowId'):
if tpl.get('destinationPort')=='654':

if rxPackets==0:

pylab.xlabel("Flow Bit Rates (b/s)")
pylab.ylabel("Number of Flows")

pylab.xlabel("No of Lost Packets")
pylab.ylabel("Number of Flows")

pylab.xlabel("Delay in Seconds")
pylab.ylabel("Number of Flows")


#End of Script

We can plot using gnuplot (through CSV File) and matplotlib(Flow monitor)
All these examples, runs for 50 nodes

whenever you compare protocols,have three different sets of node numbers

10 nodes, 50 nodes, 100 nodes and compare them with various metrics as mentioned above...

To analsyse .tr files, we need to use tracemetrics
its a jar file that can be run using

$] java -jar tracemetrics.jar

Hope you would have got an idea on how to simulate wireless protocols using ns3.


  1. Dear Sir, how i can simulate VANET routing protocol in NS3.29 using SUMO 1.2.0 and MOVE.jar on windows 10

  2. you're the king, man! such explicit and down-to-earth c++ codes and other files explanation, I've never seen a better one elsewhere! thx for your effort!

  3. Hello, i can use on this script ENERGY MODEL, how i can use? can you help me? i need compare AODV,OLSR and DSDV energy consumption.
    thank you for your help!

  4. Many Thanks for the nice video and explanation. Can i modify the code to use TCP instead of UDP? How ?


    1. Did you get that, if yes, can you please help how to run particular tcp in manet?

  5. Hello, thank you for the videos and the explanation I tried to do the same steps with OLSR but the result file has no output.. "I did change the destination port as in OLSR.flowmon and there is no error, yet there is no output.

    1. hola, tal vez pudo resolver este problema?

  6. python manet-routing-compare.flowmon
    File "", line 23
    IndentationError: unexpected indent

    Hi and good day
    i received the above error when i implement python cod3

    1. i also encountered the same problem. can you gotten a solution to it? Anybody to help us out? thank you

  7. python manet-routing-compare.flowmon
    File "", line 23
    IndentationError: unexpected indent

  8. Sir Kindly tell me about updated research protocols in ad-hoc network plzz i am very confused to select topic in my thesis..

  9. tanvir@tas:~/ns-allinone-3.29/ns-3.29$ ./waf --pyrun scratch/
    Waf: Entering directory `/home/tanvir/ns-allinone-3.29/ns-3.29/build'
    Waf: Leaving directory `/home/tanvir/ns-allinone-3.29/ns-3.29/build'
    Build commands will be stored in build/compile_commands.json
    'build' finished successfully (6.625s)
    Traceback (most recent call last):
    File "scratch/", line 16, in
    import ns.applications
    ImportError: No module named ns.applications
    Command ['/usr/bin/python', 'scratch/'] exited with code 1

    Sir, How to solve it?

  10. how to get animation this source code ?

  11. cedi@CediPC:~/ns-allinone-3.33/ns-3.33$ python3 AODV.flowmon
    Traceback (most recent call last):
    File "", line 23, in
    NameError: name 'long' is not defined

    i get NameError. Can any one help me?


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 (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/ $ ./ --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 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 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/ $] ./ --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