终端路径tcl

时间:2014-07-10 21:25:33

标签: tcl ns2

Hy家伙我试图在终端中调用这个tcl,但它给了我这个错误

num_nodes is set 0
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
can't read "node_(0)": no such variable
while executing
"$node_(0) set X_ 133.516460138239"
(file "/tmp/mob.tcl" line 4)
invoked from within
"source.orig /tmp/mob.tcl"
("uplevel" body line 1)
invoked from within
"uplevel source.orig [list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
..."
(procedure "source" line 8)
invoked from within
"source  "/tmp/mob.tcl" "
(file "mobilita_source.tcl" line 125)

并且tcl文件是

#define ions

   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
     Mac/802_11 set RTSThreshold_ 500  ;            
     Mac/802_11 set dataRate_ 24Mb   ;
     Mac/802_11 set basicRate_ 6Mb   ;
     Mac/802_11 set CWMin_ 31    ;
     Mac/802_11 set CWMAX_ 1023  ;
     Mac/802_11 set SlotTime_ 0.000009 ;    
     Mac/802_11 set SIFS_ 0.000016    ;
     Mac/802_11 set ShortRetryLImit_ 7 ;
     Mac/802_11 set LOngRetryLimit_ 7  ;


     set val(ifq)   Queue/DropTail/PriQueue     ;# interface queue type
     set val(ifqlen)        50              ;# max packet in ifq
     set val(ll)    LL              ;# link layer type
     set val(ant)   Antenna/OmniAntenna     ;# antenna model
     set val(adhocRouting)   AODV           ;# routing protocol


      set val(x)        250             ;# X dimension of the topography
      set val(y)        250             ;# Y dimension of the topography

      set val(tr)       esercizio1.tr       ;# trace file
      set val(rate)           [lindex $argv 0]  ;
      set val(nn)             [lindex $argv 1]        ;# how many nodes are simulated
      set val(stop)     [lindex $argv 3]    ;# simulation time
      set val(seed)     0.0

#主程序

# Initialize Global Variables

# create simulator instance

 set ns_        [new Simulator]

 # define topology

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

 # create trace object for ns and nam

 set tracefd    [open $val(tr) w]

 $ns_ trace-all $tracefd



 $ns_ use-newtrace 



 # Create God

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

 # define how node should be created

 #global node setting

  $ns_ node-config  -adhocRouting $val(adhocRouting) \
     -llType $val(ll) \
     -macType $val(mac) \
     -ifqType $val(ifq) \
     -ifqLen $val(ifqlen) \
     -antType $val(ant) \
     -propType $val(prop) \
     -phyType $val(netif) \
     -channelType $val(chan) \
     -topoInstance $topo \
     -agentTrace ON \
     -routerTrace ON \
     -macTrace ON


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

  for {set i 0} {$i < $val(nn) } {incr i} {
  set node_($i) [$ns_ node] 
  }


  # Define node positions

   source  "/tmp/mob.tcl" 

  # Define traffic flows

  source "traffic"

  for {set i 0} {$i < 4 } {incr i} {

  $cbr_($i) set interval_ [ expr 1 /$rate ]

  }




  # Tell nodes when the simulation ends

  for {set i 0} {$i < $val(nn) } {incr i} {
  $ns_ at $val(stop).000000001 "$node_($i) reset";
  }

  $ns_ at $val(stop).000000001 "puts \"NS EXITING...\" ; $ns_ halt"


  puts "Starting Simulation..."
  $ns_ run

我从终端调用了ns mobilita_source,但它描述了我,所以我认为它可能是mobilita_souce.tcl文件中的路径/ tmp。在tmp中,我注意到该文件存在。

1 个答案:

答案 0 :(得分:0)

未设置变量node_(0),因此变量不可读。这意味着设置它的代码没有运行,可能是因为变量val(nn)包含0,或者可能是因为它包含其他值 - 可能是非数字的 - 排序小于{{1} }; 空字符串是这样的值1的值来自val(nn),因此它是Tcl脚本之后的第二个参数,您传递给可执行文件以调用该程序(假设它类似于tclsh)。

如果参数不足,您将从lindex $argv 1获取一个空字符串(出于向后兼容的原因,超出范围lindex会产生一个空字符串而不是抛出错误)。建议您明确检查是否传递了足够的参数:

lindex

然后,您可以(假设Tcl 8.5或8.6)使用if {[llength $argv] < 4} { error "missing arguments, needs: rate, nn, ??, seed" } 将这些变量写入变量;它比一堆lassign更清晰,更容易纠正:

set … [lindex $argv …]

在8.4及之前(现在已过时的版本),您可以改为:

# your posted code ignores one argument...
lassign $argv val(rate) val(nn) ?? val(seed)

但那真的不太清楚。

相关问题