无线模拟问题

时间:2012-10-31 05:39:18

标签: tcl wireless ns2

我无法运行此模拟:

set pairs [lindex $argv 0]

# ====================================
# 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)             $pairs                     ;# pair of mobilenodes
set val(rp)             DSDV                       ;# routing protocol

# ======================================
# Main Program
# ======================================

#
# Initialize Global Variables
#

set ns [new Simulator]
set tracefd [open wl.tr w]

$ns use-newtrace
$ns trace-all $tracefd 

# set up topography object
set topo [new Topography]
#1000x1000m terrain
$topo load_flatgrid 1000 1000

#
# Create General Operations Director
#

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

Mac/802_11 set RTSThreshold_ 3000

#
#  Create the specified number of mobilenodes [$val(nn)] and "attach" them
#  to the channel. 

# configure node

        $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) \
             -channel [new $val(chan)] \
             -topoInstance $topo \
             -agentTrace ON \
             -routerTrace ON \
             -macTrace OFF \
             -movementTrace OFF

    for {set i 0} {$i < [expr {2*$val(nn)}] } {incr i} {
        set node_($i) [$ns node]    
        $node_($i) random-motion 0  ;# disable random motion
    }

#
# Provide initial (X,Y, Z=0) co-ordinates for mobilenodes
#
set rng [new RNG]
$rng seed 0

set unit 10.0;
set even_x 50.0;
set even_y 50.0;
set odd_x 50.0;
set odd_y 0.0;
for {set i 0} { $i < [expr {2*$val(nn)}] } {incr i} {
    set residue [expr {$i%2}];
#puts $residue
    set rand [expr [$rng uniform 0 1] + [ns-random 0] % 100];
    if { $residue ==0 } {

        $node_($i) set X_ [expr {$even_x + $rand}];
        $node_($i) set Y_ [expr {$even_y }]
        $node_($i) set Z_ 0.0;
    } else {
        $node_($i) set X_ [expr {$odd_x + $rand}];
        $node_($i) set Y_ [expr {$odd_y}];
        $node_($i) set Z_ 0.0;
    }
}

for {set i 0} { $i < $val(nn) } {incr i} {  
    set null_($i) [new Agent/Null]
    $ns attach-agent $node_([expr {($i*2)+1}]) $null_($i)
    set udp_($i) [new Agent/UDP]
    $ns attach-agent $node_([expr {2*$i}]) $udp_($i)
    set cbr_($i) [new Application/Traffic/CBR]
    $cbr_($i) set packetSize_ 1440  
    $udp_($i) set packetSize_ 1440
    $cbr_($i) set rate_ 500k
    $cbr_($i) attach-agent $udp_($i)
    $ns connect $udp_($i) $null_($i) 
}

for {set i 0} {$i < $val(nn)} {incr i} {
        $ns at 0.0 "$cbr_($i) start"
        $ns at 120.0 "$cbr_($i) stop"
}
$ns at 120.0 "$ns halt"
$ns run
$ns flush-trace
close $tracefd
puts "Starting Simulation..."
$ns run

我收到此错误 请任何人帮助我!!!

MAC_802_11: accessing MAC cache_ array out of range (src 33, dst 32, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 33, dst 32, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 33, dst 32, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 32, dst 33, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 32, dst 33, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 32, dst 33, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 32, dst 33, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 32, dst 33, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 32, dst 33, size 20)!
MAC_802_11: accessing MAC cache_ array out of range (src 32, dst 33, size 20)!
[suppressing additional MAC cache_ warnings]

2 个答案:

答案 0 :(得分:2)

以下几行会导致问题:

  

设置god_ [create-god $ val(nn)]

God_告诉准备nn个节点。但后来几行:

  

for {set i 0} {$ i&lt; [expr {2 * $ val(nn)}]} {incr i} {

您创建2 * nn个节点。要么创建上帝[expr {2 * $ val(nn)}],要么去掉它出现在代码中的2 *。

答案 1 :(得分:1)

http://www.isi.edu/nsnam/archive/ns-users/webarch/2001/msg04753.html,尝试

设置god_ [create-god [expr $ val(nn)+ 20]]

或某些变化。这会产生更多的GOD对象(+20),严格来说你应该弄清楚你需要多少。我认为整数是定义的节点数。