改装SMART TCL不识别变量
Modififed MDART TCL does not recognize variable
我尝试将 M-DART TCL 文件从单通道修改为多通道,同时确保 DHT 仍在运行并且不应用多路径协议。我得到的错误如下:
When configured, ns found the right version of tclsh in /usr/bin/tclsh8.6
but it doesn't seem to be there anymore, so ns will fall back on running the first tclsh in your path. The wrong version of tclsh may break the test suites. Reconfigure and rebuild ns if this is a problem.
num_nodes is set 10
INITIALIZE THE LIST xListHead
INITIALIZE THE LIST xListHead
can't read "node(0)": no such variable
while executing
"$ns attach-agent $node($i) $udp($i)"
("for" body line 3)
invoked from within
"for {set i 0} {$i < $val(n)} {incr i} {
set udp($i) [new Agent/UDP]
$ns attach-agent $node($i) $udp($i)
set dest [expr round([$randomNode value])]
..."
(file "mdart.tcl" line 267)*
但是我已经专门为每个节点编写了变量。我的问题是我哪里做错了?我在下面剪辑了修改后的 tcl 脚本。希望有人可以回答我的问题。谢谢
###########################################
# Define Option
###########################################
set val(chan) Channel/WirelessChannel; #channel type
set val(ant) Antenna/OmniAntenna; #antenna type
set val(propagation) Shado; #propagation model
set val(netif) Phy/WirelessPhy; #network interface type
set val(ll) LL; #link layer type
set val(ifq) Queue/DropTail; #interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(mac) Mac/802_11; #MAC type
set val(rp) MDART; #routing protocol
set val(n) 10.0; #node number
set val(density) 4096; #node density [node/km^2]
set val(end) 206.0; #simulation time [s]
set val(dataStart) 100.0; #data start time [s]
set val(dataStop) [expr $val(end) - 6.0]; #data stop time [s]
set val(seed) 1; #general pseudo-random sequence generator
set val(macFailed) true; #ATR protocol: ns2 MAC failed callback
set val(etxMetric) true; #ATR protocol: ETX route metric
set val(throughput) 5.40; #CBR rate (<= 5.4Mb/s)
#########################################
# Channel Model
#########################################
#Setting antenna at center of node, 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.2
Antenna/OmniAntenna set Gt_ 1.0 ;#transmitter gain
Antenna/OmniAntenna set Gr_ 1.0 ;#receiver gain
Phy/WirelessPhy set L_ 1.0 ;#system loss factor
if {$val(propagation) == "TwoRay"} {
set val(prop) Propagation/TwoRayGround
set prop [new $val(prop)]
Phy/WirelessPhy set CPThresh_ 10.0 ;#capt. thresh. in Watt
Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#carr. sens. thresh.
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;#receive signal thresh
Phy/WirelessPhy set freq_ 2.4e9 ;#chan. freq. (Hz)
Phy/WirelessPhy set Pt_ 0.28 ;#trans. signal power (Watt)
}
if {$val(propagation) == "Shado"} {
set val(prop) Propagation/Shadowing
set prop [new $val(prop)]
$prop set pathlossExp_ 3.8 ;#path loss exponent
$prop set std_db_ 2.0 ;#shadowing deviation (dB)
$prop set seed_ 1 ;#RNG seed
$prop set dist0_ 1.0 ;#ref. distance (m)
$prop set CPThresh_ 10.0 ;#capt. thresh (Watt)
$prop set RXThresh_ 2.37e-13 ;#rec. sign. thresh
$prop set CSThresh_ [expr 2.37e-13 * 0.0427] ;#carr. sens. thresh
$prop set freq_ 2.4e9 ;#chann. freq (Hz)
Phy/WirelessPhy set Pt_ 0.28
}
#####################################################
# Topology Definition
#####################################################
#Scenario creation according to chosen node density
set val(dim) [expr $val(n) / $val(density)]
set val(x) [expr [expr sqrt($val(dim))] * 1000]
set val(y) [expr [expr sqrt($val(dim))] * 1000]
####################################################
# Pseudo-random sequence generator
####################################################
#General pseudo-random sequence geneator
set genSeed [new RNG]
$genSeed seed $val(seed)
set randomSeed [new RandomVariable/Uniform]
$randomSeed use-rng $genSeed
$randomSeed set min_ 1.0
$randomSeed set max_ 100.0
#Mobility model: x node position [m]
set genNodeX [new RNG]
$genNodeX seed [expr [$randomSeed value]]
set randomNodeX [new RandomVariable/Uniform]
$randomNodeX use-rng $genNodeX
$randomNodeX set min_ 1.0
$randomNodeX set max_ [expr $val(x) - 1.0]
#Mobility model: Y node position [m]
set posNodeY [new RNG]
$posNodeY seed [expr [$randomSeed value]]
set randomNodeY [new RandomVariable/Uniform]
$randomNodeY use-rng $posNodeY
$randomNodeY set min_ 1.0
$randomNodeY set max_ [expr $val(y) - 1.0]
#Data pattern: node
set genNode [new RNG]
$genNode seed [expr [$randomSeed value]]
set randomNode [new RandomVariable/Uniform]
$randomNode use-rng $genNode
$randomNode set min_ 0
$randomNode set max_ [expr $val(n) - 1]
################################
# General definition
################################
#Instantiate the simulator
set ns [new Simulator]
#Define topology
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#create GOD
create-god $val(n)
##############################
# Trace file definition
##############################
;#create trace object for ns, nam, monitor and inspect
set tracefile [open ns.tr w] ;#Adding this
$ns trace-all $tracefile ;#adding this
;#new format for wireless traces
$ns use-newtrace
#set namTr [open nam.tr w]
#$ns namtrace-all-wireless $namTr $val(x) $val(y)
#set scenarioTr [open scenario.tr w]
#nam file creation
set namfile [open mdart.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];
#create channel
set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
$prop topography $topo
#Global node setting
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propInstance $prop \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF \
-channel $chan_1_
################################
# Nodes definition
################################
;# Create the specified number of nodes [$val(n)] and "attach" them to the channel.
#for {set i 0} {$i < $val(n) } {incr i} {
# set n($i) [$ns node]
# $n($i) random-motion 0 ; #disabled random motion
#$ns initial_node_pos $n($i) 20 ;
#}
################################
# Node configuration
################################
;#node initial coordinates
set n0 [$ns node]
$n0 random-motion 0
$n0 set X_ 20.0
$n0 set Y_ 65.0
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 random-motion 0
$n1 set X_ 50.0
$n1 set Y_ 10.0
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 random-motion 0
$n2 set X_ 0.0
$n2 set Y_ 0.0
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 random-motion 0
$n3 set X_ 95.0
$n3 set Y_ 35.0
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 random-motion 0
$n4 set X_ 8.0
$n4 set Y_ 50.0
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
$ns node-config \
-channel $chan_2_
set n5 [$ns node]
$n5 random-motion 0
$n5 set X_ 150.0
$n5 set Y_ 165.0
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
set n6 [$ns node]
$n6 random-motion 0
$n6 set X_ 110.0
$n6 set Y_ 80.0
$n6 set Z_ 0.0
$ns initial_node_pos $n6 20
set n7 [$ns node]
$n7 random-motion 0
$n7 set X_ 65.0
$n7 set Y_ 114.0
$n7 set Z_ 0.0
$ns initial_node_pos $n7 20
set n8 [$ns node]
$n8 random-motion 0
$n8 set X_ 50.0
$n8 set Y_ 165.0
$n8 set Z_ 0.0
$ns initial_node_pos $n8 20
set n9 [$ns node]
$n9 random-motion 0
$n9 set X_ 180.0
$n9 set Y_ 100.0
$n9 set Z_ 0.0
$ns initial_node_pos $n9 20
###################################
# Nodes placement
###################################
#parameters for trace Inspect
#puts $scenarioTr "# nodes: $val(n), max time: $val(end)"
#puts $scenarioTr "# nominal range: 250"
#for {set i 0} {$i < $val(n)} {incr i} {
# set X [expr [$randomNodeX value] ]
# $n($i) set X_ $X
# set Y [expr [$randomNodeY value] ]
# $n($i) set Y_ $Y
# $n($i) set Z_ 0.0
# $ns initial_node_pos $n($i) 20
# puts $scenarioTr "$node_($i) set X_ $X"
# puts $scenarioTr "$node_($i) set Y_ $Y"
# puts $scenarioTr "$node_($i) set Z_ 0.0"
#}
###################################
# moving nodes
###################################
#$ns at 3.0 "$n1 setdest 62.0 55.0 25.0"
#$ns at 3.0 "$n7 setdest 52.0 12.0 5.0"
#############################
# Data load
#############################
for {set i 0} {$i < $val(n)} {incr i} {
set udp($i) [new Agent/UDP]
$ns attach-agent $node($i) $udp($i)
set dest [expr round([$randomNode value])]
while {$dest == $i} {
set dest [expr round([$randomNode value])]
}
set monitor($dest) [new Agent/LossMonitor]
$ns attach-agent $node($dest) $monitor($dest)
$ns connect $udp($i) $monitor($dest)
set cbr($i) [new Application/Traffic/CBR]
$cbr($i) attach-agent $udp($i)
$cbr($i) set packetSize_ 1000
$cbr($i) set random_ false
$cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
$ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
$ns at $val(dataStop) "$cbr($i) stop"
}
###################################
# Nodes mobility (data load)
###################################
#for {set i 0} {$i < $val(n)} {incr i} {
# set udp($i) [new Agent/UDP]
# $ns attach-agent $n0 $udp($i)
# set dest [expr round([$randomNode value])]
# while {$dest == $i} {
# set dest [expr round([$randomNode value])]
# }
# set monitor($dest) [new Agent/LossMonitor]
# $ns attach-agent $n($dest) $monitor($dest)
# $ns connect $udp1 $monitor($dest)
# set cbr($i) [new Application/Traffic/CBR]
# $cbr($i) attach-agent $udp($i)
# $cbr($i) set packetSize_ 1000
# $cbr($i) set random_ false
# $cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
# $ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
# $ns at $val(dataStop) "$cbr($i) stop"
#}
###############################
# Routing model (for M-DART)
###############################
if {$val(rp) == "M-DART"} {
Agent/ATR set macFailed_ $val(macFailed)
Agent/ATR set etxMetric_ $val(etxMetric)
}
############################
# Tracing
############################
;#Simulation time print
proc timeTrace { tracePause} {
global ns
set now [$ns now]
$ns at [expr $now + $tracePause] "timeTrace $tracePause"
puts "$now simulation seconds"
}
$ns at 10.0 "timeTrace 10.0"
if {$val(rp) == "MDART"} {
for {set i 0} {$i < $val(n)} {incr i} {
# printing the routing table
$ns at [expr $val(end) - 1.0] "[$n($i) agent 255] routingTablePrint"
# printing the dht table
$ns at [expr $val(end) - 0.5] "[$n($i) agent 255] dhtTablePrint"
}
}
#########################
# Start and end
#########################
for {set i 0} {$i < $val(n) } {incr i} {
$ns at $val(end) "$n($i) reset";
}
$ns at $val(end) "fileTrace"
$ns at $val(end) "$ns halt"
proc fileTrace {} {
#global ns tracefile namTr
global ns tracefile scenarioTr
$ns flush-trace
close $tracefile ;#adding tis
close $scenarioTr
#close $namTr
#exec nam nam.tr &
}
$ns run
您没有在 node
数组中存储节点的句柄,因此无法从该数组读取。
如果您要更改:
set n0 [$ns node]
$n0 random-motion 0
$n0 set X_ 20.0
$n0 set Y_ 65.0
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
至:
set node(0) [$ns node]
$node(0) random-motion 0
$node(0) set X_ 20.0
$node(0) set Y_ 65.0
$node(0) set Z_ 0.0
$ns initial_node_pos $node(0) 20
(其他节点也类似)那么我希望事情开始为您工作。 这只是将一个变量名更改为另一个变量名, 其中目标变量名是数组的一个元素。
我尝试将 M-DART TCL 文件从单通道修改为多通道,同时确保 DHT 仍在运行并且不应用多路径协议。我得到的错误如下:
When configured, ns found the right version of tclsh in /usr/bin/tclsh8.6
but it doesn't seem to be there anymore, so ns will fall back on running the first tclsh in your path. The wrong version of tclsh may break the test suites. Reconfigure and rebuild ns if this is a problem.
num_nodes is set 10
INITIALIZE THE LIST xListHead
INITIALIZE THE LIST xListHead
can't read "node(0)": no such variable
while executing
"$ns attach-agent $node($i) $udp($i)"
("for" body line 3)
invoked from within
"for {set i 0} {$i < $val(n)} {incr i} {
set udp($i) [new Agent/UDP]
$ns attach-agent $node($i) $udp($i)
set dest [expr round([$randomNode value])]
..."
(file "mdart.tcl" line 267)*
但是我已经专门为每个节点编写了变量。我的问题是我哪里做错了?我在下面剪辑了修改后的 tcl 脚本。希望有人可以回答我的问题。谢谢
###########################################
# Define Option
###########################################
set val(chan) Channel/WirelessChannel; #channel type
set val(ant) Antenna/OmniAntenna; #antenna type
set val(propagation) Shado; #propagation model
set val(netif) Phy/WirelessPhy; #network interface type
set val(ll) LL; #link layer type
set val(ifq) Queue/DropTail; #interface queue type
set val(ifqlen) 50; #max packet in ifq
set val(mac) Mac/802_11; #MAC type
set val(rp) MDART; #routing protocol
set val(n) 10.0; #node number
set val(density) 4096; #node density [node/km^2]
set val(end) 206.0; #simulation time [s]
set val(dataStart) 100.0; #data start time [s]
set val(dataStop) [expr $val(end) - 6.0]; #data stop time [s]
set val(seed) 1; #general pseudo-random sequence generator
set val(macFailed) true; #ATR protocol: ns2 MAC failed callback
set val(etxMetric) true; #ATR protocol: ETX route metric
set val(throughput) 5.40; #CBR rate (<= 5.4Mb/s)
#########################################
# Channel Model
#########################################
#Setting antenna at center of node, 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.2
Antenna/OmniAntenna set Gt_ 1.0 ;#transmitter gain
Antenna/OmniAntenna set Gr_ 1.0 ;#receiver gain
Phy/WirelessPhy set L_ 1.0 ;#system loss factor
if {$val(propagation) == "TwoRay"} {
set val(prop) Propagation/TwoRayGround
set prop [new $val(prop)]
Phy/WirelessPhy set CPThresh_ 10.0 ;#capt. thresh. in Watt
Phy/WirelessPhy set CSThresh_ 1.559e-11 ;#carr. sens. thresh.
Phy/WirelessPhy set RXThresh_ 3.652e-10 ;#receive signal thresh
Phy/WirelessPhy set freq_ 2.4e9 ;#chan. freq. (Hz)
Phy/WirelessPhy set Pt_ 0.28 ;#trans. signal power (Watt)
}
if {$val(propagation) == "Shado"} {
set val(prop) Propagation/Shadowing
set prop [new $val(prop)]
$prop set pathlossExp_ 3.8 ;#path loss exponent
$prop set std_db_ 2.0 ;#shadowing deviation (dB)
$prop set seed_ 1 ;#RNG seed
$prop set dist0_ 1.0 ;#ref. distance (m)
$prop set CPThresh_ 10.0 ;#capt. thresh (Watt)
$prop set RXThresh_ 2.37e-13 ;#rec. sign. thresh
$prop set CSThresh_ [expr 2.37e-13 * 0.0427] ;#carr. sens. thresh
$prop set freq_ 2.4e9 ;#chann. freq (Hz)
Phy/WirelessPhy set Pt_ 0.28
}
#####################################################
# Topology Definition
#####################################################
#Scenario creation according to chosen node density
set val(dim) [expr $val(n) / $val(density)]
set val(x) [expr [expr sqrt($val(dim))] * 1000]
set val(y) [expr [expr sqrt($val(dim))] * 1000]
####################################################
# Pseudo-random sequence generator
####################################################
#General pseudo-random sequence geneator
set genSeed [new RNG]
$genSeed seed $val(seed)
set randomSeed [new RandomVariable/Uniform]
$randomSeed use-rng $genSeed
$randomSeed set min_ 1.0
$randomSeed set max_ 100.0
#Mobility model: x node position [m]
set genNodeX [new RNG]
$genNodeX seed [expr [$randomSeed value]]
set randomNodeX [new RandomVariable/Uniform]
$randomNodeX use-rng $genNodeX
$randomNodeX set min_ 1.0
$randomNodeX set max_ [expr $val(x) - 1.0]
#Mobility model: Y node position [m]
set posNodeY [new RNG]
$posNodeY seed [expr [$randomSeed value]]
set randomNodeY [new RandomVariable/Uniform]
$randomNodeY use-rng $posNodeY
$randomNodeY set min_ 1.0
$randomNodeY set max_ [expr $val(y) - 1.0]
#Data pattern: node
set genNode [new RNG]
$genNode seed [expr [$randomSeed value]]
set randomNode [new RandomVariable/Uniform]
$randomNode use-rng $genNode
$randomNode set min_ 0
$randomNode set max_ [expr $val(n) - 1]
################################
# General definition
################################
#Instantiate the simulator
set ns [new Simulator]
#Define topology
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#create GOD
create-god $val(n)
##############################
# Trace file definition
##############################
;#create trace object for ns, nam, monitor and inspect
set tracefile [open ns.tr w] ;#Adding this
$ns trace-all $tracefile ;#adding this
;#new format for wireless traces
$ns use-newtrace
#set namTr [open nam.tr w]
#$ns namtrace-all-wireless $namTr $val(x) $val(y)
#set scenarioTr [open scenario.tr w]
#nam file creation
set namfile [open mdart.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];
#create channel
set chan_1_ [new $val(chan)]
set chan_2_ [new $val(chan)]
$prop topography $topo
#Global node setting
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propInstance $prop \
-phyType $val(netif) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF \
-channel $chan_1_
################################
# Nodes definition
################################
;# Create the specified number of nodes [$val(n)] and "attach" them to the channel.
#for {set i 0} {$i < $val(n) } {incr i} {
# set n($i) [$ns node]
# $n($i) random-motion 0 ; #disabled random motion
#$ns initial_node_pos $n($i) 20 ;
#}
################################
# Node configuration
################################
;#node initial coordinates
set n0 [$ns node]
$n0 random-motion 0
$n0 set X_ 20.0
$n0 set Y_ 65.0
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 random-motion 0
$n1 set X_ 50.0
$n1 set Y_ 10.0
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 random-motion 0
$n2 set X_ 0.0
$n2 set Y_ 0.0
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 random-motion 0
$n3 set X_ 95.0
$n3 set Y_ 35.0
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 random-motion 0
$n4 set X_ 8.0
$n4 set Y_ 50.0
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
$ns node-config \
-channel $chan_2_
set n5 [$ns node]
$n5 random-motion 0
$n5 set X_ 150.0
$n5 set Y_ 165.0
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
set n6 [$ns node]
$n6 random-motion 0
$n6 set X_ 110.0
$n6 set Y_ 80.0
$n6 set Z_ 0.0
$ns initial_node_pos $n6 20
set n7 [$ns node]
$n7 random-motion 0
$n7 set X_ 65.0
$n7 set Y_ 114.0
$n7 set Z_ 0.0
$ns initial_node_pos $n7 20
set n8 [$ns node]
$n8 random-motion 0
$n8 set X_ 50.0
$n8 set Y_ 165.0
$n8 set Z_ 0.0
$ns initial_node_pos $n8 20
set n9 [$ns node]
$n9 random-motion 0
$n9 set X_ 180.0
$n9 set Y_ 100.0
$n9 set Z_ 0.0
$ns initial_node_pos $n9 20
###################################
# Nodes placement
###################################
#parameters for trace Inspect
#puts $scenarioTr "# nodes: $val(n), max time: $val(end)"
#puts $scenarioTr "# nominal range: 250"
#for {set i 0} {$i < $val(n)} {incr i} {
# set X [expr [$randomNodeX value] ]
# $n($i) set X_ $X
# set Y [expr [$randomNodeY value] ]
# $n($i) set Y_ $Y
# $n($i) set Z_ 0.0
# $ns initial_node_pos $n($i) 20
# puts $scenarioTr "$node_($i) set X_ $X"
# puts $scenarioTr "$node_($i) set Y_ $Y"
# puts $scenarioTr "$node_($i) set Z_ 0.0"
#}
###################################
# moving nodes
###################################
#$ns at 3.0 "$n1 setdest 62.0 55.0 25.0"
#$ns at 3.0 "$n7 setdest 52.0 12.0 5.0"
#############################
# Data load
#############################
for {set i 0} {$i < $val(n)} {incr i} {
set udp($i) [new Agent/UDP]
$ns attach-agent $node($i) $udp($i)
set dest [expr round([$randomNode value])]
while {$dest == $i} {
set dest [expr round([$randomNode value])]
}
set monitor($dest) [new Agent/LossMonitor]
$ns attach-agent $node($dest) $monitor($dest)
$ns connect $udp($i) $monitor($dest)
set cbr($i) [new Application/Traffic/CBR]
$cbr($i) attach-agent $udp($i)
$cbr($i) set packetSize_ 1000
$cbr($i) set random_ false
$cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
$ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
$ns at $val(dataStop) "$cbr($i) stop"
}
###################################
# Nodes mobility (data load)
###################################
#for {set i 0} {$i < $val(n)} {incr i} {
# set udp($i) [new Agent/UDP]
# $ns attach-agent $n0 $udp($i)
# set dest [expr round([$randomNode value])]
# while {$dest == $i} {
# set dest [expr round([$randomNode value])]
# }
# set monitor($dest) [new Agent/LossMonitor]
# $ns attach-agent $n($dest) $monitor($dest)
# $ns connect $udp1 $monitor($dest)
# set cbr($i) [new Application/Traffic/CBR]
# $cbr($i) attach-agent $udp($i)
# $cbr($i) set packetSize_ 1000
# $cbr($i) set random_ false
# $cbr($i) set rate_ [expr $val(throughput) / [expr $val(n) * sqrt($val(n))]]Mb
# $ns at [expr $val(dataStart) + [$randomSeed value]] "$cbr($i) start"
# $ns at $val(dataStop) "$cbr($i) stop"
#}
###############################
# Routing model (for M-DART)
###############################
if {$val(rp) == "M-DART"} {
Agent/ATR set macFailed_ $val(macFailed)
Agent/ATR set etxMetric_ $val(etxMetric)
}
############################
# Tracing
############################
;#Simulation time print
proc timeTrace { tracePause} {
global ns
set now [$ns now]
$ns at [expr $now + $tracePause] "timeTrace $tracePause"
puts "$now simulation seconds"
}
$ns at 10.0 "timeTrace 10.0"
if {$val(rp) == "MDART"} {
for {set i 0} {$i < $val(n)} {incr i} {
# printing the routing table
$ns at [expr $val(end) - 1.0] "[$n($i) agent 255] routingTablePrint"
# printing the dht table
$ns at [expr $val(end) - 0.5] "[$n($i) agent 255] dhtTablePrint"
}
}
#########################
# Start and end
#########################
for {set i 0} {$i < $val(n) } {incr i} {
$ns at $val(end) "$n($i) reset";
}
$ns at $val(end) "fileTrace"
$ns at $val(end) "$ns halt"
proc fileTrace {} {
#global ns tracefile namTr
global ns tracefile scenarioTr
$ns flush-trace
close $tracefile ;#adding tis
close $scenarioTr
#close $namTr
#exec nam nam.tr &
}
$ns run
您没有在 node
数组中存储节点的句柄,因此无法从该数组读取。
如果您要更改:
set n0 [$ns node]
$n0 random-motion 0
$n0 set X_ 20.0
$n0 set Y_ 65.0
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
至:
set node(0) [$ns node]
$node(0) random-motion 0
$node(0) set X_ 20.0
$node(0) set Y_ 65.0
$node(0) set Z_ 0.0
$ns initial_node_pos $node(0) 20
(其他节点也类似)那么我希望事情开始为您工作。 这只是将一个变量名更改为另一个变量名, 其中目标变量名是数组的一个元素。