我正在尝试在 ns2 中创建简单的网络拓扑。
#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 的标签后正确放置它。