Monthly Archives: July 2013

[AWK Script] An Awk Script to Print Network Statistics

Image

Hi Folks,

In this post I, shall give u an awk file I wrote that prints several network statistics of interest (these are of course the basic ones cuz i ain’t that good at statistics). Being fed up with lots of awk files floating on the net and most of them don’t work or work on old trace formats of ns-2.34. So I planned to write my own awk script for my simulations.

[ AWK FILE SCRIPT DOWNLOAD]

This awk script i wrote is for 50 nodes and by minor modifications it can be changed to any no. I have used it for 150 nodes. The statistics u can calculate with this file are:

  • Total Packets Sent
  • Total Packets Received
  • Total Packets Dropped
  • Total Packets Forwarded
  • Packet Delivery Ratio %
  • The total hop counts are
  • Average Hop Count
  • Routing Overhead
  • Normalized Routing Load
  • Througphut of the network (KBps)
  • Average End to End Delay
  • Total Energy Consumed
  • Protocol Energy Consumption

Some of these metrics I have calculated using the above shown image. However energy consumption metrics have been calculated by me. When u run this awk script using the command :

awk -f statistics.awk xyz.tr   (xyz.tr is your trace file name)

statistics.awk creates 5 files (which contain info related with each node) in your directory they are:

  • energyleft.txt
  • pktdrop.txt
  • pktfwd.txt
  • pktrecvd.txt
  • pktsent.txt

Note:- This statistics.awk file was made for 50 nodes. However in the awk file i have put comments so as to where u need to make changes in order to run it for any number of nodes.

My view:- I wrote it according to my own logic and understanding however some logic may be wrong or may not be optimal or may be very time consuming. If any suggestions are there for improving this code. Please suggest. Thanks

Let’s support the research community by sharing our code and not hiding it.

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