NS2:接收数据包为零

NS2: receiving packets is zero

我不知道为什么,但我的节点在 ns2 中什么也没有收到! 为什么会这样? 代码很好,这是一个很长的程序,我会 post 所有代码,希望有人能帮助我,我已经工作了 2 周,没有任何改进...... 有人遇到同样的问题可以帮助我吗?

set val(chan)         Channel/WirelessChannel  ;# channel type
set val(prop)         Propagation/TwoRayGround ;# radio-propagation model
set val(ant)          Antenna/OmniAntenna      ;# Antenna type
set val(ll)           LL                       ;# Link layer type
set val(ifq)          Queue/DropTail/PriQueue  ;# Interface queue type
set val(ifqlen)       50                       ;# max packet in ifq
set val(netif)        Phy/WirelessPhy          ;# network interface type
set val(mac)          Mac/802_11               ;# MAC type
set val(rp)           AODV                     ;# ad-hoc routing protocol 
set val(nn)           29                        ;# number of mobilenodes
set val(cp)             "456.cpr" 
set val(sc)             "456.scn" 
set ns_    [new Simulator]
set tracefd     [open 457.tr w]
$ns_ trace-all $tracefd           
set topo    [new Topography]
$topo load_flatgrid 250 250
create-god $val(nn)

# Configure nodes
        $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 \
                         -channelType $val(chan) \
                         -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
        }  


#
# Tell nodes when the simulation ends
#

puts "Loading scenario file..." source $val(sc)

puts "Loading connection pattern..." source $val(cp)


for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 100.0 "$node_($i) reset"; } $ns_ at 100.0001 "stop" $ns_ at 100.0002 "puts \"NS EXITING...\" ; $ns_ halt" proc stop {} {
    global ns_ tracefd
    close $tracefd }

puts "Starting Simulation..." $ns_ run

这是我的流量,我的问题可能出在这里:

for {set k 20} {$k < $val(nn) } {incr k} {
    set tcp($k) [new Agent/TCP]
    set sink($k) [new Agent/TCPSink]
    $ns_ attach-agent $node_($k) $tcp($k)
    $ns_ attach-agent $node_([expr $val(nn)-$k-1 ]) $sink($k)
    #$ns_ connect $tcp($k) $sink($k)


    set ftp_($k) [new Application/FTP]
    $ftp_($k) attach-agent $tcp($k)
    $ftp_($k) set packetSize_ 1024

    #$ns_ at [expr rand()] "$ftp_($k) start"
    $ns_ at  1.0    "$ftp_($k) start"
    $ns_ at $val(stop) "$ftp_($k) stop"

    #for {set i 0} {$i < 20 } {incr i} {
    #   $ns_ attach-agent $node_($i) $sink($k)
    #}
}
$ns_ duplex-link $node_(24) $node_(20) 2Mb 10ms DropTail
$ns_ duplex-link $node_(24) $node_(21) 2Mb 10ms DropTail
$ns_ duplex-link $node_(24) $node_(22) 2Mb 10ms DropTail
$ns_ duplex-link $node_(24) $node_(23) 2Mb 10ms DropTail
$ns_ duplex-link $node_(24) $node_(25) 2Mb 10ms DropTail
$ns_ duplex-link $node_(24) $node_(26) 2Mb 10ms DropTail
$ns_ duplex-link $node_(24) $node_(27) 2Mb 10ms DropTail
$ns_ duplex-link $node_(24) $node_(28) 2Mb 10ms DropTail
$ns_ duplex-link $node_(20) $node_(21) 2Mb 10ms DropTail
$ns_ duplex-link $node_(21) $node_(22) 2Mb 10ms DropTail
$ns_ duplex-link $node_(26) $node_(27) 2Mb 10ms DropTail
$ns_ duplex-link $node_(27) $node_(28) 2Mb 10ms DropTail
$ns_ duplex-link $node_(28) $node_(25) 2Mb 10ms DropTail
$ns_ duplex-link $node_(23) $node_(20) 2Mb 10ms DropTail
$ns_ duplex-link $node_(22) $node_(25) 2Mb 10ms DropTail
$ns_ duplex-link $node_(23) $node_(26) 2Mb 10ms DropTail

