ns2jenkins-2

wrong # args: should be "_o3 self class proc file optx opty"


When I ran the tcl code, the following error appeared:

wrong # args: should be "o3 self class proc file optx opty" (Simulator namtrace-all-wireless line 1) invoked from within "$ns namtrace-all-wireless $namtracefd" (file "test1.tcl" line 26)

How should I modify my tcl code to make the program run correctly.

This is code script in tcl file:

set opt(ifqlen) 50
set opt(nn) 6
set opt(rp) AODV
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/S-MAC
#set opt(mac) Mac/LMAC
set opt(ifq) Queue/DropTail/PriQueue
set opt(x) 2000
set opt(y) 500
set opt(ll) LL
set opt(stop) 1000
set opt(energymodel) EnergyModel
set opt(initialenergy) 1000
set opt(receivepower) 0.3682
set opt(transmitpower) 0.3442
set opt(idlepower) 0.3442
set opt(sleeppower) 5.0e-5
set opt(transitionpower) 0.05
set opt(transitiontime) 0.0005
set ns_ [new Simulator]
set tracefd [open 1Sthreenodes.tr w]
$ns_ trace-all $tracefd
set namtracefd [open 1Sthreenodes.nam w]
$ns_ namtrace-all-wireless $namtracefd
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
set channel [new Channel/WirelessChannel]
$ns_ node-config -adhocRouting $opt(rp) \
                                -llType $opt(ll) \
                                -macType $opt(mac) \
                                -ifqType $opt(ifq) \
                                -ifqLen $opt(ifqlen)
                                -antType $opt(ant) \
                                -propType $opt(prop) \
                                -phyTyenter code herepe $opt(netif) \
                                -channel $channel \
                                -topoInstance $topo \
                                -energyModel $opt(energymodel)\
                                -txPower $opt(transmitpower)\
                                -rxPower $opt(receivepower)\
                                -idlePower $opt(idlepower)\
                                -sleepPower $opt(sleeppower)\
                                -transitionPower $opt(transitionpower)\
                                -transitionTime $opt(transitiontime)\
                                -initialEnergy $opt(initialenergy)\
                                -agentTrace ON \
                                -routerTrace ON \
                                -macTrace ON \
                                -movementTrace OFF
for {set i 0} {$i < $opt(nn)} {incr i} {
          set node_($i) [$ns_ node]
          $node_($i) random-motion 0;
}
for {set i 0} {$i < $opt(nn)} {
     $node_($i) set X_ [expr $i*200]
     $node_($i) set Y_ [expr $opt(y)/2]
     $node_($i) set Z_ 0.0
}
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(0) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(5) $null_(0)
$ns_ connect $udp_(0) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 1.0
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 1000
$cbr_(0) attach-agent $udp_(0)
$ns_ at 10.0 "$cbr_(0) start“
for {set i 0} {$i < $opt(nn)} {incr i} {
    $ns_ at $opt(stop).0 "$node_($i) reset";
}
$ns_ at $opt(stop).0 "stop“
$ns_ at $opt(stop).01 "puts \"NS EXITING...\"; $ns_ halt"
proc stop {} {
     global ns_ tracefd
     $ns_ flush-trace
     close $tracefd
}
puts "starting simulation..."
$ns_ run

Solution

  • wrong # args: should be ... optx opty

    One of several typos: The original line 26 should be $ns_ namtrace-all-wireless $namtracefd $opt(x) $opt(y)

    Snippet, examples editing

    -set opt(mac) Mac/S-MAC
    +set opt(mac) Mac/SMAC          ;# edit to the ns2 default SMAC
    
    +set opt(ant)    Antenna/OmniAntenna     ;# antenna model missing
    
    +set opt(x) 2000      ;# area added
    +set opt(y) 500
    
    +# create God
    +create-god [expr $opt(nn)]     ;# missing god
    
     $ns_ node-config -adhocRouting $opt(rp) \
                                     -llType $opt(ll) \
                                     -macType $opt(mac) \
                                     -ifqType $opt(ifq) \
    -                                -ifqLen $opt(ifqlen)     (missing \)
    +                                -ifqLen $opt(ifqlen) \
                                     -antType $opt(ant) \
                                     -propType $opt(prop) \
    -                                -phyTyenter code herepe $opt(netif) \ (!!)
    -                                -channel $channel \      (surplus ?)
    +                                -phyType $opt(netif) \
    +                                -channelType $opt(chan) \   (missing line)
    
    
    +# Define initial node position in nam    (missing definition)
    +for {set i 0} {$i < $opt(nn)} {incr i} {
    +$ns_ initial_node_pos $node_($i) 40
    
    -$ns_ at 10.0 "$cbr_(0) start“
    +$ns_ at 10.0 "$cbr_(0) start"          ;# forbidden character “ edited
    
    -$ns_ at $opt(stop).0 "stop“           
    +$ns_ at $opt(stop).0 "stop"            ;# forbidden character “ edited
    

    An edited file example is here https://drive.google.com/file/d/1OP49HAAhxHumWacE_qsSq1gFBZkLi0ak/view?usp=sharing

    NAM complains "node 6 not defined". Suggest: Edit nn to 7 nodes.

    Second example = 2-zhang-test1.tcl, with node positions https://drive.google.com/drive/folders/1aTFX1vJs2k0IchPCqq6cpj_UKeTHch31?usp=sharing : Special SMAC example Energy_wireless-4x4-grid+4__flows.tcl is included.


    SMAC-examples-4.tar.gz https://drive.google.com/file/d/1nO4aZWwL7wkmAlVOGGZI40-kjl4bqeb0/view?usp=sharing

    ns2 Energy model examples https://drive.google.com/file/d/1g8WnlHHHnNXBLc0rwJY4i1z9uieKtl9s/view?usp=sharing

    All ~2500 ex https://drive.google.com/drive/folders/0B7S255p3kFXNSmRYb2lGcDRUdWs?usp=sharing