NS2 2.35无线LAN仿真脚本报错求助(Ubuntu15.10环境)
NS2无线仿真报错
Classifier::no-slot{}的排查与解决 报错原因分析
这个报错的核心是数据包无法找到对应的接收处理路径,你的脚本存在以下几个关键问题:
- 误用有线链路命令:无线节点通过共享
WirelessChannel通信,不需要手动调用duplex-link创建有线式双向链路,该命令会破坏无线节点的网络结构逻辑。 - 缺少流量接收端配置:仅创建了发送端的UDP Agent和CBR应用,但没有在目标节点创建接收用的
Agent/Null,也未建立UDP发送端与接收端的连接,导致数据包发出后无接收目标,触发分类器无slot错误。 - 无线仿真配置缺失:未设置节点位置、未启用NAM追踪文件,且
node-config中的-topoInstance参数配置错误(应指向拓扑对象而非仿真对象$ns)。
修复后的完整脚本
# Define the simulation scenario set numNodes 60 set val(x) 500 ;# X dimension of the topography set val(y) 500 ;# Y dimension of the topography set val(stop) 100 ;# Simulation end time # Create a new simulation object set ns [new Simulator] # Create trace and nam trace files set tracefd [open wireless.tr w] $ns trace-all $tracefd set namtrace [open output.nam w] $ns namtrace-all-wireless $namtrace $val(x) $val(y) # Set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # Set channel type set val(chan) [new Channel/WirelessChannel] # Configure node parameters $ns node-config -adhocRouting ON \ -llType LL \ -macType Mac/802_11 \ -ifqType Queue/DropTail/PriQueue \ -ifqLen 50 \ -antType Antenna/OmniAntenna \ -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -channel $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace ON # Create nodes and set random positions for {set i 0} {$i < $numNodes} {incr i} { set node($i) [$ns node] $node($i) set X_ [expr rand() * $val(x)] $node($i) set Y_ [expr rand() * $val(y)] $node($i) set Z_ 0.0 } # Traffic generation: set up sender and receiver set udp [new Agent/UDP] $ns attach-agent $node(0) $udp # Create receiver agent on target node (e.g., node(1)) set null [new Agent/Null] $ns attach-agent $node(1) $null $ns connect $udp $null ;# Establish connection between sender and receiver set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set packetSize_ 1000 $cbr set rate_ 1Mbps $cbr set random_ false # Schedule traffic generation $ns at 1.0 "$cbr start" $ns at $val(stop) "$cbr stop" # Define simulation end time and finish procedure proc finish {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace exec nam output.nam & exit 0 } $ns at $val(stop) "finish" # Run the simulation $ns run
关键修改点说明
- 移除了所有
duplex-link相关代码,改用无线拓扑和节点随机位置设置。 - 添加了
Agent/Null作为接收端,并通过$ns connect建立UDP发送端与接收端的关联。 - 启用了trace文件(
.tr和.nam),配置了node-config中的追踪参数,便于后续分析和NAM可视化。 - 修正了
-topoInstance参数,指向正确的拓扑对象$topo。
内容的提问来源于stack exchange,提问作者Nathan H
相关产品推荐
相关产品推荐

