Simulation NS2 : LAN Ethernet avec n nœuds & graphes fenêtre de congestion
Voici un script Tcl NS2 (ns-2) pour simuler un LAN Ethernet avec plusieurs nœuds, sources de trafic et tracé de fenêtre de congestion :
// ns-2 script: Ethernet LAN with n nodes, congestion window plots 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_ "MAC address"; $node($i) set addr_ "IP address"; $node($i) set cwnd_ 20; } # Traffic sources/sinks 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); } # Ethernet switch set switch [new CMUcsma]; for {set i 0} {$i < $num_nodes} {incr i} { $ns connect $node($i) $switch; } # Staggered start for {set i 0} {$i < $num_nodes} {incr i} { $ns at [expr 0.1+$i*1.0] "$node($i) start"; } $ns run; # Plot congestion windows set plot [new Plot/Xgraph -width 640 -height 480]; $plot set style bars; $plot set xlabel "Time (s)"; $plot set ylabel "Congestion Window Size"; 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;
Ajustez paramètres (nœuds, débits, temps simulation) selon besoins.
