Created
September 25, 2011 00:29
-
-
Save iuridiniz/1240045 to your computer and use it in GitHub Desktop.
(UFRN) Reades AV
This file contains hidden or 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
# Criar nossa rede | |
set ns [ new Simulator ] | |
# cores para o NAM? | |
# arquivo de saida | |
set nf [ open trace.out w] | |
$ns trace-all $nf | |
proc fim {} { | |
global ns nf | |
$ns flush-trace | |
close $nf | |
exit 0 | |
} | |
# criar todos os nos | |
# 20 emissores | |
# 20 roteadores um para cada emissor | |
# 1 roteador cetral | |
# 2 receptores | |
# 2 roteadores um para cada receptor | |
# emissores | |
# colocando varios for para uma enumeracao melhor | |
# emissores vao de 0 - 19 | |
for {set i 0} {$i < 20} { incr i } { | |
set e($i) [$ns node] | |
} | |
# roteadores dos emissores de 20 - 39 mapeados com emissor +20 | |
for {set i 0} {$i < 20} { incr i} { | |
set r_e($i) [$ns node] | |
} | |
# 40 | |
set r_x [$ns node] | |
# 41 | |
set r_d(0) [$ns node] | |
# 42 | |
set r_d(1) [$ns node] | |
# 43 | |
set d(0) [$ns node] | |
# 44 | |
set d(1) [$ns node] | |
for {set i 0} {$i < 20} {incr i} { | |
$ns duplex-link $e($i) $r_e($i) 6Mb 10ms DropTail | |
$ns duplex-link $r_e($i) $r_x 6Mb 0.1ms DropTail | |
} | |
$ns duplex-link $r_x $r_d(0) 10Mb 1ms DropTail | |
$ns duplex-link $r_x $r_d(1) 10Mb 1ms DropTail | |
$ns duplex-link $r_d(0) $d(0) 10Mb 10ms DropTail | |
$ns duplex-link $r_d(1) $d(1) 10Mb 10ms DropTail | |
# FILA | |
$ns queue-limit $r_x $r_d(0) 50 | |
$ns queue-limit $r_x $r_d(1) 50 | |
# abrir conexoes ftp over tcp | |
for {set i 0} {$i < 20} { incr i } { | |
set tcp($i) [ new Agent/TCP ] | |
$tcp($i) set class_ 2 | |
$ns attach-agent $e($i) $tcp($i) | |
set sink($i) [ new Agent/TCPSink ] | |
if { $i < 10 } { | |
$ns attach-agent $d(0) $sink($i) | |
} else { | |
$ns attach-agent $d(1) $sink($i) | |
} | |
$ns connect $tcp($i) $sink($i) | |
$tcp($i) set fid_ 1 | |
set ftp($i) [ new Application/FTP ] | |
$ftp($i) attach-agent $tcp($i) | |
$ftp($i) set type_ FTP | |
# agendar inicio e fim | |
$ns at 0.1 "$ftp($i) start" | |
$ns at 9.9 "$ftp($i) stop" | |
} | |
$ns at 10.0 "fim" | |
$ns run |
This file contains hidden or 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 | |
# | |
#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); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment