For using promiscuous mode in AODV NS2
Intro:-
          In Promiscuous mode each node in the network listens the packets transmitted by its own neighbor nodes. 
          In NS-2, some time we have to calculate the packet drops or
 analyze the process. For the same we need to set the network to operate
 in promiscuous mode. Here, I am going to explain how we can set our 
wireless network in promiscuous mode with AODV as Routing protocol using
 NS2 simulator.
1) We need to modify in total 3 files, so it's good to take a backup of it.
Files are:
and make the changes as shown in blue color.
1) We need to modify in total 3 files, so it's good to take a backup of it.
Files are:
- ns-allinone-2.34/ns-2.34/aodv/aodv.cc
- ns-allinone-2.34/ns-2.34/aodv/aodv.h
- ns-allinone-2.34/ns-2.34/tcl/lib/ns-mobilenode.tcl
and make the changes as shown in blue color.
  #include <mac.h>
  class AODV: public Tap, public Agent {
  public:
  void tap(const Packet *p);
  ......
  protected:
  Mac *mac_; 
  ......
 }
3) Open the file ns-allinone-2.34/ns-2.34/aodv/aodv.cc and make the changes as  
    shown in blue color.
int
AODV::command(int argc, const char* const * argv) {
AODV::command(int argc, const char* const * argv) {
......
else if(argc == 3) {
......
else if (strcmp(argv[1], "install-tap") == 0) {
mac_ = (Mac*)TclObject::lookup(argv[2]);
if (mac_ == 0) return TCL_ERROR;
mac_->installTap(this);
return TCL_OK;
}
mac_ = (Mac*)TclObject::lookup(argv[2]);
if (mac_ == 0) return TCL_ERROR;
mac_->installTap(this);
return TCL_OK;
}
} 
return Agent::command(argc, argv);
return Agent::command(argc, argv);
}
void
AODV::tap(const Packet *p) {
AODV::tap(const Packet *p) {
// put your code here
} 
4) Open the file ns-allinone-2.34/ns-2.34/tcl/lib/ns-mobilenode.tcl and make the  
    changes as shown in blue color.
Node/MobileNode instproc add-target { agent port } {
$self instvar dmux_ imep_ toraDebug_ mac_
......
# Special processing for AODV
set aodvonly [string first "AODV" [$agent info class]]
if {$aodvonly != -1 } {
$agent if-queue [$self set ifq_(0)] ; # ifq between LL and MAC
$agent install-tap $mac_(0)
......set aodvonly [string first "AODV" [$agent info class]]
if {$aodvonly != -1 } {
$agent if-queue [$self set ifq_(0)] ; # ifq between LL and MAC
$agent install-tap $mac_(0)
}
Explanation:-
The above procedure will put all the nodes in the wireless network in promiscuous mode. If a node A wants to listen the packets from a node B in promiscuous mode to check whether to check B is forwarding the packets which are sent by A to B or not we can write the code in function tap()
5) To simulate a node as a malicious node in AODV see below (not yours but blogs)
Many people have asked me how to implement malicious drop in AODV. I have decided to write simple code for adding malicious node in AODV ( or in any routing protocol).
First you need to modify aodv.cc and aodv.h files. In aodv.h after
| 1 | /*  The Routing Agent */ | 
| 2 | classAODV: publicAgent { | 
| 3 | ... | 
| 4 | /* | 
| 5 | * History management | 
| 6 | */ | 
| 7 | doublePerHopTime(aodv_rt_entry *rt); | 
| 8 | ... | 
| 1 | boolmalicious; | 
| 1 | /* | 
| 2 |   Constructor | 
| 3 | */ | 
| 4 | AODV::AODV(nsaddr_t id) : Agent(PT_AODV),btimer(this), htimer(this), ntimer(this), rtimer(this), lrtimer(this), rqueue() { | 
| 5 | index = id; | 
| 6 | seqno = 2; | 
| 7 | bid = 1; | 
| 8 | ... | 
| 1 | malicious = false; | 
| 1 | if(argc == 2) { | 
| 2 |   Tcl& tcl = Tcl::instance(); | 
| 3 | 
| 4 |     if(strncasecmp(argv[1], "id", 2) == 0) { | 
| 5 |       tcl.resultf("%d", index); | 
| 6 |       returnTCL_OK; | 
| 7 |     } | 
| 1 | if(strcmp(argv[1], "hacker") == 0) { | 
| 2 |     malicious = true; | 
| 3 |    returnTCL_OK; | 
| 4 | } | 
| 1 | $ns at 0.0"[$mnode_(5) set ragent_] hacker" | 
| 1 | for{seti 0} {$i < $val(nn)} { incr i } { | 
| 2 | $ns initial_node_pos $mnode_($i) 10 | 
| 3 | } | 
| 4 | ... | 
| 1 | /* | 
| 2 | Route Handling Functions | 
| 3 | */ | 
| 4 | void | 
| 5 | AODV::rt_resolve(Packet *p) { | 
| 6 | structhdr_cmn *ch = HDR_CMN(p); | 
| 7 | structhdr_ip *ih = HDR_IP(p); | 
| 8 | aodv_rt_entry *rt; | 
| 9 | ... | 
We add a few lines
| 1 | // if I am malicious node | 
| 2 |  if(malicious == true) { | 
| 3 |     drop(p, DROP_RTR_ROUTE_LOOP); | 
| 4 |     // DROP_RTR_ROUTE_LOOP is added for no reason. | 
| 5 |  } | 
P.S. Guys please don’t ask me c/c++ questions,
 
 
No comments:
Post a Comment