Aqui está um script Tcl NS2 (ns-2) para simular LAN Ethernet com múltiplos nós, fontes de tráfego e plotagem de janela de congestionamento:
// script ns-2: LAN Ethernet com n nós, gráficos janela congestionamento import ns_lib; import tcl_lib; set sim_time 100s; set num_nodes 10; set ifq 1000; for {set i 0} {$i < $num_nodes} {incr i} { set node($i) [new Agent/TCP]; $ns attach-agent $node($i); $node($i) set MAC_ "endereço MAC"; $node($i) set addr_ "endereço IP"; $node($i) set cwnd_ 20; } # Fontes/sinks de tráfego for {set i 0} {$i < $num_nodes} {incr i} { $node($i) set traffic_type CBR; $node($i) set start_time_ 0s; $node($i) set cbr_rate_ 100Kbps; $node($i) set rtt_ 50ms; $node($i) set packetDest_ "10.$i.2.1"; set sink($i) [new Agent/Null]; $sink($i) set addr_ "10.$i.2.1"; $ns attach-agent $sink($i); } # Switch Ethernet set switch [new CMUcsma]; for {set i 0} {$i < $num_nodes} {incr i} { $ns connect $node($i) $switch; } # Início escalonado for {set i 0} {$i < $num_nodes} {incr i} { $ns at [expr 0.1+$i*1.0] "$node($i) start"; } $ns run; # Plot janelas de congestionamento set plot [new Plot/Xgraph -width 640 -height 480]; $plot set style bars; $plot set xlabel "Tempo (s)"; $plot set ylabel "Tamanho Janela Congestionamento"; for {set i 0} {$i < $num_nodes} {incr i} { $plot add $node($i) cwnd_; $plot add Legend $node($i); } $plot set autoscale on; $plot save graph.png;
Ajuste parâmetros (nós, taxas, tempo de simulação) conforme necessário.
Tecnologia Eletrônica © [www.351231.com]