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