set udp1 [new Agent/UDP]
set null1 [new Agent/LossMonitor]
$ns_ attach-agent $node_(20) $udp1
$ns_ attach-agent $node_(21) $null1
$ns_ connect $udp1 $null1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetsize_ 500
$cbr1 set interval_ 0.005
$ns_ at 1.0 "$cbr1 start" 
$ns_ at $val(stop) "$cbr1 stop"

set udp2 [new Agent/UDP]
set null2 [new Agent/LossMonitor]
$ns_ attach-agent $node_(21) $udp2
$ns_ attach-agent $node_(22) $null2
$ns_ connect $udp2 $null2
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp2
$cbr2 set packetsize_ 500
$cbr2 set interval_ 0.005
$ns_ at 1.0 "$cbr2 start" 
$ns_ at $val(stop) "$cbr2 stop"


set udp3 [new Agent/UDP]
set null3 [new Agent/LossMonitor]
$ns_ attach-agent $node_(20) $udp3
$ns_ attach-agent $node_(23) $null3
$ns_ connect $udp3 $null3
set cbr3 [new Application/Traffic/CBR]
$cbr3 attach-agent $udp3
$cbr3 set packetsize_ 500
$cbr3 set interval_ 0.005
$ns_ at 1.0 "$cbr3 start" 
$ns_ at $val(stop) "$cbr3 stop"

set udp4 [new Agent/UDP]
set null4 [new Agent/LossMonitor]
$ns_ attach-agent $node_(23) $udp4
$ns_ attach-agent $node_(26) $null4
$ns_ connect $udp4 $null4
set cbr4 [new Application/Traffic/CBR]
$cbr4 attach-agent $udp4
$cbr4 set packetsize_ 500
$cbr4 set interval_ 0.005
$ns_ at 1.0 "$cbr4 start" 
$ns_ at $val(stop) "$cbr4 stop"

set udp5 [new Agent/UDP]
set null5 [new Agent/LossMonitor]
$ns_ attach-agent $node_(26) $udp5
$ns_ attach-agent $node_(27) $null5
$ns_ connect $udp5 $null5
set cbr5 [new Application/Traffic/CBR]
$cbr5 attach-agent $udp5
$cbr5 set packetsize_ 500
$cbr5 set interval_ 0.005
$ns_ at 1.0 "$cbr5 start" 
$ns_ at $val(stop) "$cbr5 stop"

set udp6 [new Agent/UDP]
set null6 [new Agent/LossMonitor]
$ns_ attach-agent $node_(27) $udp6
$ns_ attach-agent $node_(28) $null6
$ns_ connect $udp6 $null6
set cbr6 [new Application/Traffic/CBR]
$cbr6 attach-agent $udp6
$cbr6 set packetsize_ 500
$cbr6 set interval_ 0.005
$ns_ at 1.0 "$cbr6 start" 
$ns_ at $val(stop) "$cbr6 stop"

set udp7 [new Agent/UDP]
set null7 [new Agent/LossMonitor]
$ns_ attach-agent $node_(25) $udp7
$ns_ attach-agent $node_(28) $null7
$ns_ connect $udp7 $null7
set cbr7 [new Application/Traffic/CBR]
$cbr7 attach-agent $udp7
$cbr7 set packetsize_ 500
$cbr7 set interval_ 0.005
$ns_ at 1.0 "$cbr7 start" 
$ns_ at $val(stop) "$cbr7 stop"

set udp8 [new Agent/UDP]
set null8 [new Agent/LossMonitor]
$ns_ attach-agent $node_(25) $udp8
$ns_ attach-agent $node_(22) $null8
$ns_ connect $udp8 $null8
set cbr8 [new Application/Traffic/CBR]
$cbr8 attach-agent $udp8
$cbr8 set packetsize_ 500
$cbr8 set interval_ 0.005
$ns_ at 1.0 "$cbr8 start" 
$ns_ at $val(stop) "$cbr8 stop"

