c++ - NS2:AODV 路由消息卡在队列中

标签 c++ simulator ns2

我正在使用 AODV 路由协议(protocol)在 NS2.35 中运行一些简单的模拟。然而,在某些情况下,我注意到,当我运行模拟足够长的时间时,AODV REQUEST 和 REPLY 消息不会被发送出去并填满节点队列。

在下面的 .tcl 示例中,我有 3 个节点生成要发送到 PAN 协调器的 CBR 流量。然而,在某些时候,路由请求和回复不断被 IFQ 级别的节点 2 丢弃。

此外,如以下跟踪片段所示,在模拟结束时(时间=10000)节点 2 的 IFQ 被请求填满,尽管在模拟结束时有足够的时间清空队列.

s 9353.439721046 _2_ RTR  --- 0 AODV 48 [0 ffffffff 1 800] ------- [2:255 -1:255 2 0] [0x2 2 37 [0 149] [1 76]] (REQUEST)
D 9353.439746046 _2_ IFQ  --- 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 3 0] [0x2 2 20 [0 105] [3 42]] (REQUEST)
s 9353.441744607 _3_ MAC  --- 0 AODV 55 [0 ffffffff 3 800] ------- [3:255 -1:255 2 0] [0x2 2 37 [0 149] [1 76]] (REQUEST)
r 9353.444336620 _2_ MAC  --- 0 AODV 48 [0 ffffffff 3 800] ------- [3:255 -1:255 2 0] [0x2 2 37 [0 149] [1 76]] (REQUEST)
r 9353.444336633 _1_ MAC  --- 0 AODV 48 [0 ffffffff 3 800] ------- [3:255 -1:255 2 0] [0x2 2 37 [0 149] [1 76]] (REQUEST)
r 9353.444361620 _2_ RTR  --- 0 AODV 48 [0 ffffffff 3 800] ------- [3:255 -1:255 2 0] [0x2 2 37 [0 149] [1 76]] (REQUEST)
r 9353.444361633 _1_ RTR  --- 0 AODV 48 [0 ffffffff 3 800] ------- [3:255 -1:255 2 0] [0x2 2 37 [0 149] [1 76]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 2 0] [0x2 2 37 [0 149] [1 76]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 3 0] [0x2 2 30 [0 139] [3 62]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 4 0] [0x2 2 36 [0 143] [1 74]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 30 0] [0x2 1 103 [0 49] [2 208]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 2 0] [0x2 2 35 [0 143] [1 72]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 30 0] [0x2 1 102 [0 49] [2 206]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 30 0] [0x2 1 101 [0 49] [2 204]] (REQUEST)
D 10000.000000000 _2_ IFQ  END 0 AODV 48 [0 ffffffff 2 800] ------- [2:255 -1:255 30 0] [0x2 1 100 [0 49] [2 202]] (REQUEST)

知道发生了什么吗?

更新: 显然,在某些时候 REQUEST 消息在 RTR 级别生成但没有被发送出去,然后流量被丢弃,因为节点没有及时收到路由回复。这是一个显示此内容的跟踪示例:

s 2417.739768850 _2_ AGT  --- 23 cbr 70 [0 0 0 0] ------- [2:0 0:1 32 0] [7] 0 0
r 2417.739768850 _2_ RTR  --- 23 cbr 70 [0 0 0 0] ------- [2:0 0:1 32 0] [7] 0 0
s 2417.739768850 _2_ RTR  --- 0 AODV 48 [0 0 0 0] ------- [2:255 -1:255 30 0] [0x2 1 16 [0 49] [2 34]] (REQUEST)
s 2418.500000000 _2_ RTR  --- 0 AODV 48 [0 0 0 0] ------- [2:255 -1:255 30 0] [0x2 1 17 [0 49] [2 36]] (REQUEST)
s 2419.500000000 _2_ RTR  --- 0 AODV 48 [0 0 0 0] ------- [2:255 -1:255 30 0] [0x2 1 18 [0 49] [2 38]] (REQUEST)
s 2421.000000000 _2_ RTR  --- 0 AODV 48 [0 0 0 0] ------- [2:255 -1:255 30 0] [0x2 1 19 [0 49] [2 40]] (REQUEST)
D 2423.000000000 _2_ RTR  NRTE 23 cbr 90 [0 0 0 0] ------- [2:0 0:1 30 0] [7] 0 0

