25 February 2014

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