set udp9 [new Agent/UDP]
set null9 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp9
$ns_ attach-agent $node_(20) $null9
$ns_ connect $udp9 $null9
set cbr9 [new Application/Traffic/CBR]
$cbr9 attach-agent $udp9
$cbr9 set packetsize_ 500
$cbr9 set interval_ 0.005
$ns_ at 1.0 "$cbr9 start" 
$ns_ at $val(stop) "$cbr9 stop"

set udp10 [new Agent/UDP]
set null10 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp10
$ns_ attach-agent $node_(21) $null10
$ns_ connect $udp10 $null10
set cbr10 [new Application/Traffic/CBR]
$cbr10 attach-agent $udp10
$cbr10 set packetsize_ 500
$cbr10 set interval_ 0.005
$ns_ at 1.0 "$cbr10 start" 
$ns_ at $val(stop) "$cbr10 stop"

set udp11 [new Agent/UDP]
set null11 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp11
$ns_ attach-agent $node_(22) $null11
$ns_ connect $udp11 $null11
set cbr11 [new Application/Traffic/CBR]
$cbr11 attach-agent $udp11
$cbr11 set packetsize_ 500
$cbr11 set interval_ 0.005
$ns_ at 1.0 "$cbr11 start" 
$ns_ at $val(stop) "$cbr11 stop"

set udp12 [new Agent/UDP]
set null12 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp12
$ns_ attach-agent $node_(23) $null12
$ns_ connect $udp12 $null12
set cbr12 [new Application/Traffic/CBR]
$cbr12 attach-agent $udp12
$cbr12 set packetsize_ 500
$cbr12 set interval_ 0.005
$ns_ at 1.0 "$cbr12 start" 
$ns_ at $val(stop) "$cbr12 stop"

set udp13 [new Agent/UDP]
set null13 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp13
$ns_ attach-agent $node_(25) $null13
$ns_ connect $udp13 $null13
set cbr13 [new Application/Traffic/CBR]
$cbr13 attach-agent $udp13
$cbr13 set packetsize_ 500
$cbr13 set interval_ 0.005
$ns_ at 1.0 "$cbr13 start" 
$ns_ at $val(stop) "$cbr13 stop"

set udp14 [new Agent/UDP]
set null14 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp14
$ns_ attach-agent $node_(26) $null14
$ns_ connect $udp14 $null14
set cbr14 [new Application/Traffic/CBR]
$cbr14 attach-agent $udp14
$cbr14 set packetsize_ 500
$cbr14 set interval_ 0.005
$ns_ at 1.0 "$cbr14 start" 
$ns_ at $val(stop) "$cbr14 stop"

set udp15 [new Agent/UDP]
set null15 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp15
$ns_ attach-agent $node_(27) $null15
$ns_ connect $udp15 $null15
set cbr15 [new Application/Traffic/CBR]
$cbr15 attach-agent $udp15
$cbr15 set packetsize_ 500
$cbr15 set interval_ 0.005
$ns_ at 1.0 "$cbr15 start" 
$ns_ at $val(stop) "$cbr15 stop"

set udp16 [new Agent/UDP]
set null16 [new Agent/LossMonitor]
$ns_ attach-agent $node_(24) $udp16
$ns_ attach-agent $node_(28) $null16
$ns_ connect $udp16 $null16
set cbr16 [new Application/Traffic/CBR]
$cbr16 attach-agent $udp16
$cbr16 set packetsize_ 500
$cbr16 set interval_ 0.005
$ns_ at 1.0 "$cbr16 start" 
$ns_ at $val(stop) "$cbr16 stop"

#Give node position (for NAM)
$ns_ duplex-link-op $node_(24) $node_(25) orient right
$ns_ duplex-link-op $node_(24) $node_(23) orient left
$ns_ duplex-link-op $node_(24) $node_(27) orient down
$ns_ duplex-link-op $node_(24) $node_(21) orient up
$ns_ duplex-link-op $node_(24) $node_(20) orient left-up
$ns_ duplex-link-op $node_(24) $node_(22) orient right-up
$ns_ duplex-link-op $node_(24) $node_(26) orient left-down
$ns_ duplex-link-op $node_(24) $node_(28) orient right-down

