我是ns2模拟的新手,如果这个问题很简单,我很抱歉。这是我的tcl代码,我使用以下代码创建了我的方案文件:
./setdest -n 250 -p 0.0 -M 10.0 -t 10 -x 1500 -y 1500 > S250
以及
ns cbrgen.tcl -type tcp -nn 250 -seed 1.0 -mc 100 > T250
但是当我尝试运行模拟时,我显示了这个错误。
can't read "ns_": no such variable
while executing
"global $ns_"
(file "wireless.tcl" line 24)
你能帮帮我这个话题吗?非常感谢。
# ======================================================================
# Define options
# ======================================================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 250 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(cp) T250
set val(sc) S250
# ==================================================== =================
# Main Program
# ======================================================================
set ns [new Simulator]
set tracefd [open out.tr w]
set winfile [open winFile w]
global $ns_
$ns trace-all $tracefd
set namtrace [open out.nam w]
$ns namtrace-all-wireless $namtrace 1500 1500
set topo [new Topography]
$topo load_flatgrid 1500 1500
create-god $val(nn)
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-mvementTrace ON \
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
}
puts "Loading scenario file..."
source $val(sc)
puts "Loading connection pattern..."
source $val(cp)
# Tell nodes when the simulation ends
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 10.0 "$node_($i) reset";
}
$ns_ at 10.0 "stop"
$ns_ at 10.01 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
global ns_ tracefd
$ns_ flush-trace
close $tracefd
exec nam out.nam &
exit 0
}
puts "Starting Simulation..."
$ns_ run
答案 0 :(得分:3)
尝试
global ns_
而不是
global $ns_
ns_
是变量的名称。 $ns_
是变量的值。你用它的名字声明它。
答案 1 :(得分:0)
事实上,答案很简单,你没有在全局内存空间中声明变量“ns_”。
我在以下链接中详细解释了
http://www.projectguideline.com/topic/cant-read-ns_-no-such-variable-what-causes-this-ns-2-error/