Hi I found ready java code to calculate the statistics like Packet delivery ratio, Routing overhead(packets & bytes), average end-to-end delay. I am attaching the file below.
import java.util.*; import java.lang.*; import java.io.*; //Usage: java parsetrace inputfile(tr file) outputfile public class parsetrace1 { public static void main (String args[]) { String s, thisLine, currLine,thisLine1; int j=0; FileInputStream fin,fin1; FileOutputStream fout,fout1; final int FILES = 1;//45; final int MAX_PACKETS = 800000; System.out.println(args[0]+" "+args[1]); try { int i=0, sends=0, receives=0; int drops=0,packet_id=0, highest_packet_id = 0; int line_count=0,current_line=0, routing_packets=0; int count=0; float pdfraction, time=0, packet_duration=0, end_to_end_delay=0; float avg_end_to_end_delay=0; float start_time[] = new float[MAX_PACKETS]; float end_time[] = new float[MAX_PACKETS]; float sent_packets[] = new float[MAX_PACKETS]; float received_packets[] = new float[MAX_PACKETS]; String tokens[] = new String[100]; // initialize the start time for (i=0; i<MAX_PACKETS ; i++) start_time[i] = 0; fout =new FileOutputStream (args[1]); DataOutputStream op = new DataOutputStream(fout); for (int h=0;h<FILES;h++) { j=0; sends=0; receives=0; routing_packets=0; highest_packet_id = 0; end_to_end_delay=0; for (i=0; i<MAX_PACKETS ; i++) { start_time[i] = 0; end_time[i]=0;} fin = new FileInputStream (args[0]); DataInputStream br = new DataInputStream(fin); while ((thisLine = br.readLine()) != null) { // scan it line by line java.util.StringTokenizer st = new java.util.StringTokenizer(thisLine, " "); i=0; while(st.hasMoreElements()) tokens[i++]= st.nextToken(); if (tokens[0].equals("s") || tokens[0].equals("r")|| tokens[0].equals("f")) { // parse the time if (tokens[1].equals("-t")) time = Float.valueOf (tokens[2]).floatValue(); // parse the packet_id if (tokens[39].equals("-Ii")) packet_id = Integer.valueOf(tokens[40]).intValue(); /// calculate the sent packets if (tokens[0].equals("s")&&tokens[18].equals("AGT")&&tokens[34].equals("cbr")) sends++; // find the number of packets in the simulation if (packet_id >highest_packet_id) highest_packet_id = packet_id; // set the start time, only if its not already set if (start_time[packet_id] == 0) start_time[packet_id] = time; // calculate the receives and end-end delay if (tokens[0].equals("r") && tokens[18].equals("AGT") && tokens[34].equals("cbr")) { receives++; end_time[packet_id] = time; } else end_time[packet_id] = -1; // calculate the routing packets if ((tokens[0].equals("s") || tokens[0].equals("f")) && tokens[18].equals("RTR") && (tokens[34].equals("AODV") || tokens[34].equals("EAODV") )) routing_packets++; } } // calculate the packet duration for all the packets for (packet_id = 0; packet_id <= highest_packet_id ; packet_id++) { packet_duration = end_time[packet_id] - start_time[packet_id]; if (packet_duration >0) end_to_end_delay += packet_duration; } // calculate the average end-end packet delay avg_end_to_end_delay = end_to_end_delay / (receives ); // calculate the packet delivery fraction pdfraction = ((float)receives/(float)(sends))*100; System.out.println(" \nsends "+sends); System.out.println(" receives "+receives); System.out.println(" routing overhead (packets) "+ routing_packets); System.out.println(" Normalized routing load "+(float)routing_packets/(float)receives); System.out.println(" Packet Delivery fraction " +pdfraction); System.out.println(" Avg End-End delay " +avg_end_to_end_delay); op.writeBytes(" " +sends); op.writeBytes(" "+receives); op.writeBytes(" "+ routing_packets); op.writeBytes(" "+(float)routing_packets/(float)receives); op.writeBytes(" " +pdfraction); op.writeBytes(" " +avg_end_to_end_delay); op.writeChar('\n'); } } catch (Exception e) { e.printStackTrace(); } } } Note: It assumes trace file in new_trace format. Hope , it will be useful.... Regards Anupama A