Sunday, 2 November 2014

Black hole in AODV

I am trying to add a black hole to AODV-based MANET as a part of my study. I've found a good reference that tells how to add malicious node. The original link is here. His code is perfect. Everything runs smooth except when the very fast wireless links are used in the simulation. There were several warnings that relates to something I don't really remember. I will try to replicate that later and update in the blog someday. In order to get the simulation work, I tried tweaking the code a bit and found that adding C++ program syntax fixed that. Nothing much but a break. I will show my code which is changed a little bit from original one.

Add the following code in aodv.h
bool malicious;

around ( just before or after, it doesn't really matter)
double PerHopTime(aodv_rt_entry *rt);

In aodv.cc, the constructor shall be initialized with malicious=false.
/*
Constructor
*/
AODV::AODV(nsaddr_t id) : Agent(PT_AODV),
btimer(this), htimer(this), ntimer(this),
rtimer(this), lrtimer(this), rqueue() {
index = id;
seqno = 2;
bid = 1;
malicious = false; // code added

So far, aodv works the same with before the changes. To command a black hole start functioning, the command will be passed from TCL file. AODV needs to be programmed in a way so that it catches the passed parameter and started acting like a black hole. Thus, the following code is looked for in aodv.cc.

if(argc == 2) {
Tcl& tcl = Tcl::instance();
if(strncasecmp(argv[1], "id", 2) == 0) {
tcl.resultf("%d", index);
return TCL_OK;
}

And the following lines are added.

if(strcmp(argv[1], "malnode") == 0) {
malicious = true;
return TCL_OK;
}

In TCL, a malicious node or black hole is set by using the following command. It should be added after the nodes have been initialized.

$ns at 0.0 "[$node_(5) set ragent_] malnode"

Finally, the procedure which a black hole will be performed is going to be added. The following code segment is looked for in aodv.cc.

/*
Route Handling Functions
*/
void
AODV::rt_resolve(Packet *p) {
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
aodv_rt_entry *rt;
...

The following lines are added.
if (malicious == true ) {
drop(p, DROP_RTR_ROUTE_LOOP);
}

This is where the original code ends. It runs fine unless the data rate is high. When the packets are transferred at a significantly high rate, it causes some problems. So, the last segment of the code has been modified like the following. It works for me though I could not guarantee that it will be fine in other means.

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

No comments:

Post a Comment