Part 3
Adding a New Routing Protocol in Ns with black hole AODV example
Writing
routing protocol is fairly easy in NS2, but for beginners it seems very
difficult. Therefore, if you are new to NS2 and want to write your own
routing protocol, I would strongly recommend to revise AODV source code.
Because, I believe AODV source code is straightforward and fairly easy
to understand due to the simplicity of the AODV protocol.
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 HERE 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 blackholeaodv folder in $NS_ROOT/ ns-2.34/".
download them from clicking on the following link blackhole attack source file
(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.)
(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
blackholeaodv/blackholeaodv.o \
Add following lines to ~/ns-allinone-2.34/ns-2.34/queue/priqueue.cc from line 93.
// blackholeAODV patch
case PT_blackholeAODV:
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_blackholeAODV = 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 :
// blackholeAODV packet
static const packet_t PT_blackholeAODV = 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_blackholeAODV)
And at line 390 of the same file
// blackholeAODV patch
name_[PT_blackholeAODV] = "blackholeAODV";
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
# blackholeAODV patch
blackholeAODV
Now we set routing agent by modifying ~/ns-allinone-2.34/ns-2.34/tcl/lib/ns-lib.tcl @ line 633
blackholeAODV {
set ragent [$self create-blackholeaodv-agent $node]
}
You May Like to Read This:
From line 860 of the same file following code should be added.
Simulator instproc create-blackholeaodv-agent { node } {
# Create blackholeAODV routing agent
set ragent [new Agent/blackholeAODV [$node node-addr]]
$self at 0.0 "$ragent start"
$node set ragent_ $ragent
return $ragent
}
Modify ~/ns-allinone-2.34/ns-2.34/tcl/lib/ns-agent.tcl line 202
Agent/blackholeAODV instproc init args {
$self next $args
}
Agent/blackholeAODV set sport_ 0
Agent/blackholeAODV 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 blackholeAODV
set blackholeaodvonly [string first "blackholeAODV" [$agent info class]]
if {$blackholeaodvonly != -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
No comments:
Post a Comment