NS2无线方案Random Motion set dest不工作

时间:2017-11-21 16:07:04

标签: shell tcl ns2

Antenna/OmniAntenna set Gt_ 1              ;#Transmit antenna gain
Antenna/OmniAntenna set Gr_ 1              ;#Receive antenna gain
Phy/WirelessPhy set L_ 1.0                 ;#System Loss Factor
Phy/WirelessPhy set freq_ 2.472e9          ;#channel
Phy/WirelessPhy set bandwidth_ 10Mb        ;#Data Rate
Phy/WirelessPhy set Pt_ 0.2818        ;#Transmit Power
Phy/WirelessPhy set CPThresh_ 10.0         ;#Collision Threshold
Phy/WirelessPhy set CSThresh_ 1.74269e-10 ;#Carrier Sense Power
Phy/WirelessPhy set RXThresh_ 1.08918e-09  ;#Receive Power Threshold
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)     27                         ;# number of mobilenodes
set val(rp)     AODV                       ;# routing protocol
set val(x)      2768                      ;# X dimension of topography
set val(y)      100                      ;# Y dimension of topography
set val(stop)   10.0                         ;# time of simulation end

#Create a ns simulator
set ns [new Simulator]

#Setup topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

$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       $chan \
                -topoInstance  $topo \
                -agentTrace    ON \
                -routerTrace   ON \
                -macTrace      ON \
                -movementTrace ON

#Create 27 nodes
set n0 [$ns node]
$n0 set X_ 1468
$n0 set Y_ 1247
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 1593
$n1 set Y_ 1247
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 1718
$n2 set Y_ 1247
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 1843
$n3 set Y_ 1247
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 1968
$n4 set Y_ 1247
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 1468
$n5 set Y_ 1122
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
set n6 [$ns node]
$n6 set X_ 1593
$n6 set Y_ 1122
$n6 set Z_ 0.0
$ns initial_node_pos $n6 20
set n7 [$ns node]
$n7 set X_ 1718
$n7 set Y_ 1122
$n7 set Z_ 0.0
$ns initial_node_pos $n7 20
set n8 [$ns node]
$n8 set X_ 1843
$n8 set Y_ 1122
$n8 set Z_ 0.0
$ns initial_node_pos $n8 20
set n9 [$ns node]
$n9 set X_ 1968
$n9 set Y_ 1122
$n9 set Z_ 0.0
$ns initial_node_pos $n9 20
set n10 [$ns node]
$n10 set X_ 1468
$n10 set Y_ 997
$n10 set Z_ 0.0
$ns initial_node_pos $n10 20
set n11 [$ns node]
$n11 set X_ 1593
$n11 set Y_ 997
$n11 set Z_ 0.0
$ns initial_node_pos $n11 20
set n12 [$ns node]
$n12 set X_ 1718
$n12 set Y_ 997
$n12 set Z_ 0.0
$ns initial_node_pos $n12 20
set n13 [$ns node]
$n13 set X_ 1843
$n13 set Y_ 997
$n13 set Z_ 0.0
$ns initial_node_pos $n13 20
set n14 [$ns node]
$n14 set X_ 1968
$n14 set Y_ 997
$n14 set Z_ 0.0
$ns initial_node_pos $n14 20
set n15 [$ns node]
$n15 set X_ 1468
$n15 set Y_ 872
$n15 set Z_ 0.0
$ns initial_node_pos $n15 20
set n16 [$ns node]
$n16 set X_ 1593
$n16 set Y_ 872
$n16 set Z_ 0.0
$ns initial_node_pos $n16 20
set n17 [$ns node]
$n17 set X_ 1718
$n17 set Y_ 872
$n17 set Z_ 0.0
$ns initial_node_pos $n17 20
set n18 [$ns node]
$n18 set X_ 1843
$n18 set Y_ 872
$n18 set Z_ 0.0
$ns initial_node_pos $n18 20
set n19 [$ns node]
$n19 set X_ 1968
$n19 set Y_ 872
$n19 set Z_ 0.0
$ns initial_node_pos $n19 20
set n20 [$ns node]
$n20 set X_ 1468
$n20 set Y_ 747
$n20 set Z_ 0.0
$ns initial_node_pos $n20 20
set n21 [$ns node]
$n21 set X_ 1593
$n21 set Y_ 747
$n21 set Z_ 0.0
$ns initial_node_pos $n21 20
set n22 [$ns node]
$n22 set X_ 1718
$n22 set Y_ 747
$n22 set Z_ 0.0
$ns initial_node_pos $n22 20
set n23 [$ns node]
$n23 set X_ 1843
$n23 set Y_ 747
$n23 set Z_ 0.0
$ns initial_node_pos $n23 20
set n24 [$ns node]
$n24 set X_ 1968
$n24 set Y_ 747
$n24 set Z_ 0.0
$ns initial_node_pos $n24 20
set n25 [$ns node]
$n25 set X_ 1327
$n25 set Y_ 868
$n25 set Z_ 0.0
$ns initial_node_pos $n25 20
set n26 [$ns node]
$n26 set X_ 2108
$n26 set Y_ 1130
$n26 set Z_ 0.0
$ns initial_node_pos $n26 20

#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n25 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n26 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 9.0 "$ftp0 stop"

set xx_ [expr rand()*700]
set yy_ [expr rand()*600]
set finalxx_ [expr $xx_+1400.00]
set finalyy_ [expr $yy_+700.00]
set rng_time [expr rand()*$val(stop)]
#*******************************************************
#This is the error part.
$ns at $rng_time "$n26 setdest $finalxx_ $finalyy_ 25.0"   ;# random movements
#*****************************************************

#Define a 'finish' procedure
proc finish {} {
    global ns tracefile namfile
    $ns flush-trace
    close $tracefile
    close $namfile
    exec nam out.nam &
    exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

setdest功能在上面提到的无线方案中没有工作,并给我错误:

初始化列表xListHead

channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 300.8
SORTING LISTS ...DONE!

ns: _o586 setdest 1447.732143731663 729.26259833819358 25.0: 
    (_o586 cmd line 1)
    invoked from within

"_o586 cmd setdest 1447.732143731663 729.26259833819358 25.0"
 invoked from within

"catch "$self cmd $args" ret"
    invoked from within

"if [catch "$self cmd $args" ret] {
set cls [$self info class]

global errorInfo

set savedInfo $errorInfo

error "error when calling class $cls: $args" $..."
    (procedure "_o586" line 2)
    (SplitObject unknown line 2)
    invoked from within

"_o586 setdest 1447.732143731663 729.26259833819358 25.0"

当我在仅包含7个节点的其他文件中测试时,setdest函数工作正常。 谁能解释为什么会这样呢?

提前致谢。

1 个答案:

答案 0 :(得分:0)

第22行出现错误

set val(y)      100         ;# Y dimension of topography

...您的“Y值”在节点设置中要大得多。将第22行编辑为:

set val(y)      2000

...然后没有错误,也是一个完美的NAM动画。