Skip to main content

Adding a malicious node in NS2 in AODV Protocol

Adding a malicious node is ns2 using aodv protocol. The node which is declared as malicious will simply drop the router packet (DROP_RTR_ROUTE_LOOP).

Two files have to be modified.
1. aodv.h

aodv.h file changes
Declare a boolean variable malicious as shown below in the protected scope in the class AODV

bool malicious; file changes
1. Initialize the malicious varible with a value "false". Declare it inside the constructor as shown below
AODV::AODV(nsaddr_t id):Agent(PT_AODV)...
malicious = false;

2. Add the following statement to the file in the "if(argc==2)" statment.

if(strcmp(argv[1], "malicious") == 0) {
    malicious = true;
   return TCL_OK;

3. Implement the behavior of the malicious node by setting the following code in the rt_resolve(Packet *p) function. The malicious node will simply drop the packet as indicated below.


Once done, recompile ns2 as given below
Open Terminal -> Go to ~ns-2.35/ directory and type the command make to compile
$] cd /home/pradeep/ns-allinone-2.35/ns-2.35/
$] make

Once the compilation is done, Check the malicious behavior using the Tcl Script by setting any one node as malicious node. The command to set the malicious node is
$ns at 0.0 "[$n2 set ragent_] malicious"
The variable referred for node2 is n2 (set n2 [$ns node])

Result Analysis of Malicious Node behavior
The results of the above algorithm is analysed using tracegraph. For a given network, the malicious behavior is set.
You can download the entire files here.
1. Copy the aodv.h and file in the ~ns-2.35/aodv/ directory
2. Download the Tcl files for malicious and non malicious
See this post:
Here is the screenshot shown from the tracegraph
non malicious
Non Malicious simulation

Malicious behavior
Here is the text info for the above graph:
Non Malicious
Number of generated packets: 8493
Number of sent packets: 8493
Number of forwarded packets: 0
Number of received packets: 8401
Number of dropped packets: 4
Number of lost packets: 0
Number of sent bytes: 461918
Number of forwarded bytes: 0
Number of received bytes: 2435044
Number of dropped bytes: 164
Minimal packet size: 28
Maximal packet size: 1040

Average packet size: 171.4787

Simulation length in seconds: 21.052766
Number of nodes: 2
Number of sending nodes: 2
Number of receiving nodes: 2
Number of generated packets: 67
Number of sent packets: 54
Number of forwarded packets: 0
Number of dropped packets: 16
Number of lost packets: 0
Minimal packet size: 0
Maximal packet size: 1098
Average packet size: 125.76
Number of sent bytes: 8102
Number of forwarded bytes: 0
Number of dropped bytes: 480
Packets dropping nodes: 1

It is clear from the results that malicious is simply dropping the packet, though it generates packet and are not sent.
This post is a reproduction from with added result analysis

T S Pradeep Kumar


  1. I followed the above procedure. It shows the below mentioned error, Kindly help us to resolve it.
    root@sriramachandran-Inspiron-N4050:/home/sriramachandran/ns-allinone-2.35/ns-2.35/tcl/ex# ns malicious.tcl
    num_nodes is set 7
    warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
    INITIALIZE THE LIST xListHead - Calc highestAntennaZ_ and distCST_
    highestAntennaZ_ = 1.5, distCST_ = 550.0
    ns: _o127 malicious:
    (_o127 cmd line 1)
    invoked from within
    "_o127 cmd malicious"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o127" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "_o127 malicious"

  2. i tried flooding attack\and i cant see it is flooding??? plzz help meee

  3. hello sir!
    I am doing my graduation work!
    But your download link for tcl is disable,could u help me ?


Post a Comment

Popular posts from this blog

Ant Colony algorithm using NS2

Ant Colony Algorithm in NS2 for Wired Networks. Please follow the video for full instructions  I am running in Ubuntu 20.04 There are multiple files in Ant Colony (we use a protocol called Antnet) which i have already included in my blog called  Lets go to my Blog. And Search for Ant Colony and Download the complete folder AntNet as shown in the video. Now Copy paste the files in their corresponding location: My Location if ns2 is  /home/pradeepkumar/ns-allinone-2.35/ns-2.35/ Inside this folder, the files have to be pasted in differnet sub folders...  Let me show you one by one... and cmu-trace.h have to be pasted to ~trace/ and drop-tail.h ---- ~queue/ to be replaced in the ns-2.35/ folder. ns-default.tcl, ns-lib.tcl and ns-packet.tcl to be pasted at  ~tcl/lib packet.h to be replaced at common/ folder. and priqueue.h to be pasted at queue/ antnet / folder have to be copied to ns-2.35/ folder (this is very imp

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

ns3 installation in Ubuntu 16.04

This post serves the installation instructions of ns3 in ubuntu 16.04 version. Some of my students are working in ns3, this post will benefit them in installing ns3. OS Used: Ubuntu 16.04.4 ns3 version: ns3 version 3.27 The same procedure will be applied for OS like Debian, Linux Mint. Fresh installation of Ubuntu 16.04 Let you try the fresh installation of ubuntu in your hard disk along with windows. Installation of ns3 dependencies ns3 needs so many dependencies, developmental libraries, drivers, etc. so install all those $] sudo apt update  $] sudo apt upgrade $] sudo apt-get install build-essential autoconf automake libxmu-dev python-pygoocanvas python-pygraphviz cvs mercurial bzr git cmake p7zip-full python-matplotlib python-tk python-dev python-kiwi python-gnome2 python-gnome2-desktop-dev python-rsvg qt4-dev-tools qt4-qmake qt4-qmake qt4-default gnuplot-x11 wireshark The above command make take some time to download, compile and install it, Be Patie