Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
java --> <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859 -1"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">impo rt java.io.*; import java.util.*; public class Stats { // ========================================================================== public static void main( String[] args ) { if( args.length < 2 args.length > 4 ) usage(); // .. variabledeclarations ..............................................., BufferedReader f; // file-handler String line; // actual line from file StringTokenizer st; // splits the colums of a line String[] word = new String[6]; // stores split tokens int int int int int int totRcvd = 0; totLost = 0; curQLen = 0; totQLen = 0; counter = 0; interval = 1; // // // // // // total received packets total lost packets current queue length total queue length counts the number of intervals size of an measure-interval
double avgQLen; // average queue length double newTStamp; // actual time-stamp double oldTStamp = 0; // last time-stamp // ........................................................................ try { f = new BufferedReader( new FileReader( args[0] ) ); while( ( line = f.readLine() ) != null ) { st = new StringTokenizer( line, " " ); // split split columns of a line for( int i = 0; st.hasMoreTokens() && i < 6; i++ ) word[i] = st.nextToken(); // save token into an array /* word[0]: event ('r': receive, '+': enqueue, '-': dequeue, 'd': drop) word[1]: actual time (timestamp) word[4]: packet type word[5]: packet size */ if( args.length < 3 word[3].equals( args[2] ) ) { if( args.length < 4 word[2].equals( args[3] ) ) { // accumulate received and dropped packets if( word[4].equals( args[1] ) && word[0].equals( "r" ) ) totRcvd += Integer.parseInt( word[5] ); if( word[4].equals( args[1] ) && word[0].equals( "d" ) ) totLost += Integer.parseInt( word[5] ); // count enqued and dequeued packets if( word[0].equals( "+" ) ) curQLen++;
if( word[0].equals( "-" ) newTStamp = Double.valueOf( if( ( newTStamp - oldTStamp { totQLen += curQLen; // counter++; // oldTStamp = newTStamp; // } } }
word[0].equals( "d" ) ) curQLen--; word[1] ).doubleValue(); ) >= interval ) accumulate total queue length increase counter save actual timestamp as last timestamp
} f.close(); //System.out.println( curQLen + " -- " + totQLen ); } catch( IOException e ) { System.out.println( "file " + args[0] + " not found." ); } // calculate avarage length of the queue avgQLen = ( double )totQLen / counter; // print statistics System.out.println( "Total Received:\t\t" + totRcvd ); System.out.println( "Total Lost:\t\t" + totLost ); System.out.println( "Average Queue Length:\t" + avgQLen ); } // -------------------------------------------------------------------------public static void usage() { System.err.println( "Stats:\t\tprint statistis of a nam-tracefile" ); System.err.println( "Usage:\t\tjava Stats file.tr type [scr [dst]]" ); System.err.println( "Example types:\ttcp, ack, udp, cbr" ); System.exit( -1 ); } // ========================================================================== }</pre></body></html>