Sunday, 2 November 2014

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:
    • 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
2) Open the file ns-allinone-2.34/ns-2.34/aodv/aodv.h in your favorite editor
    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) {
......
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;
}
}
return Agent::command(argc, argv);

}
void
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)
......

}


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 */
2class AODV: public Agent {
3...
4/*
5* History management
6*/
7double      PerHopTime(aodv_rt_entry *rt);
8...
add following line
1bool     malicious;
With this variable we are trying to define if the node is malicious or not. In aodv.cc after
1/*
2  Constructor
3*/
4AODV::AODV(nsaddr_t id) : Agent(PT_AODV),btimer(this), htimer(this), ntimer(this), rtimer(this), lrtimer(this), rqueue() {
5index = id;
6seqno = 2;
7bid = 1;
8...
add following line
1malicious = false;
The above code is needed to initialize, and all nodes are initially not malicious. Then we will write a code to catch which node is set as malicious. In aodv.cc after
1if(argc == 2) {
2  Tcl& tcl = Tcl::instance();
3 
4    if(strncasecmp(argv[1], "id", 2) == 0) {
5      tcl.resultf("%d", index);
6      return TCL_OK;
7    }
add following line
1if(strcmp(argv[1], "hacker") == 0) {
2    malicious = true;
3   return TCL_OK;
4}
Now we will do some work in TCL to set a malicious node. Using script in my post , we add following line to set node 5 as malicious node.
1$ns at 0.0 "[$mnode_(5) set ragent_] hacker"
You may add this line after
1for {set i 0} {$i &lt; $val(nn)} { incr i } {
2$ns initial_node_pos $mnode_($i) 10
3}
4...
Alright, we have set malicious node but we did not tell malicious node what to do. As it is known, rt_resolve(Packet *p) function is used to select next hop node when routing data packets. So, we tell malicious node just drop any packet when it receives. To do that after
1/*
2Route Handling Functions
3*/
4void
5AODV::rt_resolve(Packet *p) {
6struct hdr_cmn *ch = HDR_CMN(p);
7struct hdr_ip *ih = HDR_IP(p);
8aodv_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 }
And implementing malicious node is done. I hope the post will be helpful to design your secure routing protocol.
P.S. Guys please don’t ask me c/c++ questions,

 

No comments:

Post a Comment