NS2代码为什么不起作用? (模拟程序未运行)25个节点

时间:2019-05-19 12:43:37

标签: tcl

这是我的代码:

#channel type
set val(chan)    Channel/WirelessChannel; 

set val(prop)    Propagation/TwoRayGround

set val(netif)   Phy/WirelessPhy/802_15_4 

set val(mac)     Mac/802_15_4

set val(ifq)     Queue/DropTail/PriQueue 

set val(ll)      LL                                   

set val(ant)     Antenna/OmniAntenna   

set val(ifqlen)  50                    

set val(nn)      25                 

set val(rp)      AODV/AOMDV/DSR/DumbAgent  

set val(x)       50  

set val(y)       50                                   

set ns [new Simulator]


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

set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

set f [open out.tr w]
$ns trace-all $f

set f1 [open out0.tr w]
set f2 [open out1.tr w]
set f3 [open out2.tr w]


create-god (1)                                                 
$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      ;
}

$node_(0) set X_ 26.608377307314
$node_(0) set Y_ 49.446991827566
$node_(0) set Z_ 0.000000000000
$node_(1) set X_ 49.337311778721
$node_(1) set Y_ 48.582820874924
$node_(1) set Z_ 0.000000000000
$node_(2) set X_ 27.437938215931
$node_(2) set Y_ 30.091658830425
$node_(2) set Z_ 0.000000000000
$node_(3) set X_ 10.568766842667
$node_(3) set Y_ 47.453389414657
$node_(3) set Z_ 0.000000000000
$node_(4) set X_ 32.496269526711
$node_(4) set Y_ 2.257450139045
$node_(4) set Z_ 0.000000000000
$node_(5) set X_ 26.476535726599
$node_(5) set Y_ 38.646396828920
$node_(5) set Z_ 0.000000000000
$node_(6) set X_ 49.430596917301
$node_(6) set Y_ 31.320042376073
$node_(6) set Z_ 0.000000000000
$node_(7) set X_ 20.045665842364
$node_(7) set Y_ 32.537008965783
$node_(7) set Z_ 0.000000000000
$node_(8) set X_ 13.641089465783
$node_(8) set Y_ 28.871428688349
$node_(8) set Z_ 0.000000000000
$node_(9) set X_ 2.125856848941
$node_(9) set Y_ 9.049644538277
$node_(9) set Z_ 0.000000000000
$node_(10) set X_ 0.596871605178
$node_(10) set Y_ 0.816174228621
$node_(10) set Z_ 0.000000000000
$node_(11) set X_ 8.828197591068
$node_(11) set Y_ 34.402175912553
$node_(11) set Z_ 0.000000000000
$node_(12) set X_ 18.759762507870
$node_(12) set Y_ 25.069997591097
$node_(12) set Z_ 0.000000000000
$node_(13) set X_ 13.277017351151
$node_(13) set Y_ 5.522149009306
$node_(13) set Z_ 0.000000000000
$node_(14) set X_ 28.935083056450
$node_(14) set Y_ 37.156742480258
$node_(14) set Z_ 0.000000000000
$node_(15) set X_ 23.507724673396
$node_(15) set Y_ 3.566772846479
$node_(15) set Z_ 0.000000000000
$node_(16) set X_ 20.236128396148
$node_(16) set Y_ 45.484419961171
$node_(16) set Z_ 0.000000000000
$node_(17) set X_ 45.709636471608
$node_(17) set Y_ 48.353113573382
$node_(17) set Z_ 0.000000000000
$node_(18) set X_ 45.610349971557
$node_(18) set Y_ 49.787732692400
$node_(18) set Z_ 0.000000000000
$node_(19) set X_ 24.345058881159
$node_(19) set Y_ 19.614188426582
$node_(19) set Z_ 0.000000000000
$node_(20) set X_ 35.972132273531
$node_(20) set Y_ 10.620805728046
$node_(20) set Z_ 0.000000000000
$node_(21) set X_ 49.626765649851
$node_(21) set Y_ 14.028905860151
$node_(21) set Z_ 0.000000000000
$node_(22) set X_ 14.914806804685
$node_(22) set Y_ 24.094071765795
$node_(22) set Z_ 0.000000000000
$node_(23) set X_ 28.443020411336
$node_(23) set Y_ 24.367299319338
$node_(23) set Z_ 0.000000000000
$node_(24) set X_ 48.102836431793
$node_(24) set Y_ 22.394995544608
$node_(24) set Z_ 0.000000000000


