[How To] Display Routing Table of AODV in ns-2.34

Hi Folks,

In this post I shall tell about how to display routing table of nodes while using AODV protocol. I read various tutorials online but most of them failed to exactly display the routing tables or were unable to exactly specify where to put the print_routing_table() function. And by using these methods I kept getting segmentation faults or huge files displaying routing tables even when the node count was 5 with only 1 traffic source. However i have used some of those tutorials and modded them to work fine “cuz u know no one writes code from scratch”. My grandfather did that and he is old by now.

Let’s begin:

Step 1) Open file aodv_rtable.h . Go to class aodv_rtable and in its public scope declare a member function

void rt_display(nsaddr_t id);

Step 2) Open file aodv_rtable.cc . Go to end and type this (read copy-paste 🙂 )

void
aodv_rtable::rt_display(nsaddr_t id)
{
FILE *dumpFile;
dumpFile = fopen("rtable.txt", "a+");
aodv_rt_entry *rt = rthead.lh_first;
for(; rt; rt = rt->rt_link.le_next) {
// You can add more route table entries if you want to. See aodv_rtable.h for more entries.
fprintf(dumpFile, "NODE: %d \t %f \t %d \t %d \t %d \t %d \t %.4f \t %d \n", id, CURRENT_TIME,
rt->rt_dst, rt->rt_nexthop, rt->rt_hops, rt->rt_seqno, rt->rt_expire, rt->rt_flags);
}
fclose(dumpFile);
}

Step 3) (Important One) Open file aodv.cc . Go to the function
AODV::rt_update(aodv_rt_entry *rt, .... )

At the end of inside this function call the rt_display() function as:

rtable.rt_display(index);

Step 4) Compile using make and sudo make install inside the ns-2.34 directory.

Step 5) run your tcl file (here is the file if u want to test). The rtable.txt should look like this rtable.txt  ..

30 thoughts on “[How To] Display Routing Table of AODV in ns-2.34

  1. Stephen raj

    Hi, i was past the (Display Routing Table of AODV in ns-2.34) command to my system, it works properly. But rtable.txt does not create. suggest me how to print routing table.
    Its urgent plz……….

    Reply
    1. metagoth Post author

      that has nothing to with printing of routing table. I had just added some code to print simple network statistics and i was calling it from the tcl file.

      Reply
      1. vidhyaravidhya

        Thanks for the reply… But where have you added that print-stats function? whether in aodv.cc or somewhere else?? Also please let me know if it is possible to call a function (my own function) i ‘ve written in aodv.cc from my tcl file… if so, how to make that call?

  2. madhu

    I tried these steps in ns2.33. No where its creating rtable.txt. plz help me! And i also want to create a txt file to print the path btwn source and destination.

    Reply
  3. Gaju

    Hello,

    I need to print all neighbor of the node in aodv protocol. I have tried above procedure but the file is not created. And i have also tried rt->rt_nexthop gives only one next hop node. Please
    Please help me….

    Reply
  4. remas

    it works with me you should re make to save changes you’ve done by typing the following commands in ns2 directory in terminal “sudo make clean, sudo make , sudo make install” each one ata atime best wishes

    Reply
  5. Vineela

    I have followed all the above steps in ns2.35 but i am unable to find the table.txt file please help me . I have a doubt in step 4 like we can run our .tcl code (ns simple-aodv.tcl) to get that table.txt file.

    Reply
  6. reetika chib

    i have followed all the steps properly, but still m not getting “rtable.txt” file neither in the home directory nor in the folder containing the script. plzzz do suggest me the solution its urget

    Reply
  7. subhashsingh

    can you tell me what is the procedure of Display Routing Table of DSR in ns-2.35.
    it’s urgent.
    thanks in advance!!!!

    Reply
  8. Divyam

    Thanks for the post.
    Can you tell me how to print residual energy of each node in the generated routing table?

    Reply

Leave a comment