为什么在 TCL 中的命令没有显示结果?

问题描述

我正在尝试在 ns2 中创建简单的网络拓扑。

network topology image

#Create a simulator object
set ns [new Simulator]

#Open the NAM trac file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedrue
proc finish {} {
      global ns nf
      $ns flush-trace
      #Close the NAM trace file
      close $nf
      #Execute NAM on the trace file
      exec nam out.nam &
      exit 0
}

#Create four nodes
for {set i 0} {$i < 6} {incr i} {
    set n$i [$ns node]
}
#Changing node colors
$n0 color "red"
$n1 color "yellow"
$n3 color "green"
$n4 color "blue"
#Adding node label
$n0 label "S1"
$n1 label "S2"
$n3 label "D1"
$n4 label "D2"
$n4 label-color "yellow"

#Changing label color
$n0 label-color "green"
$n1 label-color "blue"
$n3 label-color "red"
#Changing shapes
$n2 shape hexagon
$n5 shape hexagon
$n3 shape square
$n4 shape square

#Create the links between the nodes
$ns duplex-link $n0 $n2 10Mb 15ms RED
$ns duplex-link $n1 $n2 10Mb 15ms RED
$ns duplex-link $n2 $n5 10Mb 20ms RED
$ns duplex-link $n5 $n3 12Mb 15ms RED
$ns duplex-link $n4 $n5 10Mb 20ms RED

#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n5 orient right
$ns duplex-link-op $n5 $n3 orient right-up
$ns duplex-link-op $n4 $n5 orient left-up

#Change color of link's
$ns duplex-link-op $n0 $n2 color "purple"
$ns duplex-link-op $n1 $n2 color "purple"
$ns duplex-link-op $n5 $n3 color "purple"
$ns duplex-link-op $n4 $n5 color "purple"

#Labling link's
$ns duplex-link-op $n0 $n2 label "<10,15>"
$ns duplex-link-op $n1 $n2 label "<10,15>"
$ns duplex-link-op $n2 $n5 label "<10,20>"
$ns duplex-link-op $n5 $n3 label "<12,15>"
$ns duplex-link-op $n4 $n5 label "<12,15>"

#Calling finish procedure
$ns at 10.0 "finish"
$ns run

我的所有输出都正确,但是标记 n4 到 n5 的链接不起作用。但是当我将此行移到更改链接颜色的上块时,它起作用了。这是为什么?

当我尝试更改节点 4 的颜色时也发生了同样的情况。这就是为什么我必须在更改节点 4 的标签后正确放置它。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)