#! /usr/local/bin/perl # packet and byte percentiles by source host # oc32bysrc.pl oc3filename interface {deltatime} # # output format: # #time packs bytes hosts packet host percs byte host percs # 5 10 25 50 75 90 95 5 10 25 50 75 90 95 #10 13260 43696456 1825 : 1 2 4 25 197 665 1162 : 1 2 3 9 60 215 380 : # $|=1; $percarray{0}=0.05; $percarray{1}=0.10; $percarray{2}=0.25; $percarray{3}=0.50; $percarray{4}=0.75; $percarray{5}=0.90; $percarray{6}=0.95; $maxperc=6; # number of percentiles-1 # Parameters: $fname = $ARGV[0]; # Input file name $if = $ARGV[1]; # requested interface $deltatime = $ARGV[2]; # delta time for results if($deltatime == 0) {$deltatime = 1;} # default 1 sec. open(infile,$ARGV[0]) || die("Can't open input file\n"); # skip header while(read(infile,$record,512)){ $cellcount=vec($record,2,8)*256+vec($record,3,8); $interface=vec($record,4,8)*256+vec($record,5,8); # printf stderr "$interface\t$cellcount\n"; # Start reading in entries for ($i = 1; $i <= 17408; $i++) { read(infile,$record,60) || exit; if($i > $cellcount){next;} if(($if > 0) && ($if != $interface)){next;} if(vec($record,18,8) == 0x08){ $ts1= vec($record,0,8); $ts2= vec($record,1,8); $ts3= vec($record,2,8); $ts4= vec($record,3,8); $ts5= vec($record,4,8); $ts6= vec($record,5,8); $timestamp1=($ts1<<8)+$ts2; $timestamp2=($ts3<<24)+($ts4<<16)+($ts5<<8)+$ts6; $timestamp=0.00000004*(($timestamp1*2^32)+$timestamp2); if($oldtimestamp == 0){$oldtimestamp=$timestamp;$starttime=$timestamp;} $srch = vec($record,8,32); $plen = vec($record,22,8)*256+vec($record,23,8); $hpc{$srch}++; $hbc{$srch}=$hbc{$srch}+$plen; $pcount++; $bcount=$bcount+$plen; # if(($timestamp > ($oldtimestamp+$deltatime)) || ($timestamp < $oldtimestamp)){ if($timestamp > ($oldtimestamp+$deltatime)){ foreach $key ( keys %hpc) {$hc++;} printf"%.3f\t%.3f\t%.3f\t%d\t:",$timestamp-$starttime,$pcount/1000,$bcount*8/1000000,$hc; $pac=0; foreach $key ( sort pnumerically ( keys %hpc)) { $lpc=$lpc+$hpc{$key}; $lphc++; if($lpc >= $pcount*$percarray{$pac}){ printf "\t%d",$lphc; if($pac++ == $maxperc){printf"\t:";last;} } } $pac=0; foreach $key ( sort bnumerically ( keys %hbc)) { $lbc=$lbc+$hbc{$key}; $lbhc++; if($lbc >= $bcount*$percarray{$pac}){ printf "\t%d",$lbhc; if($pac++ == $maxperc){printf"\t:";last;} } } printf"\n"; $oldtimestamp=$timestamp; $pcount=0; $bcount=0; $hc=0; $lpc=0;$lphc=0; $lbc=0;$lbhc=0; undef %hpc;undef %hbc; } } } } sub pnumerically { $hpc{$b} <=> $hpc{$a};} sub bnumerically { $hbc{$b} <=> $hbc{$a};}