这是提示的错误,帮我看看吧!!
can't read "sink0": no such variable
while executing
"attach-expoo-traffic $n0 $sink0 200 2s 1s 100k"
invoked from within
"set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100k]"
(file "wangluo.tcl" line 32)
这是提示的错误!!
下面是我的代码:
set ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#定义4条边
$ns duplex-link $n0 $n3 1Mb 100ms DropTail
$ns duplex-link $n1 $n3 1Mb 100ms DropTail
$ns duplex-link $n2 $n3 1Mb 100ms DropTail
$ns duplex-link $n3 $n4 1Mb 100ms DropTail
proc attach-expoo-traffic { node sink size burst idle rate } {
#获得模拟器实例
set ns [Simulator instance]
#建立连接节点的UDP对象
set source [new Agent/UDP]
$ns attach-agent $node $source
#建立traffic源的对象并设置traffic参数
set traffic [new Application/Traffic/Exponential]
$traffic set packetSize_ $size
$traffic set burst_time_ $burst
$traffic set idle_time_ $idle
$traffic set rate_ $rate
$traffic attach-agent $source
#建立发送者与接收者的关系
$ns connect $source $sink
return $traffic
}
set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100k]
set source1 [attach-expoo-traffic $n1 $sink1 200 2s 1s 200k]
set source2 [attach-expoo-traffic $n2 $sink2 200 2s 1s 300k]
set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
$ns attach-agent $n4 $sink0
$ns attach-agent $n4 $sink1
$ns attach-agent $n4 $sink2
set f0 [open out0.tr w]
set f1 [open out1.tr w]
set f2 [open out2.tr w]
proc record {} {
global sink0 sink1 sink2 f0 f1 f2
#获得模拟器实例
set ns [Simulator instance]
#设置每0.5秒会调用本函数一次
set time 0.5
#记录有多少字节被接收节点接收?
set bw0 [$sink0 set bytes_]
set bw1 [$sink1 set bytes_]
set bw2 [$sink2 set bytes_]
#获得当前的时间
set now [$ns now]
#向文件中写入带宽(单位为MBit/s)
puts $f0 "$now [expr $bw0/$time*8/1000000]"
puts $f1 "$now [expr $bw1/$time*8/1000000]"
puts $f2 "$now [expr $bw2/$time*8/1000000]"
#将接收器接收到的字节重置为0
$sink0 set bytes_ 0
$sink1 set bytes_ 0
$sink2 set bytes_ 0
#重新调用record函数
$ns at [expr $now+$time] "record"
}
proc finish {} {
global f0 f1 f2
#关闭输出文件
close $f0
close $f1
close $f2
#调用Xgraph显示网络仿真曲线
exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
exit 0
}
$ns run
can't read "sink0": no such variable
while executing
"attach-expoo-traffic $n0 $sink0 200 2s 1s 100k"
invoked from within
"set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100k]"
(file "wangluo.tcl" line 32)
这是提示的错误!!
下面是我的代码:
set ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#定义4条边
$ns duplex-link $n0 $n3 1Mb 100ms DropTail
$ns duplex-link $n1 $n3 1Mb 100ms DropTail
$ns duplex-link $n2 $n3 1Mb 100ms DropTail
$ns duplex-link $n3 $n4 1Mb 100ms DropTail
proc attach-expoo-traffic { node sink size burst idle rate } {
#获得模拟器实例
set ns [Simulator instance]
#建立连接节点的UDP对象
set source [new Agent/UDP]
$ns attach-agent $node $source
#建立traffic源的对象并设置traffic参数
set traffic [new Application/Traffic/Exponential]
$traffic set packetSize_ $size
$traffic set burst_time_ $burst
$traffic set idle_time_ $idle
$traffic set rate_ $rate
$traffic attach-agent $source
#建立发送者与接收者的关系
$ns connect $source $sink
return $traffic
}
set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100k]
set source1 [attach-expoo-traffic $n1 $sink1 200 2s 1s 200k]
set source2 [attach-expoo-traffic $n2 $sink2 200 2s 1s 300k]
set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
set sink2 [new Agent/LossMonitor]
$ns attach-agent $n4 $sink0
$ns attach-agent $n4 $sink1
$ns attach-agent $n4 $sink2
set f0 [open out0.tr w]
set f1 [open out1.tr w]
set f2 [open out2.tr w]
proc record {} {
global sink0 sink1 sink2 f0 f1 f2
#获得模拟器实例
set ns [Simulator instance]
#设置每0.5秒会调用本函数一次
set time 0.5
#记录有多少字节被接收节点接收?
set bw0 [$sink0 set bytes_]
set bw1 [$sink1 set bytes_]
set bw2 [$sink2 set bytes_]
#获得当前的时间
set now [$ns now]
#向文件中写入带宽(单位为MBit/s)
puts $f0 "$now [expr $bw0/$time*8/1000000]"
puts $f1 "$now [expr $bw1/$time*8/1000000]"
puts $f2 "$now [expr $bw2/$time*8/1000000]"
#将接收器接收到的字节重置为0
$sink0 set bytes_ 0
$sink1 set bytes_ 0
$sink2 set bytes_ 0
#重新调用record函数
$ns at [expr $now+$time] "record"
}
proc finish {} {
global f0 f1 f2
#关闭输出文件
close $f0
close $f1
close $f2
#调用Xgraph显示网络仿真曲线
exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
exit 0
}
$ns run