NS2 执行Tcl脚本文件时的错误提示及解决方法

1,开始运行脚本时提示如下错误:

can't read "link_(2:3)": no such variable
    while executing
"eval $link_([$n1 id]:[$n2 id]) $op $args"
    (procedure "_o3" line 3)
    (Simulator duplex-link-op line 3)
    invoked from within
"$ns duplex-link-op $n2 $n3 color green"
    (file "test.tcl" line 31)
wl@ubuntu:~/program/ns-allinone-2.33/test$ ns test.tcl
wl@ubuntu:~/program/ns-allinone-2.33/test$ ns test.tcl
can't read "ns_": no such variable
    while executing
"$ns_ at 0.1 “$cbr1 start”"
    (file "test.tcl" line 79)
wl@ubuntu:~/program/ns-allinone-2.33/test$ ns test.tcl
can't read "ns_": no such variable
    while executing
"$ns_ at 0.1 “$cbr1 start”"
    (file "test.tcl" line 80)

原因是全角半角问题,源程序的全角应该改为半角,如下:

$ns_ at 0.1 “$cbr1 start”

$ns_ at 4.5 “$cbr1 stop”

$ns_ at 1.0 “$ftp1 start”

$ns_ at 4.0 “$ftp1 stop”

$ns_ at 4.5 “finish”

$ns_ run

改为:

$ns at 0.1 "$cbr1 start"
$ns at 4.5 "$cbr1 stop"
$ns at 1.0 "$ftp1 start"
$ns at 4.0 "$ftp1 stop"


$ns at 4.5 "finish"
$ns run

就OK了

2.添加节点和链路颜色是提示如下错误:$ns_ at 4.0 “$ftp1 stop”

NS2 执行Tcl脚本文件时的错误提示及解决方法_第1张图片s_ run

原因:仔细研究发现,我的定义节点和链路颜色的语句在定义节点的前面,源代码如下:

#指定节点颜色
$n1 color red
#指定链路颜色
$ns duplex-link-op $n2 $n3 color green

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

改为:

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

#指定节点颜色
$n1 color red
#指定链路颜色
$ns duplex-link-op $n2 $n3 color green

则可以得到正确结果,如下:

NS2 执行Tcl脚本文件时的错误提示及解决方法_第2张图片

你可能感兴趣的:(NS2 执行Tcl脚本文件时的错误提示及解决方法)