请注意,在我遇到此问题的所有示例中,每次生成 CBR 消息时,之前的路由已经过期,必须找到新的路由。我认为这可能会导致某处出现错误。

TCL file:

set tr .tr

set nam .nam

set fname [file rootname $argv0]





# Parameters Settings

set val(chan)           Channel/WirelessChannel    ;# Channel Model: Wireless

set val(prop)           Propagation/TwoRayGround   ;# Propragation Model: Shadowing (Shadowing/TwoRayGround/FreeSpace) 

set val(netif)          Phy/WirelessPhy/802_15_4

set val(mac)            Mac/802_15_4

set val(ifq)            Queue/DropTail/PriQueue    ;# Queue Model: Drop at Tail

set val(ll)             LL                         ;# Link Layer Model

set val(ant)            Antenna/OmniAntenna        ;# Antenna Model

set val(ifqlen)         64                         ;# Max Number of Queue

set val(nn)             4                         ;# Number of Nodes

set val(rp)             AODV                       ;# Routing Protocol: AODV (DSR/ZBR/AOMDV/AODV)

set val(x)      0              ;# Center Position of nam

set val(y)      0

set val(tr)     $fname$tr          ;# Tracing File

set val(nam)        $fname$nam         ;# Nam File

set val(traffic)    cbr                        ;# Data Flow: cbr (cbr/poisson/ftp)

set val(trInterval) 0.01               ;# Time Interval between Packets

set val(startInterval)  0.5            ;# Start Time

set stopTime            10000              ;# Stop Time



# For model 'TwoRayGround'

set dist(5m)  7.69113e-06

set dist(9m)  2.37381e-06

set dist(10m) 1.92278e-06

set dist(11m) 1.58908e-06

set dist(12m) 1.33527e-06

set dist(13m) 1.13774e-06

set dist(14m) 9.81011e-07

set dist(15m) 8.54570e-07

set dist(16m) 7.51087e-07

set dist(20m) 4.80696e-07

set dist(25m) 3.07645e-07

set dist(30m) 2.13643e-07

set dist(35m) 1.56962e-07

set dist(40m) 1.20174e-07

Phy/WirelessPhy set CSThresh_ $dist(10m)

Phy/WirelessPhy set RXThresh_ $dist(10m)



# Input

proc getCmdArgu {argc argv} {

        global val

        for {set i 0} {$i < $argc} {incr i} {

                set arg [lindex $argv $i]

                if {[string range $arg 0 0] != "-"} continue

                set name [string range $arg 1 end]

                set val($name) [lindex $argv [expr $i+1]]

        }

}

getCmdArgu $argc $argv



# Initial Global Variables

set ns_     [new Simulator]

set tracefd     [open ./$val(tr) w]

# $ns_ use-newtrace

$ns_ trace-all $tracefd



# Topology Configuration

set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)



set god_ [create-god $val(nn)]



set chan_1_ [new $val(chan)]



# Node Configuration

$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) \

        -topoInstance $topo \

        -agentTrace ON  \

        -routerTrace ON \

        -macTrace ON \

        -movementTrace OFF \

        -channel $chan_1_





for {set i 0} {$i < $val(nn) } {incr i} {

    set node_($i) [$ns_ node]

    $node_($i) random-motion 0      

}



#########################################################



# Topology Input

for {set i 0} {$i < $val(nn)} {incr i} {

$node_($i) set X_ [expr 4*$i]

$node_($i) set Y_ 0

$node_($i) set Z_ 0

}



# Start Coordinate/Normal Nodes

$ns_ at 0.0 "$node_(0) NodeLabel \"PAN Coor\""

$ns_ at 0.0 "$node_(0) sscs startPANCoord 0"    



for {set i 1} {$i < $val(nn)} {incr i} {

    $ns_ at [expr $i*($val(startInterval))] "$node_($i) sscs startDevice"

}



#########################################################





# Setup UDP and CBR

proc cbrtraffic { src dst interval starttime } {

   global ns_ node_

   set udp_($src) [new Agent/UDP]

   eval $ns_ attach-agent \$node_($src) \$udp_($src)

   set null_($dst) [new Agent/Null]

   eval $ns_ attach-agent \$node_($dst) \$null_($dst)

   set cbr_($src) [new Application/Traffic/CBR]

   eval \$cbr_($src) set packetSize_ 70

   eval \$cbr_($src) set rate_ 250kb

   eval \$cbr_($src) set interval_ $interval

   eval \$cbr_($src) set random_ 1

   #eval \$cbr_($src) set maxpkts_ 1000

   eval \$cbr_($src) attach-agent \$udp_($src)

   eval $ns_ connect \$udp_($src) \$null_($dst)

   $ns_ at $starttime "$cbr_($src) start"

   $ns_ at 9500 "$cbr_($src) stop"

}





# ACK

if {$val(rp) == "ZBR"} {

# 0=No ACK; 1=ACK at failure (default); 2=ACK at success/failure

    Mac/802_15_4 wpanCmd callBack 2;

}

if { ("$val(traffic)" == "cbr") || ("$val(traffic)" == "poisson") } {

   puts "\nTraffic: $val(traffic)"

   puts [format "Acknowledgement for data: %s" [Mac/802_15_4 wpanCmd ack4data off]]



#########################################################



# Set Traffic



for {set i 1} {$i < $val(nn)} {incr i} {

    cbrtraffic $i 0 300 [expr 20+200*$i]

}



#########################################################



}



# Reset of Nodes

for {set i 0} {$i < $val(nn) } {incr i} {

    $ns_ at $stopTime "$node_($i) reset";

}



# Stop Simulation

$ns_ at $stopTime  "stop"

$ns_ at $stopTime "puts \"\nNS EXITING...\n\""

$ns_ at $stopTime  "$ns_ halt"



# Stop Function

proc stop {} {

    global ns_ tracefd starttime val env

    $ns_ flush-trace

    close $tracefd

    set hasDISPLAY 0

    foreach index [array names env] {

        #puts "$index: $env($index)"

        if { ("$index" == "DISPLAY") && ("$env($index)" != "") } {

                set hasDISPLAY 1

        }

    }

}



# Start Simulation

puts "\nStarting Simulation..."

$ns_ run

最佳答案

对于可能遇到此问题的任何其他人:

这似乎是由来自 mac 层的 CCA 引起的,其中一系列不幸的事件可能导致 PriQueue 类中的 blocked_ 变量卡在 1 .

p802_15_4phy.ccPhy802_15_4::CCAHandler中,替换

CCAReportH.start(4/getRate('s'));

sensed_ch_state = t_status;
mac->PLME_CCA_confirm(sensed_ch_state);

“修复”了这个问题。这使得 CCA 成为即时的。显然,没有即时 CCA 会导致此错误。 如果有人找到更好的修复方法,请告诉我。

关于c++ - NS2:AODV 路由消息卡在队列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42680824/

相关文章:

C++ Word Automation 问题将工作簿中的图表或工作表导出到图像

physics - 弹跳球不符合能量守恒定律

algorithm - 在 ns2 中实现时 TORA 出错

c++ - 强制 GCC 执行 memcpy 运行时大小检查的循环取消切换?

c++ - 在 C++ 中表示多遍抽象语法树 (AST)?

c++ - std::thread.join() 做什么?

ios - 减小 iPhone 模拟器窗口的大小?

ios - 在 XCode 中为设备/模拟器编译不同的文件

ns2 中的 C++ undefined reference

c++ - dsr/linkcache .cc : fatal error: list. h: 没有那个文件或目录