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


Post a Comment

Popular posts from this blog

AWK Scripts for NS2 to process data from Trace Files

AWK Scripts are very good in processing the data from the log (trace files) which we get from NS2. If you want to process the trace file manually, here is the detailHere is a sample of trace file from NS2 (However ns2 supports a new type of trace file also), but this post will make you understand the old trace format only.r 0.030085562 _0_ MAC  --- 0 message 32 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] r 0.030110562 _0_ RTR  --- 0 message 32 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0] s 1.119926192 _0_ RTR  --- 1 message 32 [0 0 0 0] ------- [0:255 -1:255 32 0]
AWK Scripts are very good in processing the data column wise. For example
the first column in the above trace file represents r, s which indicates receive, sent respectively. If we want to trace the entire r and s alone from this trace file we can represent it as $1
$1 represents ACTION
$2 Time
$3 Node ID
$4 Layer
$5 Flags
$6 seqno
$7 type
$8 Size
$14 Energy (if the network nodes includes EnergyModel)To run the awk script in Li…

nam installation - Segmentation Fault (Solved)

If you are encountering "Segmentation Fault" error while running nam in Ubuntu 14.04 or Linux Mint 17+ editions, this post will be helpful for you.

Download the nam file from this link

First, remove the nam which was installed earlier using the following command 

pradeep@localhost $] sudo apt-get remove nam

and install the new nam which was downloaded just now. go to the folder where the file was downloaded and issue the following command

pradeep@localhost $]  sudo dpkg --install nam_1.15-10_i386.deb

See the screenshot below to install and use nam

 T S Pradeep Kumar

Installation of ns2 in Ubuntu 18.04 - NS2 Tutorial # 2

ns2 installation in Ubuntu 18.04

Unlike earlier version of ubuntu, the 18,04 version does not support the direct installation of ns2, because of the latest C/C++ compiler (7.x), but the latest C/C++ compiler supported by ns2 is gcc-4.8. So this post and video tells you about the installation of gcc-4.8 version, then ns2 and then configuration.
Here are the steps, Please follow the video given below for more information.

$] tar zxvf ns-allinone-2.35.tar.gz

$] sudo apt install gcc-4.8 g++-4.8

if you have installed ubuntu just now, you can try these commands also in the beginning

$] sudo apt update
$] sudo apt install build-essential autoconf automake libxmu-dev

$] cd ns-allinone-2.35/ns-2.35
$] gedit
$] gedit linkstate/ls.h

line number 137, change erase to this->erase
$] cd ..
$] ./install

export PATH=$PATH:/home/pradeepkumar/ns-allinone-2.35/bin:/home/pradeepkumar/ns-allinone-2.35/tcl8.5.10/unix:/home/pradeepkumar/ns-allinone-2.35/tk8.5.10/unix