Tag Archives: tcl file

[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  ..