#!/usr/bin/perl # #r 0.110053 0 20 tcp 40 ------- 1 0.0 43.0 0 0 #+ 0.1 0 20 tcp 40 ------- 1 0.0 43.0 0 0 #- 0.1 0 20 tcp 40 ------- 1 0.0 43.0 0 0 #d 0.318857 40 41 tcp 1040 ------- 1 6.0 43.6 19 654 use strict; use warnings; my %conexao; my @tempo; my @retardo; for (my $i=0; $i < 10; $i++) { $conexao{"$i-43"} = {enviados => 0, recebidos => 0}; $conexao{$i + 10 . "-44"} = {enviados => 0, recebidos => 0}; #$conexao{"43-$i"} = {enviados => 0, recebidos => 0}; #$conexao{"44-$i"} = {enviados => 0, recebidos => 0}; } my $i = 0; while(my $linha = <>) { chomp($linha); my ($estado, $tempo, $no_atual, $no_prox, $tipo, $tam, $flags, $flow, $f, $t, $seq_number, $id) = split(" ", $linha); my ($src, $sport) = split(/\./, "$f"); my ($dst, $dport) = split(/\./, "$t"); # contar numero de pacotes enviados por conexao if ( $no_atual == $src and $tipo eq 'tcp' and $estado eq "r") { $conexao{"$src-$dst"}->{"enviados"}++; $tempo[$id] = $tempo; } #if ( $no_atual == $src and $tipo eq 'ack' and $estado eq "r") { #$conexao{"$dst-$src"}->{"recebidos"}++; # if (not defined($retardo[$id])) { # print "Algum erro\n"; # print $. . "\n"; # } #$retardo[$id] = $tempo-$retardo[0]; #} if ( $no_prox == $dst and $tipo eq 'tcp' and $estado eq "r") { $conexao{"$src-$dst"}->{"recebidos"}++; if (not defined($tempo[$id])) { print "Algum erro\n"; print $. . "\n"; } $retardo[$i++] = $tempo - $tempo[$id]; } } my $r_total = 0; my $e_total = 0; foreach my $con (keys(%conexao)) { my $e = $conexao{$con}->{"enviados"}; my $r = $conexao{$con}->{"recebidos"}; $e_total += $e; $r_total += $r; printf "Conexao [%5s] taxa de entrega: %10s (%03.2f)\n", $con, "$r/$e", ($r*100.0)/$e; } my $retardo_total = 0; foreach my $r (@retardo) { $retardo_total += $r; } printf "Retardo medio entrega: %f\n", $retardo_total / scalar(@retardo);