#!/usr/bin/perl -w open TRACEFILE, $ARGV[0]; @packet_numbers = (); $num_dropped = 0; $max_queue_length = 0; $num_in_queue = 0; @queue_length_hist = (); $current_queue_time = 0; while () { @fields = split; if ($fields[0] eq "r") { #received packet # if it's a packet receipt indication, save it: $packet_numbers[$#packet_numbers + 1] = $fields[11]; } elsif ($fields[0] eq "d") { #dropped packet $num_dropped++; } elsif ($fields[0] eq "+") { $queue_length_hist[$num_in_queue] += $fields[1] - $current_queue_time; $current_queue_time = $fields[1]; $num_in_queue++; if ($num_in_queue > $max_queue_length) { $max_queue_length = $num_in_queue; } } elsif ($fields[0] eq "-") { $queue_length_hist[$num_in_queue] += $fields[1] - $current_queue_time; $current_queue_time = $fields[1]; $num_in_queue--; if ($num_in_queue < 0) { exit 1; } } } @aux_packet_numbers = sort {$a <=> $b} @packet_numbers; # get arrival times: for ($k = 0; $k < $#packet_numbers + 1; $k++) { $arrival_time[$packet_numbers[$k]] = $k; } for ($i = 0; $i < ($#packet_numbers + 2) * 2; $i++) { $reorder_distances[$i] = 0; } $biggest_distance = 0; @big_packet = (-1, -1); for ($i = 0; $i < $#packet_numbers + 1; $i++) { for ($j = $i; $j < $#packet_numbers + 1; $j++) { # get j's arrival time: $distance = abs( ($i - $j) - ($arrival_time[$aux_packet_numbers[$i]] - $arrival_time[$aux_packet_numbers[$j]]) ); $reorder_distances[$distance]++; if ($distance > $biggest_distance) { $biggest_distance = $distance; @big_packet = ($aux_packet_numbers[$i], $aux_packet_numbers[$j]); } } } $queue_sum = 0.0; for ($i=0; $i < $#queue_length_hist + 1; $i++) { $queue_sum += $queue_length_hist[$i]; } $test_sum = 0.0; if ($#ARGV < 3) { printf("\n"); printf("Number of packets: %d\n", $#packet_numbers + 1 + $num_dropped); printf("Number of packets dropped: %d\n", $num_dropped); printf("Packets furthest out of order: %d and %d (out of order by %d)\n", $big_packet[0], $big_packet[1], $biggest_distance); printf("Longest queue length during simulation: %d\n", $max_queue_length); for ($i=0; $i < $#queue_length_hist + 1; $i++) { printf("Percent of time at length %d: %f\n", $i, $queue_length_hist[$i] / $queue_sum); $test_sum += $queue_length_hist[$i] / $queue_sum; } printf("Sum of queue length times: %f (check: %f)\n", $queue_sum, $test_sum); printf("\n"); } else { open STAT, ">$ARGV[3]"; printf(STAT "\n"); printf(STAT "Number of packets: %d\n", $#packet_numbers + 1 + $num_dropped); printf(STAT "Number of packets dropped: %d\n", $num_dropped); printf(STAT "Packets furthest out of order: %d and %d (out of order by %d)\n", $big_packet[0], $big_packet[1], $biggest_distance); printf(STAT "Longest queue length during simulation: %d\n", $max_queue_length); for ($i=0; $i < $#queue_length_hist + 1; $i++) { printf(STAT "Percent of time at length %d: %f\n", $i, $queue_length_hist[$i] / $queue_sum); $test_sum += $queue_length_hist[$i] / $queue_sum; } printf(STAT "Sum of queue length times: %f (check: %f)\n", $queue_sum, $test_sum); printf(STAT "\n"); } if ($#ARGV >= 1) { if ($ARGV[1] eq "y") { if ($#ARGV < 2) { for ($i=0; $i < $#reorder_distances + 1; $i++) { printf "$i:$reorder_distances[$i]\n"; } } else { open REORDER, ">$ARGV[2]"; for ($i=0; $i < $#reorder_distances + 1; $i++) { printf REORDER "$i:$reorder_distances[$i]\n"; } close REORDER; } } } #for ($i=0; $i < $#packet_numbers + 1; $i++) { # print "$packet_numbers[$i]\n"; #}