ns2.35出现can't read "node_(0)":no such variable while executing

「已注销」 2016-10-11 09:13:02
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 ;#mac packet ifq
set val(nn) 2 ;#number of mobilenodes
set val(rp) AODV ;#routing protocol
set val(x) 500 ;#X dimension of the topography
set val(y) 500 ;#Y dimension of the topography
set ns [new Simulator]
set tracefd [open z-wireless_simulator.tr w]
$ns trace-all $tracefd
set namtracefd [open z-wireless_simulator.nam w]
$ns namtrace-all-wireless $namtracefd $val(x) $val(y)
proc finish {} {
global ns tracefd namtracefd
$ns flush-trace
close $tracefd
close $namtracefd
exec nam z-wireless_simulator.nam &
exit 0
}
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
$ns node -config -addressType flat \
-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\
-movementTrace OFF\
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0 ;#disable random motion
}
$node_(0) set X_ 5.0 #问题出现在这里
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0
$ns at 50.0 "$node_(1) setdest 25.0 20.0 15.0"
$ns at 10.0 "$node_(0) setdest 20.0 18.0 1.0"
$ns at 100.0 "$node_(1) setdest 490.0 480.0 15.0"
set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"
for {set i 0} {$i<$val(nn)} {incr i} {
$ns at 150.0 "$node_($i) reset";
}
$ns at 150.0 "finish"
$ns run
...全文
1431 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wya_123幸福 2016-11-29
  • 打赏
  • 举报
回复
可以检查:(1)代码{$ i<val(nn)}与{incr i}之间、{incr i}与{之间是否少了个空格符。(2)$node_(0) set X_ 5.0 ,X_ 和5.0之间是否少了空格符

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