Monday, 17 June 2013

How to print Routing table of each node in NS2

You need to pass node id as an argument to this method.
e.g. in aodv.cc withing rt_resolve() method,

rt_print(0);

This will print node 0's routing table at that time with file name as node_0.

void AODV::rt_print(nsaddr_t node_id)
{
    FILE * tmpFile;
    char tmpFileName[50] = "node_";
    char tmp[10] = "";
    sprintf(tmp,"%d",node_id);
    strcat(tmpFileName,tmp);   
    tmpFile = fopen(tmpFileName, "w");

    aodv_rt_entry *rt;   

    for (rt = rtable.head(); rt; rt = rt->rt_link.le_next)
    {

        fprintf(
            tmpFile,
            "Node Id:%i Current time:%.4lf Destination:%i Next hop:%i No. of hops:%i Seq. No.:%i Route expire:%f Flags:%.4lf %d \n",
            node_id, CURRENT_TIME, rt->rt_dst, rt->rt_nexthop, rt->rt_hops,rt->rt_seqno, rt->rt_expire, rt->rt_flags);
    }

    fclose(tmpFile);
}




All the Best!

17 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Replies
    1. can you post a blog on detecting the malicious node in network using ns2.34 with code or please mail me the explanation or the code plz
      mail address : anand.tripathi507@gmail.com

      Delete
  3. Can you please explain in detail .how 2 print routin table.Its ll really help me.Thanks in Advance

    ReplyDelete
  4. hello Mr , how can i access to node_id and this variable is declared as protected in the file Node.h , is there any solution to do that ?

    ReplyDelete
  5. where will the print statement in .cc file printed?

    ReplyDelete
    Replies
    1. you can use rt_print(index) in anywhere in aodv.cc as you like. For eg,u can use it in recvReply fun after update routing table or if (ih->daddr() == index) ... something like that.

      Delete
  6. hi i am gaurav

    i want to print current node id in to comman/ttl.cc file how can i
    ?

    ReplyDelete
  7. Can u please mail me codes of aodv modified with watchdog in ns2
    So it'll be a great help from U...
    thx

    ReplyDelete
  8. could u let us complete demo on ur above created routing table

    ReplyDelete
  9. we are doing on same one,.............can we have brief xplanation on routing table

    ReplyDelete
  10. Sir, I want to isolate the malicious node. Can you please tell me how can I do that?
    Please mail at ghodeswarekta@yahoo.in

    ReplyDelete
  11. Dear sir, I am using ns2-2.35 version. In TCL script when i define the energy model, all the nodes will be in green color. Can that be changed to any other color? (not dynamically in tcl). If so, pls explain me how.
    My mail id: ruthvicsakre@gmail.com

    ReplyDelete
  12. can you please tell me how to give IDs to the nodes

    ReplyDelete
  13. i m getting error in make command,,.. pls help me..

    ReplyDelete
  14. i m getting error in make command,,.. pls help me..

    ReplyDelete
  15. can you post a blog on detecting the malicious node in network using ns2.34 with code or please mail me the explanation or the code plz
    mail address : anand.tripathi507@gmail.com

    ReplyDelete