Commit 966d63d1 authored by paalmm's avatar paalmm
Browse files

changes in -pcap offline. Empty files gets initialized with 0 value

parent 43bffb13
...@@ -43,7 +43,7 @@ my ($rtmp,$period,$last,$debug,$swfurl,$pageurl,$flash_version,$reconnect); ...@@ -43,7 +43,7 @@ my ($rtmp,$period,$last,$debug,$swfurl,$pageurl,$flash_version,$reconnect);
require "newgetopt.pl"; require "newgetopt.pl";
@opts=('list', 'man','fullformat', 'net', 'rtp', 'mpeg', 'pcap', 'crude', 'bins=s', 'log', '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', 'ttl', 'rtt=s', 'codec=s', 'log', 'verbose', 'v', 'h', 'debug', 'av','xml=s', 'rtmp','tcp', 'port=s','swfurl=s','pageurl=s','flashversion=s','new','q','exclude=s','report=s', 'filename'); @opts=('list', 'man','fullformat', 'net', 'rtp', 'mpeg', 'pcap', 'crude', 'bins=s', 'log', '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', 'ttl', 'rtt=s', 'codec=s', 'log', 'verbose', 'v', 'h', 'debug', 'av','xml=s', 'rtmp','tcp', 'port=s','swfurl=s','pageurl=s','flashversion=s','new','q','exclude=s','report=s', 'filename','test');
&NGetOpt(@opts) || die pod2usage(1); &NGetOpt(@opts) || die pod2usage(1);
die pod2usage(1) if $opt_h; die pod2usage(1) if $opt_h;
...@@ -78,6 +78,7 @@ my $xml; ...@@ -78,6 +78,7 @@ my $xml;
my $xml_printed= 0; my $xml_printed= 0;
my $last_stream; my $last_stream;
my $file_flag; my $file_flag;
my $offline;
#TCP STUFF #TCP STUFF
my $thr; my $thr;
...@@ -149,6 +150,7 @@ $SIG{INT} = sub { $uninterrupted=0; # return if $nint++ < 1; ...@@ -149,6 +150,7 @@ $SIG{INT} = sub { $uninterrupted=0; # return if $nint++ < 1;
&display_stats(); &display_stats();
&end_xml() if $opt_xml; &end_xml() if $opt_xml;
&handle_threads() if ($opt_tcp and $opt_rtmp); &handle_threads() if ($opt_tcp and $opt_rtmp);
die "End after interrupt.\n";exit(0) }; die "End after interrupt.\n";exit(0) };
$SIG{KILL} = sub { $uninterrupted=0; # return if $nkill++ < 1; $SIG{KILL} = sub { $uninterrupted=0; # return if $nkill++ < 1;
&display_stats(); die "End after kill.\n";exit(0) }; &display_stats(); die "End after kill.\n";exit(0) };
...@@ -166,16 +168,17 @@ $SIG{ALRM} = sub { ...@@ -166,16 +168,17 @@ $SIG{ALRM} = sub {
if ($opt_dump){ if ($opt_dump){
open DUMP, ">$opt_dump"; open DUMP, ">$opt_dump";
} }
&unit_test if $opt_test;
if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell
alarm($opt_last) if $opt_last; alarm($opt_last) if $opt_last;
$uninterrupted=1; $uninterrupted=1;
$endstream=0; $endstream=0;
eat_pcap_streams(@streams); eat_pcap_streams(@streams);
&display_stats() if !$opt_xml; &display_stats() if !$opt_xml;
} else { # listen serially } else { # listen serially
my $stream_count; my $stream_count;
my $ln = @streams; my $ln = @streams;
foreach $id (@streams) { foreach $id (@streams) {
alarm($opt_last) if $opt_last; alarm($opt_last) if $opt_last;
++$stream_count; ++$stream_count;
...@@ -186,12 +189,13 @@ if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell ...@@ -186,12 +189,13 @@ if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell
init_file($id); init_file($id);
eat_stream($id) if (!($opt_tcp || $opt_rtmp)); eat_stream($id) if (!($opt_tcp || $opt_rtmp));
&rtmp_eat_stream($id,$opt_period, $opt_last,0,$opt_debug,$opt_swfurl,$opt_pageurl,$opt_flashversion) if $opt_rtmp; &rtmp_eat_stream($id,$opt_period, $opt_last,0,$opt_debug,$opt_swfurl,$opt_pageurl,$opt_flashversion) if $opt_rtmp;
&eat_tcp($id,$opt_port) if $opt_tcp && !$opt_rtmp; #&eat_tcp($id,$opt_port) if $opt_tcp && !$opt_rtmp;
if (! ( $opt_list || $opt_sum)){ if (! ( $opt_list || $opt_sum)){
&display_stats() if !$endstream; &display_stats() if !$endstream;
} }
last if ! $uninterrupted; last if ! $uninterrupted;
} }
} }
&list_flows if $opt_list; &list_flows if $opt_list;
&display_stats() if $opt_sum; &display_stats() if $opt_sum;
...@@ -199,6 +203,80 @@ if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell ...@@ -199,6 +203,80 @@ if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell
&end_xml() if $opt_xml; &end_xml() if $opt_xml;
exit(0); exit(0);
#
sub unit_test {
my $test_data = shift;
#streams = "rtp_158.38.130.110_6711_1.pcap";
@streams = "testing/testdata_mpeg.pcap" if $opt_mpeg;
@streams = "testing/testdata_rtp.pcap" if $opt_rtp;
#@streams = "testing/testdata_tcp.pcap";
$opt_xml = "tmp_testdata.xml";
$opt_q = 1;
$opt_v = 1;
}
sub unit_test_2{
#my ($orgnial_test) = &feed_data("file",rtp_file.xml);
my $test_data;
$test_data = "mpeg_testdata.xml" if $opt_mpeg;
$test_data = "rtp_testdata.xml" if $opt_rtp;
#$test_data = "udp_testdata" if $opt_net;
$test_data = "tcp_testdata_" if $opt_tcp;
my ($orginal_test) = &xml_parser($test_data);
my ($new_test) = &xml_parser("tmp_testdata.xml");
print Dumper($orginal_test), "\n", Dumper($new_test)if $opt_debug;
my $ignore_pattern = "jitter"; #PCR jitter is based on delta local time.
for my $k1(keys %$orginal_test){
if ($orginal_test->{ $k1} != $new_test->{ $k1} and $orginal_test->{ $k1} !~ m/HASH/) {
print "fail @ $k1, value: $orginal_test->{$k1} unlike value: $new_test->{$k1}\n";
}
for my $k2 ( keys %{$orginal_test->{ $k1}} ) {
if ( ($orginal_test->{ $k1}{$k2} != $new_test->{ $k1}{$k2}) and ($k2 !~ m/$ignore_pattern/)){
print "fail @ $k1-> $k2, value: $orginal_test->{ $k1}{$k2} unlike value: $new_test->{ $k1}{$k2} \n";
}
}
}
}
sub xml_parser {
my $file = shift;
my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ($file);
my $root = $doc->getFirstChild();
my $nodelist = $root->getChildNodes();
my $node = $nodelist->item(1);
my $dup;
my $flow_childs = $node->getChildNodes();
my @test_array = ();
my %test_hash = ();
foreach my $child ($node->getChildNodes()) {
if ($child->getNodeType == ELEMENT_NODE) {
if ($child->getChildNodes()){
my @children = $child->getChildNodes();
my $l = @children;
if ($l > 1){
#print "=== " ,$child->getNodeName(), " === \n";
if (exists $test_hash{$child->getNodeName()}){
$dup +=1;
}
foreach my $grandchild ($child->getChildNodes()){
if ($grandchild->getNodeType == ELEMENT_NODE){
#print $grandchild->getNodeName(), "\n";
eval {
$test_hash{$child->getNodeName().$dup}{$grandchild->getNodeName()}= $grandchild->getFirstChild()->getData();
};
if ($@){
};
}
}
}
else {
$test_hash{'flow'}{$child->getNodeName()} = $child->getFirstChild()->getData();
}
}
}
}
return (\%test_hash)
}
sub http_stream_client { sub http_stream_client {
my $f = shift; my $f = shift;
...@@ -256,17 +334,20 @@ sub end_xml{ ...@@ -256,17 +334,20 @@ sub end_xml{
$doc->dispose; $doc->dispose;
close (MYFILE); close (MYFILE);
$xml_printed = 1; $xml_printed = 1;
&unit_test_2($filename) if $opt_test;
} }
sub tcp_packet_stats { sub tcp_packet_stats {
my ($pkt) = @_; my $f = shift;
my ($pkt) = shift;
my $us = shift;
my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); my $ip_obj = NetPacket::IP->decode(eth_strip($pkt));
my $tcp_obj = NetPacket::TCP->decode(ip_strip(eth_strip($pkt))); my $tcp_obj = NetPacket::TCP->decode(ip_strip(eth_strip($pkt)));
my $us = 0; #my $f = $ip_obj->{src_ip}.":".$tcp_obj->{src_port} if !$offline;
my $f = $ip_obj->{src_ip}.":".$tcp_obj->{src_port};
my $seq_num = $tcp_obj->{seqnum}; my $seq_num = $tcp_obj->{seqnum};
my $options = $tcp_obj->{options}; #12 bytes my $options = $tcp_obj->{options}; #12 bytes
if (!exists $tcp_packet_stats{$f}){ if (!exists $tcp_packet_stats{$f}){
&init_stats($f);
$tcp_packet_stats{$f} = &share( {} ); $tcp_packet_stats{$f} = &share( {} );
$seq_stats{$f} = &share( {} ); $seq_stats{$f} = &share( {} );
$seq_stats_n{$f} = &share( {} ); $seq_stats_n{$f} = &share( {} );
...@@ -275,23 +356,24 @@ sub tcp_packet_stats { ...@@ -275,23 +356,24 @@ sub tcp_packet_stats {
$tcp_packet_stats{$f}{'pkt_dup'} = 0; $tcp_packet_stats{$f}{'pkt_dup'} = 0;
} }
++$tcp_packet_stats{'num_packets'}; print $tcp_packet_stats{$f}{'num_packets'}, "\n";
++$tcp_packet_stats{$f}{'num_packets'}; ++$tcp_packet_stats{$f}{'num_packets'};
$tc=[gettimeofday]; # current flow time #$tc=[gettimeofday]; # current flow time
if( $t0){ # if( $t0){
$elapsed=tv_interval ( $t0, $tc); # $elapsed=tv_interval ( $t0, $tc);
} else { # } else {
$t0 = $tc; # $t0 = $tc;
$elapsed=0.0; # $elapsed=0.0;
&init_stats($cur_id); # &init_stats($cur_id);
} # }
$us=$elapsed*10**6; # $us=$elapsed*10**6;
&tcp_jitter_stats($f,$options); &tcp_jitter_stats($f,$options);
#Bandwidth messurements #Bandwidth messurements
&pkt_stats($f, $tcp_obj->{data}, $elapsed * 10**6, $ip_obj->{'len'}); &pkt_stats($f, $tcp_obj->{data}, $us, $ip_obj->{'len'});
$tcp_packet_stats{$f}{'num_bytes'} += $ip_obj->{'len'}; #counts the bytes $tcp_packet_stats{$f}{'num_bytes'} += $ip_obj->{'len'}; #counts the bytes
#Check for duplicated,out-of-order, late and lost packets. #Check for duplicated,out-of-order, late and lost packets.
$seq_stats{$f}{'seq_diff'} = $seq_num - $seq_stats{$f}{'p_seq_num'}- $seq_stats{$f}{'p_packet_len'}; $seq_stats{$f}{'seq_diff'} = $seq_num - $seq_stats{$f}{'p_seq_num'}- $seq_stats{$f}{'p_packet_len'};
print $seq_stats{$f}{'seq_diff'}, "\n", if $opt_debug;
if ($seq_stats_n{$f}{'seq_num_p'} == $seq_num && $seq_stats{$f}{'p_seq_num'} != 0) { if ($seq_stats_n{$f}{'seq_num_p'} == $seq_num && $seq_stats{$f}{'p_seq_num'} != 0) {
++$tcp_packet_stats{$f}{'pkt_dup'}; ++$tcp_packet_stats{$f}{'pkt_dup'};
} }
...@@ -507,7 +589,6 @@ sub eat_stream { ...@@ -507,7 +589,6 @@ sub eat_stream {
} }
while ($uninterrupted && !($opt_packets && $n_packets > $opt_packets)) { while ($uninterrupted && !($opt_packets && $n_packets > $opt_packets)) {
my $packet; my $packet;
last if ! $uninterrupted || $endstream; last if ! $uninterrupted || $endstream;
if ($select->can_read($timeout) && ($packet = $rtp->recv())){ if ($select->can_read($timeout) && ($packet = $rtp->recv())){
...@@ -530,7 +611,6 @@ sub eat_stream { ...@@ -530,7 +611,6 @@ sub eat_stream {
&init_stats($cur_id); &init_stats($cur_id);
} }
$us=$elapsed*10**6; $us=$elapsed*10**6;
$tjoined{$cur_id} = $tjoined if !$tjoined{$cur_id}; $tjoined{$cur_id} = $tjoined if !$tjoined{$cur_id};
# No stats for that SSRC yet? # No stats for that SSRC yet?
&pkt_stats($cur_id, $packet->encode, $elapsed * 10**6, $packet->size()); &pkt_stats($cur_id, $packet->encode, $elapsed * 10**6, $packet->size());
...@@ -666,6 +746,7 @@ sub eat_stream { ...@@ -666,6 +746,7 @@ sub eat_stream {
until ( ! $uninterrupted || $endstream || ($opt_packets && $n_packets > $opt_packets) until ( ! $uninterrupted || $endstream || ($opt_packets && $n_packets > $opt_packets)
|| ! (my $pkt=Net::Pcap::next($pcap, \%hdr) ) ) { || ! (my $pkt=Net::Pcap::next($pcap, \%hdr) ) ) {
#$file_flag =1; #$file_flag =1;
$offline =1;
eat_pcap($f, $pcap, $pkt); eat_pcap($f, $pcap, $pkt);
$n_packets++; $n_packets++;
} }
...@@ -726,7 +807,6 @@ sub eat_pcap_streams{ # open groups and listen on pcap ...@@ -726,7 +807,6 @@ sub eat_pcap_streams{ # open groups and listen on pcap
} }
sub eat_pcap { # process pcap packets sub eat_pcap { # process pcap packets
my ($f, $pcap, $pkt)=@_; my ($f, $pcap, $pkt)=@_;
my $ip=null; my $ip=null;
...@@ -740,13 +820,15 @@ sub eat_pcap { # process pcap packets ...@@ -740,13 +820,15 @@ sub eat_pcap { # process pcap packets
} else { } else {
die "Invalid link layer type : ".Net::Pcap::datalink($pcap); die "Invalid link layer type : ".Net::Pcap::datalink($pcap);
} }
&tcp_packet_stats($pkt) if $ip->{proto} == IP_PROTO_TCP; $tc= [$hdr{tv_sec}, $hdr{tv_usec}];
$us = tv_interval ( $t0, $tc) * 10**6 ; # us relative packet
&tcp_packet_stats($f,$pkt,$us) if $ip->{proto} == IP_PROTO_TCP;
$opt_tcp = 1 if $ip->{proto} == IP_PROTO_TCP; $opt_tcp = 1 if $ip->{proto} == IP_PROTO_TCP;
next if $ip->{proto} != IP_PROTO_UDP; next if $ip->{proto} != IP_PROTO_UDP;
my $udp = NetPacket::UDP->decode($ip->{data}); my $udp = NetPacket::UDP->decode($ip->{data});
#my $tcp = NetPacket::TCP->decode($ip->{data});
my $dlen = $ip->{len} - $ip->{hlen}*4; my $dlen = $ip->{len} - $ip->{hlen}*4;
my $flow_key; my $flow_key;
if ($opt_sum){ if ($opt_sum){
$flow_key=$opt_sum; $flow_key=$opt_sum;
} }
...@@ -768,6 +850,7 @@ sub eat_pcap { # process pcap packets ...@@ -768,6 +850,7 @@ sub eat_pcap { # process pcap packets
if ($pttl{$flow_key} && ($opt_log || ($pttl{$flow_key} != $ip->{ttl}))){ # change in ttl if ($pttl{$flow_key} && ($opt_log || ($pttl{$flow_key} != $ip->{ttl}))){ # change in ttl
printf "%s\n", $ttl_log; printf "%s\n", $ttl_log;
$nttl{$flow_key}=0; $nttl{$flow_key}=0;
print "TTL \n";
} }
$pttl{$flow_key}= $ip->{ttl}; $pttl{$flow_key}= $ip->{ttl};
$nttl{$flow_key}++; $nttl{$flow_key}++;
...@@ -777,7 +860,6 @@ sub eat_pcap { # process pcap packets ...@@ -777,7 +860,6 @@ sub eat_pcap { # process pcap packets
$ip->{src_ip}, $ip->{dest_ip}, $tx_time_seconds{$flow_key}, $ip->{src_ip}, $ip->{dest_ip}, $tx_time_seconds{$flow_key},
$tx_time_useconds{$flow_key}, $hdr{tv_sec}, $hdr{tv_usec}, $pttl{$flow_key}; $tx_time_useconds{$flow_key}, $hdr{tv_sec}, $hdr{tv_usec}, $pttl{$flow_key};
$ttl_log.= sprintf(" No=%08d\n", $nttl{$flow_key},) if !$opt_log; $ttl_log.= sprintf(" No=%08d\n", $nttl{$flow_key},) if !$opt_log;
} }
next if $opt_list; # just count packets per flow next if $opt_list; # just count packets per flow
next if $opt_flow_key && $flow_key !~ $wanted_flow; next if $opt_flow_key && $flow_key !~ $wanted_flow;
...@@ -787,22 +869,14 @@ sub eat_pcap { # process pcap packets ...@@ -787,22 +869,14 @@ sub eat_pcap { # process pcap packets
&init_stats($flow_key); &init_stats($flow_key);
push (@myflows, $flow_key); push (@myflows, $flow_key);
} }
$tc= [$hdr{tv_sec}, $hdr{tv_usec}];
if (! defined($t0)) {
$t0=$tc;
}
$tjoined{$f}=$tc if !$tjoined{$f}; $tjoined{$f}=$tc if !$tjoined{$f};
$tjoined{$flow_key} = $tjoined{$f} if !exists($tjoined{$flow_key}); $tjoined{$flow_key} = $tjoined{$f} if !exists($tjoined{$flow_key});
$us = tv_interval ( $t0, $tc) * 10**6 ; # us relative packet time
# fixate on first flow to appear # fixate on first flow to appear
# if ( $first_port) { # if ( $first_port) {
# next if $udp->{dest_port} != $first_port; # next if $udp->{dest_port} != $first_port;
# } else { # } else {
# $first_port = $udp->{dest_port}; # $first_port = $udp->{dest_port};
# } # }
&pkt_stats($flow_key, $udp->{data}, $us, $dlen); &pkt_stats($flow_key, $udp->{data}, $us, $dlen);
} }
...@@ -849,7 +923,7 @@ sub init_stats { ...@@ -849,7 +923,7 @@ sub init_stats {
sub format_numbers{ sub format_numbers{
my $value = shift; my $value = shift;
if ($value =~ /^[a-zA-z][\D]*$/ || $value !~ /^\d+\.\d+$/) { if ($value =~ /^[a-zA-z][\D]*$/ || $value !~ /^\d+\.\d+$/) {
return $value; return sprintf("%1.0f",$value);
} }
else { else {
return sprintf("%0.5f",$value); return sprintf("%0.5f",$value);
...@@ -869,13 +943,15 @@ sub xml_dump_rtmp_tcp { ...@@ -869,13 +943,15 @@ sub xml_dump_rtmp_tcp {
$qstream->setAttribute('version',$xml_version); $qstream->setAttribute('version',$xml_version);
$doc->appendChild($qstream); $doc->appendChild($qstream);
} }
($address,$app,$play) = rtmp_prepare_url($f) if $rtmp; ($address,$app,$play) = rtmp_prepare_url($f) if $rtmp;
($address, $port) = prepare_ip($f) if $opt_tcp && !$opt_rtmp; #($address, $port) = prepare_ip($f) if $opt_tcp && !$opt_rtmp;
$port = 1935 unless $opt_port; #$port = 1935 unless $opt_port;
my $id=$address.":".$port; #my $id=$address.":".$port;
my ($date,$time) = &get_date_time(); my $id = $f;
my $span=&tv_interval($tstart{$id}, $tend{$id}); # second my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tstart{$f}->[0]);
my $time=sprintf "%02d:%02d:%02d", $hour, $min, $sec;
my $date=sprintf "%4d-%02d-%02d", $year+1900, $mon+1, $mday;
my $span=&tv_interval($tstart{$f}, $tend{$f}); # second
&do_math($id,$span); &do_math($id,$span);
my $flow = $doc->createElement('flow'); my $flow = $doc->createElement('flow');
my $flow_id = $doc->createElement('flow_id'); my $flow_id = $doc->createElement('flow_id');
...@@ -932,7 +1008,7 @@ sub xml_dump_rtmp_tcp { ...@@ -932,7 +1008,7 @@ sub xml_dump_rtmp_tcp {
$bw_stats->appendChild($max_bw); $bw_stats->appendChild($max_bw);
$bw_stats->appendChild($max_bw_100ms); $bw_stats->appendChild($max_bw_100ms);
$bw_stats->appendChild($sdv_bw); $bw_stats->appendChild($sdv_bw);
$avg_bw->addText(&format_numbers( avg( $bw_stats{$f}{'sumbyte'}*8, $opt_period ))); $avg_bw->addText(&format_numbers( avg( $bw_stats{$f}{'sumbyte'}*8, $span )));
$max_bw->addText(&format_numbers($bw_stats{$f}{'maxbps'})); $max_bw->addText(&format_numbers($bw_stats{$f}{'maxbps'}));
$max_bw_100ms->addText(&format_numbers($bw_stats{$f}{'max100ms'})); $max_bw_100ms->addText(&format_numbers($bw_stats{$f}{'max100ms'}));
$sdv_bw->addText(&format_numbers(sdv($bw_stats{$f}{'n100ms'}, $sdv_bw->addText(&format_numbers(sdv($bw_stats{$f}{'n100ms'},
...@@ -1037,11 +1113,10 @@ sub xml_dump { ...@@ -1037,11 +1113,10 @@ sub xml_dump {
$flow->appendChild($dateXML); $flow->appendChild($dateXML);
$flow->appendChild($timeXML); $flow->appendChild($timeXML);
$flow->appendChild($spanXML); $flow->appendChild($spanXML);
my $media="file"; my $media="file";
$media = "host:port" if $opt_net; $media = "host:port" if $opt_net;
my $id=$f; my $id=$f;
next if $npkt{$f} <= $opt_flow_min; next if $npkt{$f} < $opt_flow_min;
my $source=$f; my $source=$f;
$source=$source{$f} if ! $opt_v && $source{$f} ne ""; $source=$source{$f} if ! $opt_v && $source{$f} ne "";
$source=$opt_id if $opt_id; $source=$opt_id if $opt_id;
...@@ -1057,9 +1132,7 @@ sub xml_dump { ...@@ -1057,9 +1132,7 @@ sub xml_dump {
my $date=sprintf "%4d-%02d-%02d", $year+1900, $mon+1, $mday; my $date=sprintf "%4d-%02d-%02d", $year+1900, $mon+1, $mday;
my $span=&tv_interval($tstart{$f}, $tend{$f}); # second my $span=&tv_interval($tstart{$f}, $tend{$f}); # second
&do_math($f,$span); &do_math($f,$span);
&burst($f); # in case a second is interrupted &burst($f); # in case a second is interrupted
#source and destination ip. #source and destination ip.
$flow_id->addText($f); $flow_id->addText($f);
#datetime #datetime
...@@ -1148,11 +1221,11 @@ sub xml_dump { ...@@ -1148,11 +1221,11 @@ sub xml_dump {
$packet_stats->appendChild($packets_lostXML); $packet_stats->appendChild($packets_lostXML);
$packet_stats->appendChild($packets_sizeXML); $packet_stats->appendChild($packets_sizeXML);
$packets_dupXML->addText($dup{$f}); $packets_dupXML->addText(&format_numbers($dup{$f}));
$packets_lateXML->addText($late{$f}); $packets_lateXML->addText(&format_numbers($late{$f}));
$packets_lostXML->addText(&format_numbers($nloss{$f})); $packets_lostXML->addText(&format_numbers($nloss{$f}));
my $n=$npkt{$f}; $n=1 if $npkt{$f} <1; # divide by zero protection my $n=$npkt{$f}; $n=1 if $npkt{$f} <1; # divide by zero protection
$packets_sizeXML->addText($sumbyte{$f}/$n); $packets_sizeXML->addText(&format_numbers($sumbyte{$f}/$n));
#adds values #adds values
$MOS_XML->addText(&format_numbers(&mos_r($codec, $rtt, avg( $sumgap{$f}, $ngap{$f}) / 1000, $MOS_XML->addText(&format_numbers(&mos_r($codec, $rtt, avg( $sumgap{$f}, $ngap{$f}) / 1000,
...@@ -1174,7 +1247,7 @@ sub xml_dump { ...@@ -1174,7 +1247,7 @@ sub xml_dump {
} }
#packet stats #packet stats
$packets_numbXML->addText($npkt{$f}); $packets_numbXML->addText(&format_numbers($npkt{$f}));
#$packets_sizeXML->addText(); #$packets_sizeXML->addText();
#bandwidth #bandwidth
...@@ -1339,22 +1412,21 @@ sub pkt_stats { ...@@ -1339,22 +1412,21 @@ sub pkt_stats {
my $us = shift; my $us = shift;
my $dlen = shift; my $dlen = shift;
my $rtp = new Net::RTP::Packet(); my $rtp = new Net::RTP::Packet();
if (! exists($tstart{$f})){ if (! exists($tstart{$f})){
$tstart{$f} = $tc; #print "$tc \n";
$first_us{$f}=$prev1s_us{$f}=$prevt100ms_us{$f}=$us; $tstart{$f} = $tc;
if (! exists($setuptime{$f}) ){ $first_us{$f}=$prev1s_us{$f}=$prevt100ms_us{$f}=$us;
if ( $pinterval){ if (! exists($setuptime{$f}) ){
$setuptime{$f}=0; if ( $pinterval){
} else { $setuptime{$f}=0;
$setuptime{$f}=tv_interval ( $tjoined{$f}, $tstart{$f}) * 10**3; } else {
} $setuptime{$f}=tv_interval ( $tjoined{$f}, $tstart{$f}) * 10**3;
printf "setup $f : %.3f\n", $setuptime{$f} if $opt_debug; }
} printf "setup $f : %.3f\n", $setuptime{$f} if $opt_debug;
}
} }
$tend{$f} = $tc; $tend{$f} = $tc;
$last_us{$f}=$us; $last_us{$f}=$us;
# next if $dlen < 20; # typically small background noice packets added # next if $dlen < 20; # typically small background noice packets added
$npkt{$f}++; $npkt{$f}++;
$sumbyte{$f}+=$dlen; $sum1s{$f}+=$dlen; $sum100ms{$f}+=$dlen; $sumbyte{$f}+=$dlen; $sum1s{$f}+=$dlen; $sum100ms{$f}+=$dlen;
...@@ -1428,9 +1500,7 @@ sub pkt_stats { ...@@ -1428,9 +1500,7 @@ sub pkt_stats {
&seq_stat($f, $seq_num{$f}, $mtime{$f}); &seq_stat($f, $seq_num{$f}, $mtime{$f});
} }
#&burst($f); &burst($f);
&burst($f) if !$opt_tcp;
&burst_2($f) if $opt_tcp;
} }
if ($opt_period){ if ($opt_period){
$interval=int($us/10**6 / $opt_period); $interval=int($us/10**6 / $opt_period);
...@@ -1472,12 +1542,13 @@ sub do_math{ ...@@ -1472,12 +1542,13 @@ sub do_math{
} }
} }
if($opt_tcp){ if($opt_tcp){
$tcp_packet_stats{$f}{'span'} = $span; #$tcp_packet_stats{$f}{'span'} = 10;
$tcp_packet_stats{$f}{'avg_bandwidth'} = (($tcp_packet_stats{$f}{'num_bytes'}*8)/$span); #$span = 10;
$tcp_packet_stats{$f}{'jitter_avg'} = avg($tcp_packet_stats{$f}{'jitter_sum'},$tcp_packet_stats{$f}{'num_packets'}); #$tcp_packet_stats{$f}{'avg_bandwidth'} = (($tcp_packet_stats{$f}{'num_bytes'}*8)/$span);
$tcp_packet_stats{$f}{'jitter_sdv'} = sdv($tcp_packet_stats{$f}{'num_packets'}, $tcp_packet_stats{$f}{'jitter_sum'}, $tcp_packet_stats{$f}{'jitter_square'}); #$tcp_packet_stats{$f}{'jitter_avg'} = avg($tcp_packet_stats{$f}{'jitter_sum'},$tcp_packet_stats{$f}{'num_packets'});
$tcp_packet_stats{$f}{'gap_avg'} = (10**3)*avg($tcp_packet_stats{$f}{'gap_sum'},$tcp_packet_stats{$f}{'num_packets'}); #$tcp_packet_stats{$f}{'jitter_sdv'} = sdv($tcp_packet_stats{$f}{'num_packets'}, $tcp_packet_stats{$f}{'jitter_sum'}, $tcp_packet_stats{$f}{'jitter_square'});
$tcp_packet_stats{$f}{'gap_sdv'} = (10**3)*sdv($tcp_packet_stats{$f}{'num_packets'}, $tcp_packet_stats{$f}{'gap_sum'}, $tcp_packet_stats{$f}{'gap_square'}); #$tcp_packet_stats{$f}{'gap_avg'} = (10**3)*avg($tcp_packet_stats{$f}{'gap_sum'},$tcp_packet_stats{$f}{'num_packets'});
#$tcp_packet_stats{$f}{'gap_sdv'} = (10**3)*sdv($tcp_packet_stats{$f}{'num_packets'}, $tcp_packet_stats{$f}{'gap_sum'}, $tcp_packet_stats{$f}{'gap_square'});
} }
} }
...@@ -1498,6 +1569,11 @@ sub burst { ...@@ -1498,6 +1569,11 @@ sub burst {
$per1s{$f} = $per1s; $per1s{$f} = $per1s;
$prev_1s{$f} = $last_us{$f}; $prev_1s{$f} = $last_us{$f};
$sum1s{$f}=0; $sum1s{$f}=0;
if ($opt_tcp) {
$bw_stats{$f}{'maxbps'} = $bps if $bps > $bw_stats{$f}{'maxbps'};
$bw_stats{$f}{'per1s'}= $per1s;
$bw_stats{$f}{'per1s'}= $last_us{$f};
}
} }
} }
if ( $per100ms > $per100ms{$f} ){ # period expired if ( $per100ms > $per100ms{$f} ){ # period expired
...@@ -1511,50 +1587,13 @@ sub burst { ...@@ -1511,50 +1587,13 @@ sub burst {
$per100ms{$f} = $per100ms; $per100ms{$f} = $per100ms;
$prev_100ms{$f} = $last_us{$f}; $prev_100ms{$f} = $last_us{$f};
$sum100ms{$f}=0; $sum100ms{$f}=0;
} if($opt_tcp){
}
}
sub burst_2 {
my $f=shift;
#my %bw_stats = ();
my $span=$last_us{$f}-$first_us{$f};
my $per1s=int($span/10**6);
#printf "per1s: %f\n", $per1s;
my $per100ms=int($span/10**5);