set namtrace [open wireless.nam w]   
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

proc finish {} {
    global ns f namtrace f1 f2 f3
    $ns flush-trace
    close $f
    close $namtrace
    close $f1
    close $f2
    close $f3
    exec nam wireless.nam &
    exit 0
}

proc record { } {
    global sink1  f1 f2 f3
    set ns [Simulator instance]
    set time 1.0
    set now [$ns now]
    set b0 [$sink1 set bytes_]
    set b1 [$sink1 set nlost_ ]
    set b2 [$sink1 set npkts_ ]
    set bw0 [expr $b0/$time*8/1000]
    puts $f2 "$now $bw0"
    puts $f1 "$now $b1"
    puts $f3 "$now $b2"
    $sink1 set bytes_ 0
    $ns at [expr $now+$time] "record"
}


set udp1 [new Agent/UDP]
$ns attach-agent $node_(10) $udp1

set sink1 [new Agent/LossMonitor]
$ns attach-agent $node_(0) $sink1
$ns connect $udp1 $sink1
$udp1 set fid_ 2

set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set type_ CBR
$cbr1 set packet_size_ 70
$cbr1 set rate_ 120k
$cbr1 set random_ false

#set cbr2 [new Application/Traffic/Pareto]
#$cbr2 attach-agent $udp1
#$cbr2 set type_ Pareto
#$cbr2 set packet_size_ 70
#$cbr2 set rate_ 10k
#$cbr2 set random_ false

#set cbr3 [new Application/Traffic/Exponential]
#$cbr3 attach-agent $udp1
#$cbr3 set type_ Exponential
#$cbr3 set packet_size_ 70
#$cbr3 set rate_ 10k
#$cbr3 set random_ false

for {set i 0} {$i < $val(nn)} {incr i} {
    $ns initial_node_pos $node_($i) 2
}

$ns at 0.0 "record"

$ns at 0.1 "$cbr1 start"
$ns at 20.1 "$cbr1 stop"
#$ns at 21.1 "$cbr2 start"
#$ns at 41.1 "$cbr2 stop"
#$ns at 42.1 "$cbr3 start"
#$ns at 62.1 "$cbr3 stop"

$ns at 63.0 "finish"
$ns run

此代码与终端错误

When configured, ns found the right version of tclsh in /usr/bin/tclsh8.6
but it doesn't seem to be there anymore, so ns will fall back on running the first tclsh in your path. The wrong version of tclsh may break the test suites. Reconfigure and rebuild ns if this is a problem.
num_nodes is set 0
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl

    (_o14 cmd line 1)
    invoked from within
"_o14 cmd addr"
    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 "_o14" line 2)
    (SplitObject unknown line 2)
    invoked from within
"_o14 addr"
    ("eval" body line 1)
    invoked from within    
"eval $node addr $args"
    ("default" arm line 2)
    invoked from within
"switch -exact $routingAgent_ {
    DSDV {
    set ragent [$self create-dsdv-agent $node]
    }
    DSR {
    $self at 0.0 "$node start-dsr"
    }
    AODV {
    set ragent [$self cre..."
    (procedure "_o3" line 14)
    (Simulator create-wireless-node line 14)
    invoked from within
"_o3 create-wireless-node"
    ("eval" body line 1)
    invoked from within
"eval $self create-wireless-node $args"
    (procedure "_o3" line 23)
    (Simulator node line 23)
    invoked from within
"$ns node"
    ("for" body line 2)
    invoked from within
"for {set i 0} {$i < $val(nn) } {incr i} {
    set node_($i) [$ns node]    
    $node_($i) random-motion 0      ;
    }"
    (file "prog.tcl" line 71)

我需要模拟才能正确运行。

0 个答案:

没有答案