Saturday 29 June 2013

Part 4 Adding a New Routing Protocol in Network simulator with idsAODV example



Before you begin reading this post, I assume that you have already installed NS2 on Linux. I have used version 2.34, which is current release. If you have not installed yet, DOWNLOAD ns2.34 and INSTALL. Okey, simple requirements to write your own routing protocol

  • NS2 installed
  • You should know how to program in C/C++.
  • Optionally, shell scripting and perl.
Let's start with creating directory of routing protocol.  


Download and put idsaodv folder in $NS_ROOT/ ns-2.34/". 

download them from by clicking on the following link Idsaodv.zip.

(TO Download this file, You have to take a survey. Click on the Ace2three link or any other link and register yourself  there and Activate that link. Mean while don't close that survey window popped. else mail me I will send them to you.)

 I will not explain the code here, and if you don't understand just leave comment I will try to answer.



Now, we are going to modify following files. Therefore it is better you backup these files before you start adding new protocol, so that you can easily go back.

$NS_ROOT/Makefile
$NS_ROOT/queue/priqueue.cc
$NS_ROOT/common/packet.h
$NS_ROOT/trace/cmu-trace.h
$NS_ROOT/trace/cmu-trace.cc
$NS_ROOT/tcl/lib/ns-packet.tcl
$NS_ROOT/tcl/lib/ns-lib.tcl
$NS_ROOT/tcl/lib/ns-agent.tcl
$NS_ROOT/tcl/lib/ns-mobilenode.tcl

Let's start with ~/ns-allinone-2.34/ns-2.34/Makefile just add following lien at 269

idsaodv/idsaodv.o \

Add following lines to ~/ns-allinone-2.34/ns-2.34/queue/priqueue.cc from line 93.

// idsAODV patch
case PT_idsAODV:

To define new routing protocol packet type we have to modify ~/ns-allinone-2.34/ns-2.34/common/packet.h file.
We change PT_NTYPE to 63, and for our protocol PT_idsAODV = 62.
If you have already installed another routing protocol. Just make sure PT_NTYPE is last, and protocol number is ordered sequentially. From line 85 changes would be :

// idsAODV packet
static const packet_t PT_idsAODV = 62;
// insert new packet types here
static packet_t PT_NTYPE = 63; // This MUST be the LAST one

We make following code change at line 254 of ~/ns-allinone-2.34/ns-2.34/common/packet.h. 
The code is used that the packet is routing protocol packet and has high priority.

type == PT_AODV ||
type == PT_idsAODV)
And at line 390 of the same file

// idsAODV patch
name_[PT_idsAODV] = "idsAODV";

Now we will modify tcl files to create routing agent.
First we define protocol name to use in tcl file.
It would done by modifying ~/ns-allinone-2.34/ns-2.34/tcl/lib/ns-packet.tcl @ line 172

# idsAODV patch
idsAODV

Now we set routing agent by modifying ~/ns-allinone-2.34/ns-2.34/tcl/lib/ns-lib.tcl @ line 633

idsAODV {
set ragent [$self create-idsaodv-agent $node]
}

From line 860 of the same file following code should be added.

Simulator instproc create-idsaodv-agent { node } {
# Create idsAODV routing agent
set ragent [new Agent/idsAODV [$node node-addr]]
$self at 0.0 "$ragent start"
$node set ragent_ $ragent
return $ragent
}

Now we will set port numbers of routing agent. sport is source port, dport is destination port.
Modify ~/ns-allinone-2.34/ns-2.34/tcl/lib/ns-agent.tcl line 202

Agent/idsAODV instproc init args {
$self next $args
}
Agent/idsAODV set sport_ 0
Agent/idsAODV set dport_ 0

Frankly speaking I have no idea why I have to add following things. But I believe it should be done according to some tutorial :
 ~/ns-allinone-2.34/ns-2.34/tcl/lib/ns-mobilenode.tcl line 201

# Special processing for idsAODV
set idsaodvonly [string first "idsAODV" [$agent info class]]
if {$idsaodvonly != -1 } {
$agent if-queue [$self set ifq_(0)] ;# ifq between LL and MAC
}

We are done.
got to ~/ns-allinone-2.34/ns-2.34/ directory and do

make clean
make

If you face any difficulty please place comment. I will try level best to solve.

2 comments:

  1. Hi ,first of all thank u for your plog is really interest .
    My question is that i implemented AODV against blackhole attack and now i want to secure my network by using IDSaodv how can i do that plz?thanks in advance

    ReplyDelete
  2. hello Akourmis,
    can you please help to detect the malicious node using the idsaodv
    baglarypriyanka1@gmail.com

    ReplyDelete