RED的TCL脚本(多节点版,非ARED)

set ns [new Simulator] set nd [open out.tr w] $ns trace-all $nd set nf [open out.nam w] $ns namtrace-all $nf set nodenum 30 $ns color 0 Yellow $ns color 1 Blue $ns color 2 Red $ns color 3 Green $ns color 4 Brown for {set i 0} {$i < $nodenum} {incr i} { set s($i) [$ns node] } set r0 [$ns node] set r1 [$ns node] for {set i 0} {$i < $nodenum} {incr i} { set d($i) [$ns node] } $ns duplex-link $r0 $r1 5Mb 20ms RED # Tracing a queue set redq [[$ns link $r0 $r1] queue] set tchan_ [open all.q w] $redq trace curq_ $redq trace ave_ $redq attach $tchan_ for {set i 0} {$i < $nodenum} {incr i} { $ns duplex-link $s($i) $r0 10Mb 2ms DropTail } for {set i 0} {$i < $nodenum} {incr i} { $ns duplex-link $r1 $d($i) 10Mb 2ms DropTail } $ns queue-limit $r0 $r1 50 $ns queue-limit $r1 $r0 50 for {set i 0} {$i < $nodenum} {incr i} { set tcp($i) [$ns create-connection TCP/Reno $s($i) TCPSink $d($i) $i] $tcp($i) set fid_ $i $tcp($i) set window_ 15 set ftp($i) [$tcp($i) attach-source FTP] } for {set i 0} {$i < $nodenum} {incr i} { $ns at 0.0 "$ftp($i) start" } $ns at 20 "finish" proc finish {} { global tchan_ nf nd # # Plot the queue size and average queue size, for RED gateways. # set awkCode { { if ($1 == "Q" && NF>2) { print $2, $3 >> "temp.q"; set end $2 } else if ($1 == "a" && NF>2) print $2, $3 >> "temp.a"; } } set f [open temp.queue w] if { [info exists tchan_] } { close $tchan_ } exec rm -f temp.q temp.a exec touch temp.a temp.q exec awk $awkCode all.q puts $f /"queue exec cat temp.q >@ $f puts $f /n/"ave_queue exec cat temp.a >@ $f close $nf close $nd exit 0 } $ns run

你可能感兴趣的:(tcp,脚本,Tcl,plot)