$ns_ duplex-link-op $node_(23) $node_(20) orient up
$ns_ duplex-link-op $node_(23) $node_(26) orient down

$ns_ duplex-link-op $node_(25) $node_(22) orient up
$ns_ duplex-link-op $node_(25) $node_(28) orient down


$ns_ duplex-link-op $node_(21) $node_(20) orient left
$ns_ duplex-link-op $node_(21) $node_(22) orient right
$ns_ duplex-link-op $node_(27) $node_(26) orient left
$ns_ duplex-link-op $node_(27) $node_(28) orient right

这是我的方案,它必须在程序中使用:

$node_(20) set X_ 75.0
$node_(20) set Y_ 75.0
$node_(20) set Z_ 0.0

$node_(21) set X_ 125.0
$node_(21) set Y_ 75.0
$node_(21) set Z_ 0.0

$node_(22) set X_ 175.0
$node_(22) set Y_ 75.0
$node_(22) set Z_ 0.0

$node_(23) set X_ 75.0
$node_(23) set Y_ 125.0
$node_(23) set Z_ 0.0

$node_(24) set X_ 125.0
$node_(24) set Y_ 125.0
$node_(24) set Z_ 0.0

$node_(25) set X_ 175.0
$node_(25) set Y_ 125.0
$node_(25) set Z_ 0.0

$node_(26) set X_ 75.0
$node_(26) set Y_ 175.0
$node_(26) set Z_ 0.0

$node_(27) set X_ 125.0
$node_(27) set Y_ 175.0
$node_(27) set Z_ 0.0

$node_(28) set X_ 175.0
$node_(28) set Y_ 175.0
$node_(28) set Z_ 0.0

$ns_ at 0 "$node_(20) add-mark ap0 blue circle"
$ns_ at 0 "$node_(21) add-mark ap1 blue circle"
$ns_ at 0 "$node_(22) add-mark ap2 blue circle"
$ns_ at 0 "$node_(23) add-mark ap3 blue circle"
$ns_ at 0 "$node_(24) add-mark ap4 blue circle"
$ns_ at 0 "$node_(25) add-mark ap5 blue circle"
$ns_ at 0 "$node_(26) add-mark ap6 blue circle"
$ns_ at 0 "$node_(27) add-mark ap7 blue circle"
$ns_ at 0 "$node_(28) add-mark ap8 blue circle"

$ns_ at 1 "$node_(0) setdest 28 222 52.95" ;# 3.37  0

