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 1. AODV
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/flo…

NAM and XGraph Installation in Ubuntu 18.04

This post helps you in installing nam and xgraph in ubuntu 18.04.

Mandatory steps before proceeding the following installation

$] sudo apt update
$] sudo apt install build-essential autoconf automake libxmu-dev
$] sudo apt install gcc-4.8 g++-4.8 

Installing ns2 on Ubuntu 18.04 (Refer this detailed instructions)

ns2 uses gcc-4.8 as c compiler and
g++-4.8 as C++ Compiler

ns2, nam and xgraph all these softwares were comfortable with 4.8 version so wee need to change these settings inthe

We have to modify at three locations;
1. ns-2.35/
2. nam-1.15/
3. xgraph-12.2/

Change as per the following in the above three files.
@CC@ --> gcc-4.8
@CPP@ --> g++-4.8

line nuber 137, change erase to this->erase

Set the PATH and LD_LIBRARY_PATH in /home/networks/.bashrc file as per the video shown below.

we have installed ns2, nam and xgraph in the OS Ubuntu 18.04

Subscribe to Engineering Clinic and click the Bell Button to get the u…

Wired Cum Wireless Network Simulation - NS2 Tutorial 22

Today Session on
Wired Cum Wireless Networks using ns2.

You can watch the following lecture before understanding this lecture.
Watch Wireless Networks -
Watch Wired Networks -

Number of Wireles snodes is 7
Wired nodes - 2
Accesspoint or Base Stations - 2

Watch the full video for this example

this example is already avaialble in tcl/ex folder.
The same example I have taken but modified to my design...

How to generate Scenario and Traffic generation (connection Pattern)

To generate the connection pattern, here is the steps

Open the terminal and go to the folder
$] cd /home/pradeepkumar/ns-allinone-2.35/ns-2.35/indep-utils/cmu-scen-gen
and run this command
$] ns cbrgen.tcl -type tcp -nn 7 -seed 1 -mc 20 -rate 0.001 

for 7 nodes, type of traffic is TCP, random seed is 1, maximum connection is 20 and the rate is 1ms or 0.001 and the output is sent to tcpgen.tcl


Ns2 and Ns3 Video Tutorials with Free Source Code

This post shows you the way to download, learn and watch source  codes and their working in ns3 and ns2.
Everyday thousands of visitor visits this blog and search for source code and explanation. Since 2011, the blog is delivering information across the globe.

Now this era is on Videos and online tutorials. nsnam is happily created a Video Channel called "Engineering Clinic" in Youtube and deliver video lectures with free source codes for all applications.

Subscribers of this blog are requested to subscribe to the video channel given below 

Here are some Playlists that are important to the viewers of this blog.

NS2 Tutorials -

NS3 Tutorials -

IoT Tutorials -

MOODLE Tutorials - 

Wormhole Attack in ns2 with full source code

Wormhole attack in ns2 - with full source code.

OS Used: Ubuntu 18.04 LTS
Ns2 version - 2.35

Just three files are to be modified


Download link for all the files .cc, .h and .tcl files

All these files are located in the ~ns-2.35/mac/

How to do?
Copy all the above three files in the mac/ folder and open the terminal

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

$] make 

You should not get any error. Once done, open the tcl files given in the folder ex-wormhole and run the examples and predict the performance as per the video given above.

What is wormhole?

How to download the files. I will give the copy of the above three files in my website

Very soon, I will move to github.

Subscribe to my youtube channel and share.

Explanation of Wormhole Attack

Hope you would have enjoyed this worm hole attack in ns2.

Please download the full source code from my website

If you need more informa…

How to add a Protocol in ns2 - NS2 Tutorial #13

How to add a new protocol in ns2

I am going to use the version ns-2.35
protoname was one of the best unicast routing protocol for ns2.


Protoname -> Simp


protoname -> simp

you can download the  source code from

There are totally 5 files in the source code converted to 

protoname.h -> simp.h 

protoname_pkt.h -> simp_pkt.h -> 

protoname_rtable.h -> simp_rtable.h

New Protocol Implementation

In this new protocol,  we have to

1. Add the source code (the 5 files given above)

2. existing code modification (within ns2)

3. Make an entry in the

4. Recompile ns2

5. Test the protocol using a TCL file.

Addition of source code is done.

Existing code modification - Very important.

in ns2, inforamtion about compilation is scattered... we need to make modifications at multiple locations. What are the files that are needed for modification.

all the file locations are he…

Blackhole attack in ns2 - NS2 Tutorial # 12

How to add a black hole attack in AODV protocol in ns2.  You can download the source codes. 
Black hole is the basic attack in a network, here we are going mitigate this attack in ns2.
Trust value, based on the trust value, if the value is less, then we can make it as an attacker node.
High trust, medium trust and low trust (integer)
Trusted or not (boolean)
To make a node attacker node (preferanly a black hole attack, how to do that?)
AODV protocol as it is easy to implement in ns2.

Step 1: Declare the attacker variable We will two files aodv.h and files  in aodv.h file,  create a variable name as given below in the protected scope

bool attacker;
Step 2: initialize the attacker variable as false. In file, initialize the attacker to be false inside the constructor.

Step 3: if a node is a blackhole, what happens to attacker value in the command() function of file inside the block  if(argc==2), include the following lines
if(strncasecmp(argv[1], "blackhol…