Skip to main content

MANET Routing Protocols using ns3

#AODV #OLSR #MANETs #DSDV #DSR

Download the Code here: 
https://drive.google.com/open?id=1OkVOsifjN9UfQjPGvfR7OuS-x_GBRgCV

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


Comparison of MANET routing Protocols

1. AODV
2. DSDV
3. DSR
4. OLSR
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

https://www.nsnam.com 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:
/home/networks/ns-allinone-3.29/ns-3.29/examples/routing/manet-routing-compare.cc

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
AODV.csv
AODV.mob
AODV.flomon
temp.data

Parameters:
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 temp.py is advised.

to run the file, use the following

$] python flow.py AODV.flowmon

Find the python script here.

#beginning of Script

from xml.etree import ElementTree as ET
import sys
import matplotlib.pyplot as pylab
et=ET.parse(sys.argv[1])
bitrates=[]
losses=[]
delays=[]
for flow in et.findall("FlowStats/Flow"):
for tpl in et.findall("Ipv4FlowClassifier/Flow"):
if tpl.get('flowId')==flow.get('flowId'):
break
if tpl.get('destinationPort')=='654':
continue
losses.append(int(flow.get('lostPackets')))

rxPackets=int(flow.get('rxPackets'))
if rxPackets==0:
bitrates.append(0)
else:
t0=float(flow.get('timeFirstRxPacket')[:-2])
t1=float(flow.get("timeLastRxPacket")[:-2])
duration=(t1-t0)*1e-9
bitrates.append(8*long(flow.get("rxBytes"))/duration*1e-3)
delays.append(float(flow.get('delaySum')[:-2])*1e-9/rxPackets)

pylab.subplot(311)
pylab.hist(bitrates,bins=40)
pylab.xlabel("Flow Bit Rates (b/s)")
pylab.ylabel("Number of Flows")

pylab.subplot(312)
pylab.hist(bitrates,bins=40)
pylab.xlabel("No of Lost Packets")
pylab.ylabel("Number of Flows")

pylab.subplot(313)
pylab.hist(bitrates,bins=10)
pylab.xlabel("Delay in Seconds")
pylab.ylabel("Number of Flows")

pylab.subplots_adjust(hspace=0.4)
pylab.savefig("results.pdf")

#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.


Comments

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

    ReplyDelete
  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!

    ReplyDelete
  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!

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

    Regards
    Derar

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

      Delete
  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.

    ReplyDelete
    Replies
    1. hola, tal vez pudo resolver este problema?

      Delete
  6. python flow.py manet-routing-compare.flowmon
    File "flow.py", line 23
    bitrates.append(8*long(flow.get("rxBytes"))/duration*1e-3)
    ^
    IndentationError: unexpected indent

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

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

      Delete
  7. python flow.py manet-routing-compare.flowmon
    File "flow.py", line 23
    bitrates.append(8*long(flow.get("rxBytes"))/duration*1e-3)
    ^
    IndentationError: unexpected indent

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

    ReplyDelete
  9. tanvir@tas:~/ns-allinone-3.29/ns-3.29$ ./waf --pyrun scratch/first.py
    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/first.py", line 16, in
    import ns.applications
    ImportError: No module named ns.applications
    Command ['/usr/bin/python', 'scratch/first.py'] exited with code 1

    Sir, How to solve it?

    ReplyDelete
  10. how to get animation this source code ?

    ReplyDelete
  11. cedi@CediPC:~/ns-allinone-3.33/ns-3.33$ python3 flow.py AODV.flowmon
    Traceback (most recent call last):
    File "flow.py", line 23, in
    bitrates.append(8*long(flow.get("rxBytes"))/duration*1e-3)
    NameError: name 'long' is not defined



    i get NameError. Can any one help me?

    ReplyDelete

  12. Thanks, Prof T S Pradeepkumar. Sorry, an error message appeared:
    ((Traceback (most recent call last):
    File "flow.py", line 3, in
    import matplotlib.pyplot as pylab
    ImportError: No module named matplotlib.pyplot))

    How do I treat it?

    ReplyDelete

  13. Thanks, Prof T S Pradeepkumar. Sorry, an error message appeared:
    ((Traceback (most recent call last):
    File "flow.py", line 3, in
    import matplotlib.pyplot as pylab
    ImportError: No module named matplotlib.pyplot))

    How do I treat it?

    ReplyDelete

  14. Thanks, Prof T S Pradeepkumar. Sorry, an error message appeared:
    ((Traceback (most recent call last):
    File "flow.py", line 3, in
    import matplotlib.pyplot as pylab
    ImportError: No module named matplotlib.pyplot))

    How do I treat it?

    ReplyDelete
    Replies
    1. You need to install the following software in linux to handle this error
      sudo apt install python3-matplotlib

      Delete

Post a Comment

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools 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 gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libc...

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb http://in.archive.ubuntu.com/ubuntu bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/Makefile.in Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/Makefile.in ~xgraph-12.2/Makefile.in ~otcl-1.14/Makefile.in Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes ...

Simulation of URDF, Gazebo and Rviz | ROS Noetic Tutorial 8

Design a User-defined robot of your choice (or you can use the URDF file) and enable the LIDAR Scanner so that any obstacle placed on the path of the light scan will cut the light rays. Visualize the robot in the Gazebo workspace, and also show the demonstration in RViz.   (NB: Gain knowledge on wiring URDF file and .launch file for enabling any user-defined robot to get launched in the gazebo platform.) SLAM : One of the most popular applications of ROS is SLAM(Simultaneous Localization and Mapping). The objective of the SLAM in mobile robotics is to construct and update the map of an unexplored environment with the help of the available sensors attached to the robot which will be used for exploring. URDF: Unified Robotics Description Format, URDF, is an XML specification used in academia and industry to model multibody systems such as robotic manipulator arms for manufacturing assembly lines and animatronic robots for amusement parks. URDF is especially popular with users of the ...