Search This Blog

Tuesday 31 December 2013

Adding malicious node to aodv ns2 ?


   >  We need to modify two files,

                    i)  aodv.h
                    ii) aodv.cc

   >  In aodv.h,

                   i)
                       /*
                           The Routing Agent
                       */
                      class AODV: public Agent
                     {
                        ..........

                       /*
                       * History management
                       */
                         bool  malicious; 
                           ..........
                       }

   >  In aodv.cc,

                 i)
                 
                   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;
                        ............
                    }

              ii)

                    int AODV::command(int argc, const char*const* argv)
                    {
                       if(argc == 2)
                      {
                           Tcl& tcl = Tcl::instance();

                          if(strncasecmp(argv[1], "id", 2) == 0)
                          {
                               tcl.resultf("%d", index);
                                 return TCL_OK;
                          }
     
                          if(strcmp(argv[1], "hacker") == 0) 
                          {
                                 malicious=true;
             return TCL_OK;
                          }
                                ...........
                          }
                     }

             iii)
                     /*
                        Route Handling Functions
                     */

                     void AODV::rt_resolve(Packet *p)
                     {
                        ..........
                     // If i am a malicious node,
if (malicious == true) 
{
drop(p, DROP_RTR_NO_ROUTE);
                                // DROP_RTR_NO_ROUTE is added for no reason
                                return;    //Required if you get pkt flow not specified error.
}
                        .........
                      }

    > In your tcl code,
         
                 >  After packet transmission, add the following line

                             $ns at 0.0 "[$node_(0) set ragent_] hacker"

                 >  Node 0 is set as malicious. It won't forward a packet.


Packet drop in aodv ns2 ?


     >  Packet drop can be done in two ways,

                i)  drop(p) or drop(p , DROP_RTR_NO_ROUTE)

                         >  In cmu-trace.h ( ns-2.35/trace ), you can find different kind of packet drop.

                ii)  Packet::free(p)

                         >  In packet.h ( ns-2.35/common ), you can find the free() function.

                         >  Note, free() is not the same as drop(). If you use free() function to drop a packet then you cannot see a packet drop in nam.

Where can i find node's position, energy, speed and transmission range in aodv ns2 ?


   >  In mobilenode.h ( ns-2.35/common ), you can find node's position ( X & Y ) and speed.

   >  In node.h ( ns-2.35/common ), you can find the energy of a node ( energy_model() -> energy() ).

   >  In god.h ( ns-2.35/mobile ), you can find Macro variable RANGE (Transmission Range).


For more explanation, visit : http://elmurod.net/en/index.php/archives/348

Monday 30 December 2013

How can i enable Hello Packets in AODV ?


     > By default Hello Packet is not enabled. You have to enable it.

 Steps :
           i) In aodv.cc, comment the line as shown

                     //#ifndef AODV_LINK_LAYER_DETECTION
                       htimer.handle((Event*) 0);
                       ntimer.handle((Event*) 0);
                     //#endif // LINK LAYER DETECTION


 How can i change the Hello interval ?

     >  By default hello interval set to 1 second ( 1000 milli sec )

      >  In aodv.h, Macro variable HELLO_INTERVAL can be found.

How can i monitor my neighbor nodes in aodv (Promiscuous mode in aodv) ?


            >  Using tap function we can  monitor the neighbor nodes transmission.

            >  If a node forwards a packet then tap function will be called for all of its neighbors. Using this functionality we can easily find out packet drop.

            >  tap function can be found in mac.h, dsragent.h, dsragent.cc.

       
 Steps :

            >   We need to modify 3 files
                        i)  aodv.h
                        ii) aodv.cc
                        iii) ns-mobilenode.tcl ( can be found under ns-2.35/tcl/lib )

            >   In  aodv.h

                       i) Include the header file
                               #include <mac.h>
                       ii)
                           /*
                           The Routing Agent
                          */
                         class AODV: public Tap, public Agent
                        {
                          .......
                          public:
                                ........
                                void tap(const Packet *p); 
                                ........
                          protected:
                              Mac *mac_;
                                .........
                         }


            >   In aodv.cc,

                   int AODV::command(int argc, const char* const * argv )
                   {
                         .......
                        elseif( 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)
                    {
                           // Write your own code here
                    }


         >  In ns-mobilenode.tcl,

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

For more explanation visit :  http://durgeshkshirsagar.blogspot.in/2012/07/how-to-use-promiscuous-mode-in-aodv-ns2.html