Elmurod A. Talipov
8Apr/09Off

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);

void  rt_print(nsaddr_t node_id); 

Add following code to aodv.cc after void  AODV::rt_down(aodv_rt_entry *rt)

void  AODV::rt_print(nsaddr_t node_id) {
	FILE * dumpFile;
	char dumpFileName[50] = "rtable.txt";

	dumpFile = fopen(dumpFileName, 'a');

	aodv_rt_entry *rt;

	fprintf(dumpFile, "=======================================================");

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

		fprintf(dumpFile, "NODE: %i\t %.4lf\t %i\t %i\t %i\t %i\t %i\t %.4lf\t %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(dumpFile);
}

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

if (ih->daddr() == index) { // If I am the original source
  // Update the route discovery latency statistics
  // rp->rp_timestamp is the time of request origination

	rt_print(index); // print this nodes whole routing table

	rt->rt_disc_latency[(unsigned char)rt->hist_indx] = (CURRENT_TIME - rp->rp_timestamp)
                                         / (double) rp->rp_hop_count;
	// increment indx for next time
	rt->hist_indx = (rt->hist_indx + 1) % MAX_HISTORY;
}