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.


42 comments:

  1. could u let me know in ns2

    ReplyDelete
  2. @likhitha, For basics refer this link http://www.isi.edu/nsnam/ns/. To start working, http://karthicksivakrr.blogspot.in/2013/11/ns2-tips_27.html refer this link.

    ReplyDelete
  3. if i m run tcl file then

    error msg -- not define variable malicious

    ReplyDelete
  4. @rahul, can you paste the error here...?

    ReplyDelete
    Replies
    1. [root@localhost malicious]# ns mali.tcl
      num_nodes is set 22
      INITIALIZE THE LIST xListHead
      can't read "ns": no such variable
      while executing
      "$ns at 0.0 "$[n(5) set ragent_] hacker""
      (file "mali.tcl" line 221)
      [root@localhost malicious]#

      Delete
    2. @rahul, if you still have the same error, then post the tcl file.

      Delete
  5. please suggest me,
    how to provide the security aodv node. and which algorithm is better to use for security(RSA & ECC).

    i m create the malicious node in aodv.

    thanks...

    ReplyDelete
    Replies
    1. @rahul, you need to read an appropriate paper published in that domain. Both RSA and ECC has pros and cons, but you can select one, which satisfies your requirements.

      Delete
    2. thanks for suggest me,

      but i have create rsa protocol then getting some error

      ns:
      [code omitted because of length ]
      : invalid command name "Agent/rsa_packet"
      while executing
      "Agent/rsa_packet set packetSize_ 30"


      please help me...........

      Delete
    3. thanks for suggest me,

      but i have create rsa protocol then getting some error

      ns:
      [code omitted because of length ]
      : invalid command name "Agent/rsa_packet"
      while executing
      "Agent/rsa_packet set packetSize_ 30"


      please help me...........

      Delete
  6. suggest for this concept,

    Node Recognition- The first step of CSRP algorithm is to
    recognize a node. This means, the nodes in an area set by the
    third party (organization) is to be recognized by MN to know
    whether the nodes are genuine nodes or malicious nodes. For
    this, organization places a pre-computed sign S and secret key
    SK in the general nodes before placing the nodes in that area
    and it places a database of secret keys in MN. The public keys
    e, n and hash function are also placed in MN. SK is common in
    MN and general nodes. For recognition of genuine nodes by
    MN it verifies the SK first and then compute h1(SK)=Se mod n.
    If the h(SK) matches with h1(SK) then it verifies it as a genuine
    node and then MN changes the SK and places it again in the
    node. SK changes with time interval. This modification helps
    in securing the key safe.

    ReplyDelete
  7. hello.can i ask something? can u help me to fix the problem? thank you.

    -PC:~/Downloads/malicious$ ns malicious.tcl
    num_nodes is set 2
    INITIALIZE THE LIST xListHead
    Starting Simulation...
    ns: _o18 hacker:
    (_o18 cmd line 1)
    invoked from within
    "_o18 cmd hacker"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o18" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "_o18 hacker"

    ReplyDelete
    Replies
    1. i ask you that is your problem solved?? because i also facing same problem...please help me

      Delete
  8. @sazli, there is a chance for a spacing error in tcl file or aodv.cc. check it out.

    ReplyDelete
  9. ns: _o18 hacker:
    (_o18 cmd line 1)
    invoked from within
    "_o18 cmd hacker"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o18" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "_o18 hacker"
    Hi i tried this code im getting this error

    ReplyDelete
  10. @Gayathri, i guess the above comment suits you well that you did spacing error where you mentioned hacker..

    ReplyDelete
  11. i facing a problem please help me....after editing aodv.cc and aodv.h file there is error in my tcl coding..my all coding is correct...i search out many solutions on internet but it doesn't work...i write make command but it also not work am facing error in make command...please give me a solution to this problem...how i recompile my ns2 after editing??

    ReplyDelete
  12. @barinder,
    http://karthicksivakrr.blogspot.in/2013/11/ns2-tips_27.html
    http://karthicksivakrr.blogspot.in/2013/11/ns2-tips.html
    i guess, these two posts helps. You gotta run all four commands for safety. Still, If you are facing any error paste it here. Hope it helps.

    ReplyDelete
  13. i do everything but still problem occur...i think there is an error in my ns2..when i run update command then error occur of fetching..how to resolve this error??

    ReplyDelete
    Replies
    1. @barinder, can you mention the command, you have tried to update...?

      Delete
  14. Hi there I have two questions please:
    q1: where i should put the tcl file is it under ns-2.35 folder or under home directory. I appreciate if you could put yours tcl file for this exercise
    q2: after i editing aodv files I went to ns-2.35 folder and wrote make clean but it shows messeage permission denied . however, if i log as a root it compiles normally so what is the problem please.

    ReplyDelete
    Replies
    1. @Reem kadi, its always best to login as root. But the only thing that needs admin permission is "make install" command.
      Q2) Permission denied, this may be, you have installed ns2 as user. Its good practice to install ns2 as root ( now, user have access too).
      P.S : if you didn't install ns2 as root, i suggest try to install as root.

      Delete
    2. @Reem kadi,
      Q1. You can have your tcl file, anywhere in the local and you can run. But its best practice to have it under AODV. Its like all codes we need to change in the same place. But one thing is clear, you need to run "./configure" "make clean" "make" "make install" under ns-2.35 folder. Hope, it helps.

      Delete
  15. this is the error when try to compile under ns-2.35 folder:
    ./configure line 2097: config.log: Permission Denied
    ./configure line 2107: config.log: Permission Denied

    ReplyDelete
    Replies
    1. As i already mentioned @Reem kadi, you don't have access. It's clearly states permissed denied. One way to solve is, install as root.

      Delete
  16. i fix everything...now error is on runing tcl coding..when i run tcl coding of malicious node the following error occur:
    num_nodes is set 5
    warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
    INITIALIZE THE LIST xListHead
    ns: _o114 malicious:
    (_o114 cmd line 1)
    invoked from within
    "_o114 cmd malicious"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o114" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "_o114 malicious"

    ReplyDelete
  17. Hi i reinstall ns2 as a root and the problem is the same, I need to log as a root to compile files any suggestions please

    ReplyDelete
  18. Hi everybody after lots of reading I found a solution and it works but I do not know if it is a correct method or not:
    I put sudo before every command to compile like the followings:
    under ns-2.35 I wrote: sudo ./configure
    then sudo make clean , then sudo make, then sudo make install. after that everything works and I did not get the permission denied again. Am I wright please

    ReplyDelete
    Replies
    1. hi reem...i need your help..please tell me how to install ns2 as a root?? where to install it??

      Delete
  19. Hi first I log in as a root by typing sudo su
    then I follow this steps:
    http://karthicksivakrr.blogspot.in/2013/11/ns2-tips_27.html
    good luck

    ReplyDelete
  20. ya everything works well now...thnxxx to u karthick....help me in future too

    ReplyDelete
  21. How to check if a node is within the transmission range of a selected node ?

    ReplyDelete
    Replies
    1. @Vishnu, in AODV you can check its neighbour list. If we are speaking of now now, you can send a hello packet and then confirm it existence.

      Delete
  22. how i can go back to simple aodv from malicious??

    ReplyDelete
  23. @barinder, ask more specific.

    ReplyDelete
  24. can you please send me the coding of simple aodv with graphs on my email :- barinderpal.singh013@gmail.com

    ReplyDelete
  25. i need one more help...tell me how to isolate malicious node ??

    ReplyDelete
  26. @barinder, actually i missed your comment. Isolation of malicious node, its very simple. Just don't forward packets through malicious node(if its next hop); Don't accept the route(RREQ), if it has malicious node route. I believe i already discussed this one with @amatek or someone else. Look for the comments section of posts in google+.(it has detailed description). Hope it helps.

    ReplyDelete
  27. I did the same but i am getting following error..

    avinash@avinash-HP-Compaq-Elite-8300-SFF:~/Downloads$ ns aodv1.tcl
    num_nodes is set 6
    INITIALIZE THE LIST xListHead
    ns: _o39 hacker:
    (_o39 cmd line 1)
    invoked from within
    "_o39 cmd hacker"
    invoked from within
    "catch "$self cmd $args" ret"
    invoked from within
    "if [catch "$self cmd $args" ret] {
    set cls [$self info class]
    global errorInfo
    set savedInfo $errorInfo
    error "error when calling class $cls: $args" $..."
    (procedure "_o39" line 2)
    (SplitObject unknown line 2)
    invoked from within
    "_o39 hacker"

    ReplyDelete
  28. @incredible, there is an splitObject object error. Most probably spacing error. Check it out, wherever you have mentioned hacker. Hope this helps.

    ReplyDelete

Thanks & Regrds,
Karthick SIva