Commit bf1644a0 authored by Olav Kvittem's avatar Olav Kvittem

support for Crude packet log format

parent 229b2cf4
Qstream Computes packet stream quality statistics for UDP/RTP from network or captured files(pcap)
see http://software.uninett.no/qstream
revision 3
support for Crude packet log format
......@@ -16,6 +16,7 @@ use Net::RTP;
use Net::RTP::Packet;
use Time::HiRes qw/ sleep time tv_interval gettimeofday/;
use Data::Dumper;
use Carp;
use constant MTU => 1580;
......@@ -46,7 +47,7 @@ $usage="$0 [option]... [file...|ip/|:port]...
-debug - print debugging info
-help/h this message
\n";
@opts=('list', 'fullformat', 'net', 'rtp', 'mpeg', 'pcap', 'nperiod=s', 'period=s', 'last=s', 'packets=s', 'src=s', 'flow_key=s', 'flow_no=s', 'flow_min=s', 'nohead', 'dump=s', 'format=s', 'id=s', 'sum=s', 'verbose', 'v', 'help', 'h', 'debug');
@opts=('list', 'fullformat', 'net', 'rtp', 'mpeg', 'pcap', 'crude', 'nperiod=s', 'period=s', 'last=s', 'packets=s', 'src=s', 'flow_key=s', 'flow_no=s', 'flow_min=s', 'nohead', 'dump=s', 'format=s', 'id=s', 'sum=s', 'verbose', 'v', 'help', 'h', 'debug');
&NGetOpt(@opts) || die $usage;
die $usage if $opt_h or $opt_help;
$continous= ! $opt_packets;
......@@ -64,6 +65,9 @@ my $nint=0;
my $n_packets=0;
my $endstream=0;
$SIG{USR2} = sub {confess "Caught by SIGUSR2"; };
$SIG{INT} = sub { $uninterrupted=0; # return if $nint++ < 1;
&display_stats(); die "End after interrupt.\n";exit(0) };
$SIG{KILL} = sub { $uninterrupted=0; # return if $nkill++ < 1;
......@@ -266,17 +270,49 @@ sub eat_stream {
$pcap_file=$tmp_file;
system( "/bin/zcat $f > $tmp_file") ; # rc code ? || die "Could not unpack $f to $tmp_file : $!";
}
if ($pcap=Net::Pcap::open_offline($pcap_file, \$err)){
# my $select=IO::Select->new(Net::Pcap::fileno($pcap));
until ( ! $uninterrupted || $endstream || ($opt_packets && $n_packets > $opt_packets)
|| ! (my $pkt=Net::Pcap::next($pcap, \%hdr) ) ) {
eat_pcap($f, $pcap, $pkt);
$n_packets++;
if ($opt_crude){
my $flow_key;
open CRUDE, "<", $pcap_file || die "Could not open $f : $err";
while(<CRUDE>){ # crude.sourceforge.net
if (($fid, $seq, $src, $dst, $tx, $rx, $size)=
/ID=(\d+)\s+SEQ=(\d+)\s+SRC=([\d.:]+)\s+DST=([\d.:]+)\s+Tx=([\d.,]+)\s+Rx=([\d.,]+)\s+SIZE=(\d+)/){
$flow_key="$src->$dst";
$flow_pkts{$flow_key}++;
if ($flow_pkts{$flow_key} <= 1) { # new flow
push(@flows, $flow_key); #
$flow_no++;
$file{$flow_key}=$f;
$source{$flow_key}=$src;
}
next if $opt_list; # just count packets per flow
next if $opt_flow_key && $flow_key !~ $wanted_flow;
next if $opt_flow_no && $opt_flow_no !~ /\b$flow_no\b/;
if ($flow_pkts{$flow_key} <= 1) { #
&init_stats($flow_key);
push (@myflows, $flow_key);
}
$us=($rc-$tc)*10^6; # us
&pkt_stats($flow_key, , $us, $size);
}
}
} else { # open failed
if ($format ne "full"){ # always put out data when format full
die "Could not open $f : $err";
} else {
if ($pcap=Net::Pcap::open_offline($pcap_file, \$err)){
# my $select=IO::Select->new(Net::Pcap::fileno($pcap));
until ( ! $uninterrupted || $endstream || ($opt_packets && $n_packets > $opt_packets)
|| ! (my $pkt=Net::Pcap::next($pcap, \%hdr) ) ) {
eat_pcap($f, $pcap, $pkt);
$n_packets++;
}
} else { # open failed
if ($format ne "full"){ # always put out data when format full
die "Could not open $f : $err";
}
}
}
undef $t0;
......@@ -432,7 +468,6 @@ sub init_file {
sub pkt_stats {
my $f = shift; # file or stream name
my $packet = shift;
my $rtp;
my $us = shift;
my $dlen = shift;
my $rtp = new Net::RTP::Packet();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment