Black hole in AODV
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
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;
}
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;
}
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);
}
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 ;
drop(p, DROP_RTR_ROUTE_LOOP);
return ;
}
No comments:
Post a Comment