$ns_ at 1 "$node_(1) setdest 120 219 35.95" ;# 0.12 0
$ns_ at 1 "$node_(2) setdest 23 55 87.57" ;# 4.06   0
$ns_ at 1 "$node_(3) setdest 80 23 47.86" ;# 5.97   0
$ns_ at 1 "$node_(4) setdest 10 60 53.55" ;# 1.6    0
$ns_ at 1 "$node_(5) setdest 173 45 31.29" ;# 1.95  0
$ns_ at 1 "$node_(6) setdest 41 95 88.14" ;# 5.09   0
$ns_ at 1 "$node_(7) setdest 78 110 48.54" ;# 2.7   0
$ns_ at 1 "$node_(8) setdest 1 143 86.4" ;# 3.07    0
$ns_ at 1 "$node_(9) setdest 160 73 47.15" ;# 2.56  0
$ns_ at 1 "$node_(10) setdest 104 149 47.92" ;# 1.75    0
$ns_ at 1 "$node_(11) setdest 19 195 83.93" ;# 1.58 0
$ns_ at 1 "$node_(12) setdest 141 135 76.36" ;# 2.25    0
$ns_ at 1 "$node_(13) setdest 189 223 30.36" ;# 3.58    0
$ns_ at 1 "$node_(14) setdest 151 198 52.96" ;# 0.3 0
$ns_ at 1 "$node_(15) setdest 137 88 47.99" ;# 0.84 0
$ns_ at 1 "$node_(16) setdest 201 113 39.56" ;# 3.42    0
$ns_ at 1 "$node_(17) setdest 138 86 76.99" ;# 1.65 0
$ns_ at 1 "$node_(18) setdest 76 215 82.29" ;# 1.41 0
$ns_ at 1 "$node_(19) setdest 141 56 76.3" ;# 3.18  0
$ns_ at 2 "$node_(0) setdest 15 219 52.95" ;# 3.37  0
$ns_ at 2 "$node_(1) setdest 156 224 35.95" ;# 0.12 0
$ns_ at 2 "$node_(2) setdest 58 128 81.55" ;# 1.12  0
$ns_ at 2 "$node_(3) setdest 124 9 47.86" ;# 5.97   0
$ns_ at 2 "$node_(4) setdest 8 113 53.55" ;# 1.6    0
$ns_ at 2 "$node_(5) setdest 161 74 31.29" ;# 1.95  0
$ns_ at 2 "$node_(6) setdest 73 13 88.14" ;# 5.09   0
$ns_ at 2 "$node_(7) setdest 34 131 48.54" ;# 2.7   0
$ns_ at 2 "$node_(8) setdest 25 78 68.74" ;# 5.07   0
$ns_ at 2 "$node_(9) setdest 122 98 47.15" ;# 2.56  0
$ns_ at 2 "$node_(10) setdest 95 196 47.92" ;# 1.75 0
$ns_ at 2 "$node_(11) setdest 44 152 49.32" ;# 5.24 0
$ns_ at 2 "$node_(12) setdest 93 194 76.36" ;# 2.25 0
$ns_ at 2 "$node_(13) setdest 161 210 30.36" ;# 3.58    0
$ns_ at 2 "$node_(14) setdest 201 214 52.96" ;# 0.3 0
$ns_ at 2 "$node_(15) setdest 161 115 47.99" ;# 0.84    0
$ns_ at 2 "$node_(16) setdest 163 102 39.56" ;# 3.42    0
$ns_ at 2 "$node_(17) setdest 132 163 76.99" ;# 1.65    0
$ns_ at 2 "$node_(18) setdest 61 137 79.42" ;# 4.52 0
$ns_ at 2 "$node_(19) setdest 65 53 76.3" ;# 3.18   0
$ns_ at 3 "$node_(0) setdest 63 169 69.5" ;# 5.48   0
$ns_ at 3 "$node_(1) setdest 191 228 35.95" ;# 0.12 0
$ns_ at 3 "$node_(2) setdest 94 202 81.55" ;# 1.12  0
$ns_ at 3 "$node_(3) setdest 87 14 70.79" ;# 2.99   0
$ns_ at 3 "$node_(4) setdest 7 167 53.55" ;# 1.6    0
$ns_ at 3 "$node_(5) setdest 149 103 31.29" ;# 1.95 0
$ns_ at 3 "$node_(6) setdest 76 5 88.14" ;# 5.09    0
$ns_ at 3 "$node_(7) setdest 8 143 48.54" ;# 2.7    0
$ns_ at 3 "$node_(8) setdest 48 18 68.74" ;# 5.07   0
$ns_ at 3 "$node_(9) setdest 98 166 72.31" ;# 1.91  0
$ns_ at 3 "$node_(10) setdest 88 236 47.92" ;# 1.75 0
$ns_ at 3 "$node_(11) setdest 69 110 49.32" ;# 5.24 0
$ns_ at 3 "$node_(12) setdest 71 222 76.36" ;# 2.25 0
$ns_ at 3 "$node_(13) setdest 134 197 30.36" ;# 3.58    0
$ns_ at 3 "$node_(14) setdest 212 217 52.96" ;# 0.3 0
$ns_ at 3 "$node_(15) setdest 214 111 52.78" ;# 6.22    0
$ns_ at 3 "$node_(16) setdest 125 91 39.56" ;# 3.42 0
$ns_ at 3 "$node_(17) setdest 126 240 76.99" ;# 1.65    0
$ns_ at 3 "$node_(18) setdest 54 100 79.42" ;# 4.52 0
$ns_ at 3 "$node_(19) setdest 44 52 76.3" ;# 3.18   0
$ns_ at 4 "$node_(0) setdest 112 119 69.5" ;# 5.48  0
$ns_ at 4 "$node_(1) setdest 227 233 35.95" ;# 0.12 0
$ns_ at 4 "$node_(2) setdest 106 228 81.55" ;# 1.12 0
$ns_ at 4 "$node_(3) setdest 116 98 88.39" ;# 1.23  0
$ns_ at 4 "$node_(4) setdest 6 196 53.55" ;# 1.6    0
$ns_ at 4 "$node_(5) setdest 138 132 31.29" ;# 1.95 0
$ns_ at 4 "$node_(6) setdest 107 80 81.2" ;# 1.17   0
$ns_ at 4 "$node_(7) setdest 15 100 43.75" ;# 4.88  0
$ns_ at 4 "$node_(8) setdest 43 70 53.02" ;# 1.67   0
$ns_ at 4 "$node_(9) setdest 80 216 72.31" ;# 1.91  0
$ns_ at 4 "$node_(10) setdest 98 207 31.12" ;# 5.05 0
$ns_ at 4 "$node_(11) setdest 71 105 49.32" ;# 5.24 0
$ns_ at 4 "$node_(12) setdest 47 165 61.67" ;# 4.32 0
$ns_ at 4 "$node_(13) setdest 106 184 30.36" ;# 3.58    0
$ns_ at 4 "$node_(14) setdest 147 157 88.79" ;# 3.89    0
$ns_ at 4 "$node_(15) setdest 235 110 52.78" ;# 6.22    0
$ns_ at 4 "$node_(16) setdest 115 88 39.56" ;# 3.42 0
$ns_ at 4 "$node_(17) setdest 125 249 76.99" ;# 1.65    0
$ns_ at 4 "$node_(18) setdest 104 102 50.81" ;# 0.04    0
$ns_ at 4 "$node_(19) setdest 59 82 32.69" ;# 1.11  0
$ns_ at 5 "$node_(0) setdest 160 69 69.5" ;# 5.48   0
$ns_ at 5 "$node_(1) setdest 232 233 35.95" ;# 0.12 0
$ns_ at 5 "$node_(2) setdest 136 202 39.94" ;# 5.56 0
$ns_ at 5 "$node_(3) setdest 136 154 88.39" ;# 1.23 0
$ns_ at 5 "$node_(4) setdest 89 196 82.59" ;# 0 0
$ns_ at 5 "$node_(5) setdest 126 161 31.29" ;# 1.95 0
$ns_ at 5 "$node_(6) setdest 139 155 81.2" ;# 1.17  0
$ns_ at 5 "$node_(7) setdest 16 97 43.75" ;# 4.88   0
$ns_ at 5 "$node_(8) setdest 37 123 53.02" ;# 1.67  0
$ns_ at 5 "$node_(9) setdest 129 205 50.17" ;# 6.07 0
$ns_ at 5 "$node_(10) setdest 109 177 31.12" ;# 5.05    0
$ns_ at 5 "$node_(11) setdest 104 125 38.29" ;# 0.57    0

如果你知道可能是什么问题,请告诉我 谢谢

我已经删除了这些代码(从交通部分)并且它有效但不是我想要的那样:

for {set k 20} {$k < $val(nn) } {incr k} {
set tcp($k) [new Agent/TCP]
set sink($k) [new Agent/TCPSink]
$ns_ attach-agent $node_($k) $tcp($k)
$ns_ attach-agent $node_([expr $val(nn)-$k-1 ]) $sink($k)
#$ns_ connect $tcp($k) $sink($k)


set ftp_($k) [new Application/FTP]
$ftp_($k) attach-agent $tcp($k)
$ftp_($k) set packetSize_ 1024

#$ns_ at [expr rand()] "$ftp_($k) start"
$ns_ at  1.0    "$ftp_($k) start"
$ns_ at $val(stop) "$ftp_($k) stop"
}