微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决为什么在 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 举报,一经查实,本站将立刻删除。