Created
January 11, 2013 16:17
-
-
Save sulrich/4511903 to your computer and use it in GitHub Desktop.
parse stream information from spirent (dealing with the foible associated with their horked address encoding) and generate some useful stats around a particular traffic stream. particularly useful for instrumentation of large MPLS-TE tunnel blocks and doing failure analysis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# -*- mode: cperl; c-basic-offset: 2; indent-tabs-mode: nil -*- | |
use Statistics::Descriptive; | |
#fields within the output file | |
# 00 - Rx Port Name | |
# 01 - Comp32 | |
# 02 - Comp16_1 (src_addr lt) - the following four fields need to be merged into | |
# 03 - Comp16_2 (src_addr rt) a valid IP addrss | |
# 04 - Comp16_3 (dst_addr lt) | |
# 05 - Comp16_4 (dst_addr rt) | |
# 06 - Stream Index | |
# 07 - Rx Count (Frames) | |
# 08 - Sequence Run Length | |
# 09 - Dropped Frame Count(per stream) | |
# 10 - Dropped Frame Percent(per stream) | |
# 11 - In-order Count (Frames) | |
# 12 - Reordered Frame Count | |
# 13 - Duplicate Frame Count | |
# 14 - Late Frame Count | |
open (INFILE, "<$ARGV[0]") || die "ERROR: opening $ARGV[0]\n"; | |
my $stat = Statistics::Descriptive::Full->new(); | |
while (<INFILE>) { | |
my @stream = split(',', $_); | |
next if $#stream <= 1; # skip the cruft lines in the input file. | |
next if $stream[11] <= 0; # skip stale stream entries | |
my $lt1 = int2addr($stream[2]); | |
my $rt1 = int2addr($stream[3]); | |
my $src_addr = join('.', $lt1, $rt1); | |
my $lt2 = int2addr($stream[4]); | |
my $rt2 = int2addr($stream[5]); | |
my $dst_addr = join('.', $lt2, $rt2); | |
$stat->add_data($stream[9]); # dropped frame counter | |
} | |
close(INFILE); | |
print " count: " . $stat->count() . "\n"; | |
print " min: " . $stat->min() . "\n"; | |
print " max: " . $stat->max() . "\n"; | |
print " mean: " . $stat->mean() . "\n"; | |
print " sum: " . $stat->sum() . "\n"; | |
print "std dev: " . $stat->standard_deviation() . "\n"; | |
sub int2addr() { | |
my ($int) = @_; | |
# yes, i realize there's probably some (un)pack() leetness i'm missing here, | |
# but this is good enough | |
my $packed_hex = sprintf("%02x", $int); | |
my $addr = join ('.', hex substr($packed_hex, 0, -2), hex substr($packed_hex, -2)); | |
return $addr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment