Commit 33312e8a authored by paalmm's avatar paalmm

added -name, and -id for xml. some fixtures in xml output. mpeg analyises for...

added -name, and -id for xml. some fixtures in xml output.  mpeg analyises for http and tcp added + ipv6 support for -pcap 
parent 966d63d1
......@@ -17,6 +17,8 @@ use NetPacket::IP;
use NetPacket::IP qw(:strip :protos);;
use NetPacket::UDP;
use NetPacket::TCP;
use Net::IPv6Addr;
use NetPacket::IPv6 qw(ipv6_strip);
#use Net::RTP;
use Net::RTP::Packet;
use Time::HiRes qw/ sleep time tv_interval gettimeofday/;
......@@ -43,7 +45,7 @@ my ($rtmp,$period,$last,$debug,$swfurl,$pageurl,$flash_version,$reconnect);
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','test');
@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','ipv6','p=s','name=s');
&NGetOpt(@opts) || die pod2usage(1);
die pod2usage(1) if $opt_h;
......@@ -79,6 +81,7 @@ my $xml_printed= 0;
my $last_stream;
my $file_flag;
my $offline;
my $lost_counter = 0;
#TCP STUFF
my $thr;
......@@ -104,12 +107,15 @@ $tcp_packet_stats{'pkt_late'} = 0;
$tcp_packet_stats{'pkt_dup'} = 0 ;
$tcp_packet_stats{'pkt_retrans'} = 0;
my %offset_bytes =();
my %network_info =();
my $start_time = time();
#MPEG-TS measurement globals (most are reset in init)
my $CHECK_NUM_TSP = 2;
#globals for mpeg ts
#a tabel for transport streams pids. aleternativ to PAT impl.
my %pcr_pid = ();
my $TS;
my @cc = ();
my $discontinuities = 0;
......@@ -168,6 +174,7 @@ $SIG{ALRM} = sub {
if ($opt_dump){
open DUMP, ">$opt_dump";
}
&unit_test if $opt_test;
if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell
......@@ -178,11 +185,11 @@ if ($opt_pcap || ($opt_tcp && !$opt_rtmp)){ # listen in parallell
&display_stats() if !$opt_xml;
} else { # listen serially
my $stream_count;
my $ln = @streams;
#my $ln = @streams;
foreach $id (@streams) {
alarm($opt_last) if $opt_last;
++$stream_count;
$last_stream = 1 if $stream_count == ($ln);
#$last_stream = 1 if $stream_count == ($ln);
#print "count $stream_count lengde $ln \n";
$uninterrupted=1;
$endstream=0;
......@@ -207,12 +214,13 @@ 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_mpeg.pcap" if $opt_mpeg;
@streams = "testing/testdata_rtp.pcap" if $opt_rtp;
#@streams = "testing/testdata_tcp.pcap";
@streams = "testing/testdata_tcp.pcap" if $opt_tcp;
$opt_xml = "tmp_testdata.xml";
$opt_q = 1;
$opt_v = 1;
#print $streams[0], "\n";
}
sub unit_test_2{
#my ($orgnial_test) = &feed_data("file",rtp_file.xml);
......@@ -220,18 +228,18 @@ sub unit_test_2{
$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;
$test_data = "tcp_testdata.xml" 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";
print "different value @ $k1, value: $orginal_test->{$k1}, differs from 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";
print "different value @ $k1-> $k2, value: $orginal_test->{$k1}{$k2} differs from, value: $new_test->{$k1}{$k2}\n";
}
}
}
......@@ -339,13 +347,23 @@ sub end_xml{
sub tcp_packet_stats {
my $f = shift;
my ($pkt) = shift;
my $us = shift;
my $ip_obj = NetPacket::IP->decode(eth_strip($pkt));
my $tcp_obj = NetPacket::TCP->decode(ip_strip(eth_strip($pkt)));
#my $f = $ip_obj->{src_ip}.":".$tcp_obj->{src_port} if !$offline;
my $ip = shift;
my ($tcp_obj) = shift;
my $len,$ip_hlen = 0;
#ipv6.pm uses different variables.
if($opt_ipv6){
$len = plen;
}
else {
$len = len;
$ip_hlen = 20;
}
#my $ip = NetPacket::IP->decode(eth_strip($pkt));
#my $tcp_obj = NetPacket::TCP->decode(ip_strip(eth_strip($pkt)));
#my $f = $ip->{src_ip}.":".$tcp_obj->{src_port} if !$offline;
my $seq_num = $tcp_obj->{seqnum};
my $options = $tcp_obj->{options}; #12 bytes
#print "$tcp_obj->{src_port} \n";
if (!exists $tcp_packet_stats{$f}){
&init_stats($f);
$tcp_packet_stats{$f} = &share( {} );
......@@ -356,24 +374,12 @@ sub tcp_packet_stats {
$tcp_packet_stats{$f}{'pkt_dup'} = 0;
}
print $tcp_packet_stats{$f}{'num_packets'}, "\n";
++$tcp_packet_stats{$f}{'num_packets'};
#$tc=[gettimeofday]; # current flow time
# if( $t0){
# $elapsed=tv_interval ( $t0, $tc);
# } else {
# $t0 = $tc;
# $elapsed=0.0;
# &init_stats($cur_id);
# }
# $us=$elapsed*10**6;
&tcp_jitter_stats($f,$options);
#Bandwidth messurements
&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->{$len}; #counts the bytes
#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'};
print $seq_stats{$f}{'seq_diff'}, "\n", if $opt_debug;
$seq_stats{$f}{'seq_diff'} = $seq_num - $seq_stats{$f}{'p_seq_num'} - $seq_stats{$f}{'p_packet_len'};
if ($seq_stats_n{$f}{'seq_num_p'} == $seq_num && $seq_stats{$f}{'p_seq_num'} != 0) {
++$tcp_packet_stats{$f}{'pkt_dup'};
}
......@@ -389,10 +395,10 @@ sub tcp_packet_stats {
}
}
if($seq_stats{$f}{'p_seq_num'} < $seq_num){
$seq_stats{$f}{'n_seq_num'} = ($seq_num+$ip_obj->{len} -($ip_obj->{hlen}*4)-($tcp_obj->{hlen}*4))
$seq_stats{$f}{'n_seq_num'} = ($seq_num+$ip->{$len} -($ip_hlen)-($tcp_obj->{hlen}*4))
}
$seq_stats{$f}{'p_seq_num'} = $seq_num;
$seq_stats{$f}{'p_packet_len'} = $ip_obj->{len}-($ip_obj->{hlen}*4)-($tcp_obj->{hlen}*4);
$seq_stats{$f}{'p_packet_len'} = $ip->{$len}-($ip_hlen)-($tcp_obj->{hlen}*4);
$seq_stats_n{$f}{'seq_num_p'} = $seq_num;
$seq_stats_n{$f}{'seq_num_n'} = $seq_stats{$f}{'n_seq_num'};
}
......@@ -405,7 +411,6 @@ sub tcp_jitter_stats {
$seq_stats{$f}{'p_tcp_time_stamp'} = $tcp_time_stamp;
$seq_stats{$f}{'p_tcp_time_stamp_echo'} = $tcp_time_stamp_echo;
my $real_time_delta = time() - $seq_stats{$f}{'real_last_time'};
$seq_stats{$f}{'real_last_time'} = time();
#After AV streams starts
......@@ -767,18 +772,24 @@ sub eat_stream {
sub eat_pcap_streams{ # open groups and listen on pcap
my @streams=@_;
my $filter="( ";
my ($address, $port, $multicast);
my $mc = IO::Socket::Multicast->new(LocalPort=>$DEFAULT_PORT, ReuseAddr=>1) ||
die "Could not connect to port $port : $!";
foreach $id (@streams){ # listen to all groups
my ($address, $port, $multicast) = prepare_ip($id);
if ($opt_ipv6){
$address = Net::IPv6Addr::ipv6_parse($id);
$port = $opt_p;
}
else {
($address, $port, $multicast) = prepare_ip($id);
}
$filter .= " or " if $filter =~ /\(\s+\(/;
if ($multicast){
$mc->mcast_add($address) || die "could not join $address:$port : $!";
$filter .= "(dst $address and port $port)";
} else {
$filter .= "(src $address and port $port)";
}
}
}
$tjoined{$f}=[gettimeofday];
$filter .= " )";
......@@ -807,27 +818,47 @@ sub eat_pcap_streams{ # open groups and listen on pcap
}
sub set_network_info{
my ($f,$src_ip,$dst_ip,$src_port,$dst_port) = @_;
$network_info{$f}{'src_ip'} = $src_ip;
$network_info{$f}{'dst_ip'} = $dst_ip;
$network_info{$f}{'src_port'} = $src_port;
$network_info{$f}{'dst_port'} = $dst_port;
}
sub eat_pcap { # process pcap packets
my ($f, $pcap, $pkt)=@_;
my $ip=null;
my $ip_payload;# udp or tcp packet.
my $rtp = new Net::RTP::Packet(); # spare rtp obj
my $proto,$len=null;
if (Net::Pcap::datalink($pcap) == 1){ # ethernet
$ip = NetPacket::IP->decode(eth_strip($pkt));
if ($opt_ipv6){
$ip = NetPacket::IPv6->decode(eth_strip($pkt));
$proto = $ip->{nxt};
$len = plen;
$hlen = 0;
}
else {
$ip = NetPacket::IP->decode(eth_strip($pkt));
$proto = $ip->{proto};
$len = len;
$hlen = ($ip->{hlen}*4);
}
} elsif (Net::Pcap::datalink($pcap) == 113) { # DLT_LINUX_SLL
my ($head, $data)=unpack('a16a*', $pkt);
$ip = NetPacket::IP->decode($data);
} else {
die "Invalid link layer type : ".Net::Pcap::datalink($pcap);
}
$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;
next if $ip->{proto} != IP_PROTO_UDP;
my $udp = NetPacket::UDP->decode($ip->{data});
#my $tcp = NetPacket::TCP->decode($ip->{data});
my $dlen = $ip->{len} - $ip->{hlen}*4;
if ($proto == IP_PROTO_TCP){
$opt_tcp = 1;
$ip_payload = NetPacket::TCP->decode($ip->{data});
}
else {
$ip_payload = NetPacket::UDP->decode($ip->{data});
}
my $dlen = $ip->{$len} - $hlen;
my $flow_key;
if ($opt_sum){
$flow_key=$opt_sum;
......@@ -837,24 +868,25 @@ sub eat_pcap { # process pcap packets
}
else {
$flow_key=sprintf "%s:%d->%s:%d",
$ip->{src_ip}, $udp->{src_port}, $ip->{dest_ip}, $udp->{dest_port};
$ip->{src_ip}, $ip_payload->{src_port}, $ip->{dest_ip}, $ip_payload->{dest_port};
}
set_network_info($f,$ip->{src_ip}, $ip_payload->{src_port}, $ip->{dest_ip}, $ip_payload->{dest_port});
$flow_pkts{$flow_key}++;
#next if $ip->{proto} != IP_PROTO_UDP;
if ($flow_pkts{$flow_key} <= 1) { # new flow
push(@flows, $flow_key); #
$flow_no++;
$file{$flow_key}=$f;
$source{$flow_key} =sprintf "%s:%d", $ip->{src_ip}, $udp->{src_port};
$source{$flow_key} =sprintf "%s:%d", $ip->{src_ip}, $ip_payload->{src_port};
}
if ($opt_ttl){
if ($pttl{$flow_key} && ($opt_log || ($pttl{$flow_key} != $ip->{ttl}))){ # change in ttl
printf "%s\n", $ttl_log;
$nttl{$flow_key}=0;
print "TTL \n";
}
$pttl{$flow_key}= $ip->{ttl};
$nttl{$flow_key}++;
($sequence_number{$flow_key}, $tx_time_seconds{$flow_key}, $tx_time_useconds{$flow_key}, $flow_id{$flow_key})= unpack('NNNN', $udp->{data});
($sequence_number{$flow_key}, $tx_time_seconds{$flow_key}, $tx_time_useconds{$flow_key}, $flow_id{$flow_key})= unpack('NNNN', $ip_payload->{data});
$ttl_log=sprintf "ID=%u SEQ=%u SRC=%s DST=%s Tx=%u.%06u Rx=%u.%06u TTL=%u",
$flow_id{$flow_key}, $sequence_number{$flow_key},
$ip->{src_ip}, $ip->{dest_ip}, $tx_time_seconds{$flow_key},
......@@ -869,16 +901,23 @@ sub eat_pcap { # process pcap packets
&init_stats($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{$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
# if ( $first_port) {
# next if $udp->{dest_port} != $first_port;
# next if $ip_payload->{dest_port} != $first_port;
# } else {
# $first_port = $udp->{dest_port};
# $first_port = $ip_payload->{dest_port};
# }
&pkt_stats($flow_key, $udp->{data}, $us, $dlen);
if ($opt_tcp){
&tcp_packet_stats($flow_key,$ip,$ip_payload);
}
&pkt_stats($flow_key, $ip_payload->{data}, $us, $dlen);
}
sub init_stats {
my $f=shift;
......@@ -960,7 +999,6 @@ sub xml_dump_rtmp_tcp {
my $timeXML = $doc->createElement('time');
my $spanXML = $doc->createElement('span');
$qstream->appendChild($flow);
$flow->appendChild($flow_id);
$flow->appendChild($dateXML);
$flow->appendChild($timeXML);
......@@ -1027,7 +1065,7 @@ sub xml_dump_rtmp_tcp {
&init_stats($id);
}
sub dump_XML_new {
sub xml_new {
my ($pcr_stats,$pts_stats,$mpeg_stats) = (\%pcr_stats, \%pts_stats,\%mpeg_stats) if $opt_mpeg;
my $doc = XML::DOM::Document->new;
my $decl = $doc->createXMLDecl('1.0');
......@@ -1093,6 +1131,7 @@ sub dump_XML_new {
sub xml_dump {
my $f = shift;
return 0 if $xml_printed;
my ($network_info) = (\%network_info);
my ($pcr_stats,$pts_stats) = (\%pcr_stats, \%pts_stats) if $opt_mpeg;
my $xml_version="1.0";
if ($period_num <= 1 ){
......@@ -1105,17 +1144,26 @@ sub xml_dump {
}
my $flow = $doc->createElement('flow');
my $flow_id = $doc->createElement('flow_id');
my $flow_nameXML = $doc->createElement('flow_name');
my $dateXML = $doc->createElement('date');
my $timeXML = $doc->createElement('time');
my $spanXML = $doc->createElement('span');
my $spanXML = $doc->createElement('span');
my $pcr_jitter_parrent = $doc->createElement('pcr_jitter');
my $network_info_parrent = $doc->createElement('network_info');
$qstream->appendChild($flow);
$flow->appendChild($flow_id);
$flow->appendChild($flow_nameXML);
$flow->appendChild($dateXML);
$flow->appendChild($timeXML);
$flow->appendChild($spanXML);
$flow->appendChild($spanXML);
$flow->appendChild($network_info_parrent);
$flow->appendChild($pcr_jitter_parrent);
my $media="file";
$media = "host:port" if $opt_net;
my $id=$f;
$flow_name = $id;
$id = $opt_id if $opt_id;
$flow_name = $opt_name if $opt_name;
next if $npkt{$f} < $opt_flow_min;
my $source=$f;
$source=$source{$f} if ! $opt_v && $source{$f} ne "";
......@@ -1134,11 +1182,19 @@ sub xml_dump {
&do_math($f,$span);
&burst($f); # in case a second is interrupted
#source and destination ip.
$flow_id->addText($f);
$flow_id->addText($id);
$flow_nameXML->addText($flow_name);
#datetime
$dateXML->addText($date);
$timeXML->addText($time);
$spanXML->addText($span);
for my $k1 ( sort keys %network_info ) {
for my $k2 ( keys %{$network_info->{ $k1 }} ) {
$child = $doc->createElement($k2);
$child->addText($network_info->{ $k1 }{ $k2 });
$network_info_parrent->appendChild($child);
}
}
#network_stats
my $network_stats = $doc->createElement('network_stats');
my $setuptimeXML = $doc->createElement('setuptime');
......@@ -1263,15 +1319,15 @@ sub xml_dump {
my $pcr_jitter_sdv_XML = $doc->createElement('pcr_jitter_sdv');
my $pcr_jitter_min_XML = $doc->createElement('pcr_jitter_min');
my $pcr_jitter_max_XML = $doc->createElement('pcr_jitter_max');
$pcr_jitter_avg_XML->addText(&format_numbers( (10**3) * avg($pcr_stats{$f}{'pcr_jitter_sum'}, $pcr_stats{$f}{'num'})));
$pcr_jitter_sdv_XML->addText(&format_numbers( (10**3) * sdv($pcr_stats{$f}{'num'}, $pcr_stats{$f}{'pcr_jitter_sum'},$pcr_stats{$f}{'pcr_jitter_square'})));
$pcr_jitter_min_XML->addText(&format_numbers( (10**3) * $pcr_stats{$f}{'min_jit'}));
$pcr_jitter_max_XML->addText(&format_numbers( (10**3) * $pcr_stats{$f}{'max_jit'}));
$pcr_jitter_avg_XML->addText(&format_numbers( (10**3) * avg($pcr_stats{$f}{$pcr_pid{$f}}{'pcr_jitter_sum'}, $pcr_stats{$f}{$pcr_pid{$f}}{'num'})));
$pcr_jitter_sdv_XML->addText(&format_numbers( (10**3) * sdv($pcr_stats{$f}{$pcr_pid{$f}}{'num'}, $pcr_stats{$f}{$pcr_pid{$f}}{'pcr_jitter_sum'},$pcr_stats{$f}{$pcr_pid{$f}}{'pcr_jitter_square'})));
$pcr_jitter_min_XML->addText(&format_numbers( (10**3) * $pcr_stats{$f}{$pcr_pid{$f}}{'min_jit'}));
$pcr_jitter_max_XML->addText(&format_numbers( (10**3) * $pcr_stats{$f}{$pcr_pid{$f}}{'max_jit'}));
$flow->appendChild($pcr_jitter_avg_XML);
$flow->appendChild($pcr_jitter_sdv_XML);
$flow->appendChild($pcr_jitter_min_XML);
$flow->appendChild($pcr_jitter_max_XML);
$pcr_jitter_parrent->appendChild($pcr_jitter_avg_XML);
$pcr_jitter_parrent->appendChild($pcr_jitter_sdv_XML);
$pcr_jitter_parrent->appendChild($pcr_jitter_min_XML);
$pcr_jitter_parrent->appendChild($pcr_jitter_max_XML);
}
#Transport stream, goes throu @transport_streams for vidoe and audiostreams.
if ($opt_mpeg){
......@@ -1413,7 +1469,6 @@ sub pkt_stats {
my $dlen = shift;
my $rtp = new Net::RTP::Packet();
if (! exists($tstart{$f})){
#print "$tc \n";
$tstart{$f} = $tc;
$first_us{$f}=$prev1s_us{$f}=$prevt100ms_us{$f}=$us;
if (! exists($setuptime{$f}) ){
......@@ -1444,7 +1499,7 @@ sub pkt_stats {
print DUMP $packet;
}
if ($opt_mpeg){
if ($opt_mpeg){
mpeg_stats($f, $packet, $us);
}
......@@ -1504,6 +1559,7 @@ sub pkt_stats {
}
if ($opt_period){
$interval=int($us/10**6 / $opt_period);
if ($interval > $pinterval){
&mpeg_debug() if $opt_debug;
&display_stats() if !$opt_rtmp;
......@@ -1525,8 +1581,8 @@ sub do_math{
my $span = shift;
my $pts_stats = (\%pts_stats);
if ($opt_mpeg){
$pcr_stats{$f}{'pcr_avg_jitter'} = (10**3)*avg($pcr_stats{$f}{'pcr_jitter_sum'}, $pcr_stats{$f}{'num'});
$pcr_stats{$f}{'pcr_sdv_jitter'} = (10**3)*sdv($pcr_stats{$f}{'num'}, $pcr_stats{$f}{'pcr_jitter_sum'},$pcr_stats{$f}{'pcr_jitter_square'});
$pcr_stats{$f}{$TS}{'pcr_avg_jitter'} = (10**3)*avg($pcr_stats{$f}{$TS}{'pcr_jitter_sum'}, $pcr_stats{$f}{$TS}{'num'});
$pcr_stats{$f}{$TS}{'pcr_sdv_jitter'} = (10**3)*sdv($pcr_stats{$f}{$TS}{'num'}, $pcr_stats{$f}{$TS}{'pcr_jitter_sum'},$pcr_stats{$f}{$TS}{'pcr_jitter_square'});
for my $k1 ( sort keys %$pts_stats ) {
for my $pid ( keys %{$pts_stats->{ $k1 }} ) {
if ( grep { $_ eq $pts_stats->{ $f }{ $pid }{ 'stream_id_type'} || $_ eq 'all'} @filter) {
......@@ -1542,13 +1598,12 @@ sub do_math{
}
}
if($opt_tcp){
#$tcp_packet_stats{$f}{'span'} = 10;
#$span = 10;
#$tcp_packet_stats{$f}{'avg_bandwidth'} = (($tcp_packet_stats{$f}{'num_bytes'}*8)/$span);
#$tcp_packet_stats{$f}{'jitter_avg'} = avg($tcp_packet_stats{$f}{'jitter_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_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'});
$tcp_packet_stats{$f}{'span'} = $span;
$tcp_packet_stats{$f}{'avg_bandwidth'} = (($tcp_packet_stats{$f}{'num_bytes'}*8)/$span);
$tcp_packet_stats{$f}{'jitter_avg'} = avg($tcp_packet_stats{$f}{'jitter_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_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'});
}
}
......@@ -1601,7 +1656,6 @@ sub burst {
sub jitter_stats {
my $pts_stats = shift;
my $span = shift;
Dumper($pts_stats);
my $counter = 0;
my $max_colums = (length(@filter)+1);
for my $k1 ( sort keys %$pts_stats ) {
......@@ -1640,11 +1694,6 @@ sub display_stats{
foreach $f (sort @myflows) {
#my ($ip,$port) = prepare_ip($f) if $opt_tcp;
#$f = $ip.":".$port if $opt_tcp;
if (!exists $npkt{$f}){
#print "no packets \n";
$ngap{$f} = 0;
}
$period_num++;
if ($opt_xml){
if($opt_tcp || $opt_rtmp){
......@@ -1804,12 +1853,12 @@ sub print_out {
#printf " %5s %5s %5s %5s %5s %5s",
printf " %5s %5s %5s %5s",
&lesbar( (10**3) * avg($pcr_stats{$f}{'pcr_jitter_sum'}, $pcr_stats{$f}{'num'})),
&lesbar( (10**3) * sdv($pcr_stats{$f}{'num'},
$pcr_stats{$f}{'pcr_jitter_sum'},
$pcr_stats{$f}{'pcr_jitter_square'})),
&lesbar( (10**3) * $pcr_stats{$f}{'min_jit'}),
&lesbar( (10**3) * $pcr_stats{$f}{'max_jit'}),
&lesbar( (10**3) * avg($pcr_stats{$f}{$TS}{'pcr_jitter_sum'}, $pcr_stats{$f}{$TS}{'num'})),
&lesbar( (10**3) * sdv($pcr_stats{$f}{$TS}{'num'},
$pcr_stats{$f}{$TS}{'pcr_jitter_sum'},
$pcr_stats{$f}{$TS}{'pcr_jitter_square'})),
&lesbar( (10**3) * $pcr_stats{$f}{$TS}{'min_jit'}),
&lesbar( (10**3) * $pcr_stats{$f}{$TS}{'max_jit'}),
if $opt_mpeg;
if ($opt_mpeg){
for my $k1 (sort keys %$jitter_stats){
......@@ -1937,10 +1986,10 @@ sub print_out {
@jitterstat = (
&lesbar( (10**3) * avg($pcr_stats{$f}{'pcr_jitter_sum'}, $pcr_stats{$f}{'num'})),
&lesbar( (10**3) * sdv($pcr_stats{$f}{'num'},
$pcr_stats{$f}{'pcr_jitter_sum'},
$pcr_stats{$f}{'pcr_jitter_square'})),
&lesbar( (10**3) * avg($pcr_stats{$f}{$TS}{'pcr_jitter_sum'}, $pcr_stats{$f}{$TS}{'num'})),
&lesbar( (10**3) * sdv($pcr_stats{$f}{$TS}{'num'},
$pcr_stats{$f}{$TS}{'pcr_jitter_sum'},
$pcr_stats{$f}{$TS}{'pcr_jitter_square'})),
$dwell_avg,
$dwell_sdv,
#&lesbar( (10**3) * avg($pts_stats{$f}{$TS}{'dwell_sum'}, $pts_stats{$f}{$TS}{'num'})),
......@@ -2103,15 +2152,19 @@ sub search {
}
return @ret
}
sub find_sync_byte{
sub find_sync_byte_old{
my $data = shift;
my @hex_string = unpack("H2864", $data);
my @offset_array = &search(@hex_string);
#s print "@offset_array \n";
my $length = @offset_array;
my @offset;
for (my $i = 0; $i < $length;$i++){
my $temp = $offset_array[$i+1] - (376+$offset_array[$i]);
my $sync_byte = $offset_array[$i]+376;
if($offset_array[$i]==120){
# print "HALLO \n";
}
for my $pos (@offset_array){
if($pos == $sync_byte){
push(@offset,$offset_array[$i]);
......@@ -2121,6 +2174,45 @@ sub find_sync_byte{
return @offset;
}
sub find_sync_byte {
my $f = shift;
my $data = shift;
my $hex_size = do {use bytes; length($data)*2};
my @hex_string = unpack("H2864", $data);
my $hex_scalar = unpack("H2864", $data);
my @offset_array = &search(@hex_string);
@g_array = qw();
my $length = @offset_array;
for (my $i = 0; $i < $length;$i++){
#my $temp = $offset_array[$i]+376;
for (my $j = $i+1; $j < $length; $j++){
#print " $offset_array[$j] ...........\n";
#print "$offset_array[$i], \n";
if ($offset_array[$j] == $offset_array[$i]+376){
# print " $offset_array[$j] ...........\n";
push(@g_array, $offset_array[$i]);
# print "$offset_array[$i] \n";
# print "hallo \n";
}
}
}
my $g_size = @g_array;
if ($g_array[$g_size-1]+376 <= $hex_size){
if($g_array[$g_size-1]+752 > $hex_size){
my $byte_pos = ($g_array[$g_size-1]+376);
$offset_bytes{$f} = substr($data,($byte_pos/2),($hex_size/2));
#print "size $hex_size \n";
#print "offsetYO ", $offset_bytes{$f}, "\n";
}
else {
push(@g_array,$g_array[$g_size-1]+376);
}
}
return @g_array;
}
sub mpeg_stats
{
my ($flow_id, $packet, $us) = @_;
......@@ -2131,19 +2223,49 @@ sub mpeg_stats
my @ret;
my $offset = 0;
if ($opt_tcp){
@ret = &find_sync_byte($packet);
$n = length(@ret);
@ret = &find_sync_byte($flow_id,$packet);
$n = @ret;
#print "@ret \n";
}
#One UDP-packet contains $n number of MPEG-TS packets, check every one:
for(my $j = 0; $j < $n; ++$j) {
my $var = $j*188;
$mpeg_stats{$flow_id}{'num'} += 1;
if (exists $offset_bytes{$flow_id}){
#my $offset_size = do {use bytes; length($offset_bytes{$flow_id})};
my $rest = substr($packet,0,$ret[0]/2);
#print "new off ", $ret[0]/2, "\n";
my $scrambled_packet .= $offset_bytes{$flow_id};
$scrambled_packet .= $rest;
my $offset_size = do {use bytes; length($scrambled_packet)};
#print "offset " , $offset_size, "\n";
$tspack = mpegtspacket->new ($scrambled_packet);
$mpeg_stats{$flow_id}{'num'} += 1;
$TS = $tspack->PID();
$mpeg_stats{$flow_id}{$TS}{'num'} += 1;
#print "scramb \n";
#cc_update_stats($flow_id, $tspack, $us);
#cc_update_stats($flow_id, $tspack, $us);
#$lost_counter++;
delete $offset_bytes{$flow_id};
#print "$lost_counter \n";
}
for(my $j = 0; $j < $n; ++$j) {
my $var = $j*188;
#print " j $j ....N $n \n";
#print $mpeg_stats{$flow_id}{'num'}, "\n";
if ($opt_tcp) {
if (@ret == 0){next;}
if (@ret == 0){
#print "next $j \n" if $debug;
#$lost_counter++;
next;}
$var = ($ret[$j]/2);
if ($var !~ /^\d+$/) {next;}
if ($var !~ /^\d+$/) {
#print "@ret \n";
#$lost_counter++;
#print "$var $j THIS \n" if $debug;