0

我无法运行此模拟:

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]
4

2 回答 2

2

以下行导致问题:

设置神_ [创建神$val(nn)]

god_ 告诉为 nn 个节点做准备。但几行之后:

对于 {set i 0} {$i < [expr {2*$val(nn)}] } {incr i} {

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

于 2012-11-29T07:54:25.190 回答
1

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

设置神_ [创建神 [expr $val(nn) + 20]]

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

于 2012-11-01T20:25:18.580 回答