Se nos pidió hacer una simulación de una situación real, por lo que decidí hacer algo sencillo como una simulación de un protocolo VoIp como lo podemos encontrar en Skype, Face Time, Google Hangouts. Lo hice lo más sencillo que pude, solo simulando que dos usuarios establecen una llamada en Skype.
En el protocolo VoIp se transmiten paquetes tipo UDP y utilicé un protocolo de ruteo tipo DV (Distance Vector).
Código de la topología:
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
set ns [new Simulator] | |
$ns color 1 Green | |
$ns color 2 Red | |
set f [open skype.tr w] | |
set nf [open skype.nam w] | |
ns trace-all f | |
ns namtrace-all nf | |
proc finish {} { | |
global ns f nf | |
$ns flush-trace | |
close $f | |
close $nf | |
exec nam skype.nam & | |
exit 0 | |
} | |
set n0 [$ns node] | |
set n1 [$ns node] | |
$n0 label "1" | |
$n1 label "2" | |
ns duplex-link n0 $n1 1.5Mb 50ms DropTail | |
ns duplex-link-op n0 $n1 orient left | |
set udp [new Agent/UDP] | |
ns attach-agent n0 $udp | |
$udp set fid_ 1 | |
set udp1 [new Agent/UDP] | |
ns attach-agent n1 $udp1 | |
$udp1 set fid_ 2 | |
set sink0 [new Agent/LossMonitor] | |
ns attach-agent n0 $sink0 | |
ns connect udp1 $sink0 | |
set sink1 [new Agent/LossMonitor] | |
ns attach-agent n1 $sink1 | |
ns connect udp $sink1 | |
ns at 0.3 "cbr0 start" | |
ns at 0.3 "cbr1 start" | |
ns at 1.0 "cbr0 stop" | |
ns at 1.0 "cbr1 stop" | |
$ns at 1.2 "finish" | |
$ns run |
Una de las medidas que evalué fue throughput que es la cantidad de bits que se transmiten exitosamente por segundo. Para obtener esta medida se suma el total de bits que se enviaron de un nodo a otro y el resultado se divide entre la duración total de la transmisión
Código awk:
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
BEGIN { | |
fromNode=1; | |
toNode=0; | |
counter = 0; | |
totalBits = 0; | |
} | |
{ | |
if(5 == fromNode && 7==toNode){ | |
totalBits += 8*$11; | |
if ( ounter==0 ) { | |
timeBegin = $3; | |
counter++; | |
}else { | |
timeEnd = $3; | |
} | |
} | |
} | |
END{ | |
duration = timeEnd-timeBegin; | |
print "Bits transmitidos: " totalBits " bits"; | |
print "Throughput: " totalBits/duration/1e3 " kbps."; | |
} |
Otra de las medidas que evalué fue la cantidad de paquetes perdidos, utilicé el siguiente script de awk:
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
BEGIN { | |
#losts = paquetes perdidos | |
#sent = los paquetes enviados | |
losts = 0; | |
sent = 0; | |
} | |
{ | |
action = $1; | |
from = $5; | |
to = $7; | |
flow_id = $8; | |
if (from==0 && to==1 && action == "+") | |
sent++; | |
if (flow_id==2 && action == "d") | |
losts++; | |
} | |
END { | |
printf("Paquetes enviados: %d\n", sent); | |
printf("Paquetes perdidos: %d\n", losts); | |
} |
Para calcular el jitter se calcula la diferencia entre el tiempo anterior y el actual, dividiendolo entre la diferencia del número de secuencia anterior y actual.
En esta simulación se obtiene un jitter de 0 ya que utilicé un generador de tráfico constante.
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
BEGIN { | |
maxPacktid = 0; | |
} | |
{ | |
action = $1; | |
time = $2; | |
pktsize = $6; | |
flow_id = $8; | |
seq_no = $11; | |
packet_id = $12; | |
if ( packet_id > maxPacktid ) { | |
maxPacktid = packet_id; | |
} | |
if ( start_time[packet_id] == 0 ) { | |
pkt_seqno[packet_id] = seq_no; | |
start_time[packet_id] = time; | |
} | |
if ( flow_id == 2 && action != "d" ) { | |
if ( action == "r" ) { | |
end_time[packet_id] = time; | |
} | |
}else { | |
end_time[packet_id] = -1; | |
} | |
} | |
END { | |
last_seqno = 0; | |
last_delay = 0; | |
seqno_diff = 0; | |
for (packet_id = 0; packet_id <= maxPacktid; packet_id++ ) { | |
start = start_time[packet_id]; | |
start = start_time[packet_id]; | |
end = end_time[packet_id]; | |
packet_duration = end - start; | |
if ( start < end ) { | |
seqno_diff = pkt_seqno[packet_id]-last_seqno; | |
delay_diff = packet_duration-last_delay; | |
if (seqno_diff == 0) { | |
jitter =0; | |
} else { | |
jitter = delay_diff/seqno_diff; | |
} | |
} | |
} | |
} | |
END { | |
printf("jitter: %f\n", jitter); | |
last_seqno = pkt_seqno[packet_id]; | |
last_delay = packet_duration; | |
} |
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
BEGIN { | |
fromNode=1; toNode=0; | |
num_samples = 0; | |
total_delay = 0; | |
} | |
/^\+/&&5==fromNode&&7==toNode { | |
t_arr[15] = 3; | |
}; | |
/^r/&&5==fromNode&&7==toNode { | |
if (t_arr[$15] > 0) { | |
num_samples++; | |
delay = 3 - t_arr[15]; | |
total_delay += delay; | |
}; | |
}; | |
END{ | |
avg_delay = total_delay/num_samples; | |
print "N" fromNode "->N" toNode; | |
print " - Delay: " avg_delay " s"; | |
}; |
Las medidas de desempeño sería bueno graficar. Y habría que tener más maneras de generar tráfico. Infórmate bien sobre la tarea que sigue. 5 pts.
ReplyDelete