Sunday, 2 November 2014

NS2: Printing Routing Table in AODV

Actually you can find all this information in trace file which NS2 made, however using following code simplifies getting required informaiton during running time. The code stores

Add following code to aodv.h after void rt_down(aodv_rt_entry *rt);
1void  rt_print(nsaddr_t node_id);
Add following code to aodv.cc after혻void혻 AODV::rt_down(aodv_rt_entry *rt)
1void  AODV::rt_print(nsaddr_t node_id) {
2    FILE * dumpFile;
3    char dumpFileName[50] = "rtable.txt";
4 
5    dumpFile = fopen(dumpFileName, 'a');
6 
7    aodv_rt_entry *rt;
8 
9    fprintf(dumpFile, "=======================================================");
10 
11    for (rt=rtable.head();rt; rt = rt->rt_link.le_next) {
12 
13        fprintf(dumpFile, "NODE: %it %.4lft %it %it %it %it %it %.4lft %d n", node_id, CURRENT_TIME, rt->rt_dst, rt->rt_nexthop, rt->rt_hops, rt->rt_seqno, rt->rt_expire, rt->rt_flags)
14 
15    }
16 
17    fclose(dumpFile);
18}
The function (rt_print) can be used anywhere in AODV. For example, I am using the function, when route request generated혻node receives route reply message (RREP).

1if (ih->daddr() == index) { // If I am the original source
2  // Update the route discovery latency statistics
3  // rp->rp_timestamp is the time of request origination
4 
5    rt_print(index); // print this nodes whole routing table
6 
7    rt->rt_disc_latency[(unsigned char)rt->hist_indx] = (CURRENT_TIME - rp->rp_timestamp)
8                                         / (double) rp->rp_hop_count;
9    // increment indx for next time
10    rt->hist_indx = (rt->hist_indx + 1) % MAX_HISTORY;
11}

No comments:

Post a Comment