次の tcl スクリプトを実行しようとしていますが、手順 thpt_rec で
ns: thpt_rec: can't read "tcps(0)": no such variable
while
execution "$tcps(0) set bytes_"
(procedure "thpt_rec " 4 行目)
"thpt_rec"
内から呼び出される
しかし、この tcps(0) をすべての場所で sink という名前の変数に置き換えると、すべてがうまく機能します。この問題に光を当ててください。
set ns [new Simulator]
set tracefile [open tcpf1.tr w]
set thptfile [open thpt.tr w]
$ns trace-all $tracefile
proc finish {} {
global ns tracefile thptfile
$ns flush-trace
close $tracefile
close $thptfile
exit 0
}
proc thpt_rec {} {
global ns tcps(0) thptfile
set time 1.0
set bw [$tcps(0) set bytes_]
set now [$ns now]
puts $thptfile "$now [expr $bw/$time*8/1000000]"
$tcps(0) set bytes_ 0
$ns at [expr $now+$time] "thpt_rec"
}
for {set i 0} {$i < 10} {incr i} {
set n($i) [$ns node]
}
for {set i 0} {$i < 4} {incr i} {
$ns duplex-link $n($i) $n(4) 10Mb 2ms DropTail
$ns duplex-link $n(5) $n([expr ($i+6)]) 10Mb 2ms DropTail
}
$ns duplex-link $n(4) $n(5) 0.25Mb 10ms DropTail
set tcp(0) [new Agent/TCP]
$ns attach-agent $n(0) $tcp(0)
set tcps(0) [new Agent/TCPSink]
$ns attach-agent $n(6) $tcps(0)
$ns connect $tcp(0) $tcps(0)
set ftp(0) [new Application/FTP]
$ftp(0) attach-agent $tcp(0)
$ns at 0.0 "thpt_rec"
for {set i 0} {$i < 1} {incr i} {
$ns at [expr (5.0 * $i )] "$ftp($i) start"
$ns at 140.0 "$ftp($i) stop"
}
$ns at 150.0 "finish"
$ns run