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
2. aodv.cc

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

bool malicious;

aodv.cc 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 aodv.cc 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.

if(malicious==true)
{
drop(p,DROP_RTR_ROUTE_LOOP);
}

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 aodv.cc file in the ~ns-2.35/aodv/ directory
2. Download the Tcl files for malicious and non malicious
See this post: http://www.nsnam.com/2013/10/tracegraph-installation-in-ubuntu-1310.html
Here is the screenshot shown from the tracegraph
non malicious
Non Malicious simulation

malicious
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

Malicious
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 www.elmurod.net with added result analysis

T S Pradeep Kumar

Comments

  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
    channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
    highestAntennaZ_ = 1.5, distCST_ = 550.0
    SORTING LISTS ...DONE!
    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"

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

    ReplyDelete

Post a Comment

Popular posts from this blog

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 Makefile.in
$] 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
export LD_LIBRARY_PATH=$L…

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 Patient. 
Installing ns3 Download the…

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
So
$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…