【问题标题】:Tcl "can't read "ifqlen_": no such variable"Tcl“无法读取“ifqlen_”:没有这样的变量”
【发布时间】:2018-04-23 00:36:22
【问题描述】:

我找不到解决这个问题的方法,当我改变时

for {set i 0} {$i < $opt(row)} {incr i} {
for {set j 0} {$j < $opt(col)} {incr j} {  

for {set i 1} {$i < $opt(row)} {incr i} {
for {set j 1} {$j < $opt(col)} {incr j} {

我发现另一个问题是“无法读取”node_(0)”:没有这样的变量

set opt(netif) Phy/WirlessPhy ;#network interface type
set opt(chan) Channel/WirelessChannel ;#channel type
set opt(prop) Propagation/TwoRayGround ;#radio-propagation model
set opt(ant) Antenna/OmniAntenna ;#antenna model 
set opt(mac) Mac/802_11 ;#mac type
set opt(ifq) Queue/DropTail/PriQueue ;#interface queue type
set opt(ll) LL ;#link layer type
set opt(ifqlen) 10 ;#max packet
set opt(nn) 2 ;#nombre de noeud
set opt(rp) DSDV ;#protocol
set opt(MaxX) 500 ;#longueur
set opt(MaxY) 500 ;#longuer 
set opt(row) 2;
set opt(col) 1;        
######################
set ns_  [new Simulator] 
#####################
set nf   [open TP2.nam w]
$ns_ namtrace-all $nf
$ns_ namtrace-all-wireless $nf $opt(MaxX) $opt(MaxY)
############################
set tracefile [open TP2.tr w]
$ns_ trace-all $tracefile
##########################
set topo [new Topography]
$topo load_flatgrid $opt(MaxX) $opt(MaxY)
########################
set god [create-god $opt(nn)]
##################
$ns_ color 1 Green
$ns_ color 2 Red
########################
$ns_ node-config   -adhocRouting $opt(rp) \
                   -llType $opt(ll) \
                   -macType $opt(mac) \
                   -ifqType $opt(ifq) \
                   -ifqlen $opt(ifqlen)\
                   -antType $opt(ant) \
                   -propType $opt(prop) \
                   -phyType $opt(netif) \
                   -channelType $opt(chan) \
                   -topoInstance $topo \
                   -agentTrace ON \
                   -routerTrace ON \
                   -macTrace ON\
                   -movementTrace ON 
##################
 for {set i 0} {$i < $opt(row)} {incr i} {
 for {set j 0} {$j < $opt(col)} {incr j} {

                     set nodenum [expr ($i*$opt(col))+($j)]
                     set nodenum_($nodenum) [$ns_ node $nodenum]

                     set xpos[expr ($i+1)*$opt(dist)]
                     set ypos[expr ($j+1)*$opt(dist)]

                     $node_($nodenum) set X_$xpos
                     $node_($nodenum) set Y_$ypos

                     $node_($nodenum) random-motion 0
                     $ns_ initial_node_pos $node_($nodenum) 20 }}    
###################################
$node_(0) Color Red
$node_(0) shape circle
$node_([expr $opt(nn)-1]) color Green
$ns_ at 0.0"$node_(0) color red"
$ns_ at 0.0"$node_(0) label Emetteur"
$ns_ at 0.0"$node_([expr$opt(nn)-1]) color blue"
$ns_ at 0.0"$node_([expr$opt(nn)-1]) label Recepteur"
################################
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(0)$tcp
$ns_ attach-agent $node_(1)$sink
$ns_ connect$tcp$sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 0.01 "$ftp start"
############################
proc finish{}{
  global ns_tracefile
  $ns_ flush-trace 
  close $tracefile
  puts "simulation terminée"
  exit 0
}
for {set i 0} {$i < $opt(nn)}{incr i}{
   $ns_at$opt(stop) "\$node_($i) reset"
}
$ns_ at $opt(stop) "finish"
$ns_ at $opt(stop) "put\"done\";$ns_halt"
$ns_ run

帮助

【问题讨论】:

    标签: tcl ns2


    【解决方案1】:

    "无法读取 "node_(0)": 没有这样的变量

    未定义节点:文件中缺少用于节点配置的行。

    “无法读取“ifqlen_”:没有这样的变量”

    由第 1 行中的拼写错误引起:Phy/WirlessPhy → 必须是 Phy/WirelessPhy

    修复了大约 100 个拼写错误后,您的文件可以正常工作,从而创建文件 TP2.nam 9.2kB、TP2.tr 5.2kB。非常小的文件大小可能是由这个错误引起的:--- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---

    编辑:得到结果,没有错误:其他节点位置 → 跟踪文件现在是 24MB / 13MB。

    $node_(0) set X_ 299
    $node_(0) set Y_ 248
    $node_(1) set X_ 297
    $node_(1) set Y_ 496
    

    $ nam TP2.nam:一个不错的动画。

    编辑后的文件:不完美....但有一些工作要做... (file.diff:原始与编辑https://www.dropbox.com/s/98wxqbgttyj8arv/Priority-Queue.tar.gz?dl=0

    set opt(netif) Phy/WirelessPhy          ;#network interface type
    set opt(chan) Channel/WirelessChannel   ;#channel type
    set opt(prop) Propagation/TwoRayGround  ;#radio-propagation model
    set opt(ant) Antenna/OmniAntenna        ;#antenna model 
    set opt(mac) Mac/802_11                 ;#mac type
    set opt(ifq) Queue/DropTail/PriQueue    ;#interface queue type
    set opt(ll) LL              ;#link layer type
    set opt(ifqlen) 10          ;#max packet
    set opt(dist)   250
    set opt(nn) 2               ;#nombre de noeud
    set opt(rp) DSDV            ;#protocol
    set opt(MaxX) 500           ;#longueur
    set opt(MaxY) 500           ;#longuer 
    set opt(row) 2;
    set opt(flow)       3
    set opt(col) 1;
    set opt(stop) 100        
    ######################
    set ns_  [new Simulator] 
    #####################
    set nf   [open TP2.nam w]
    $ns_ namtrace-all $nf
    $ns_ namtrace-all-wireless $nf $opt(MaxX) $opt(MaxY)
    ############################
    set tracefile [open TP2.tr w]
    $ns_ trace-all $tracefile
    ##########################
    set topo [new Topography]
    $topo load_flatgrid $opt(MaxX) $opt(MaxY)
    ########################
    set god [create-god $opt(nn)]
    ##################
    $ns_ color 1 Green
    $ns_ color 2 Red
    ########################
    set ifqlen_ 10
    
    $ns_ node-config   -adhocRouting $opt(rp) \
                       -llType $opt(ll) \
                       -macType $opt(mac) \
                       -ifqType $opt(ifq) \
                       -ifqLen $opt(ifqlen) \
                       -antType $opt(ant) \
                       -propType $opt(prop) \
                       -phyType $opt(netif) \
                       -channelType $opt(chan) \
                       -topoInstance $topo \
                       -agentTrace ON \
                       -routerTrace ON \
                       -macTrace ON \
                       -movementTrace ON
    
    set node_(0) [$ns_ node]
    set node_(1) [$ns_ node]
    
    
    ##################
     for {set i 0} {$i < $opt(row)} {incr i} {
     for {set j 0} {$j < $opt(col)} {incr j} {
    
                         set nodenum [expr ($i*$opt(col))+($j)]
                         set nodenum_($nodenum) [$ns_ node $nodenum]
    
    #                     set xpos[expr ($i+1)*$opt(dist)]
    #                     set ypos[expr ($j+1)*$opt(dist)]
    
    #                     $node_($nodenum) set X_$xpos
    #                     $node_($nodenum) set Y_$ypos
    
    $node_(0) set X_ 299
    $node_(0) set Y_ 248
    $node_(1) set X_ 297
    $node_(1) set Y_ 496
    
                         $node_($nodenum) random-motion 0
                         $ns_ initial_node_pos $node_($nodenum) 20 }}    
    ###################################
    $node_(0) color red
    $node_(0) shape circle
    $node_([expr $opt(nn)-1]) color green
    $ns_ at 0.0 "$node_(0) color red"
    $ns_ at 0.0 "$node_(0) label Emetteur"
    $ns_ at 0.0 "$node_(1) color blue"
    $ns_ at 0.0 "$node_(1) label Recepteur"
    ################################
    set tcp [new Agent/TCP]
    set sink [new Agent/TCPSink]
    $ns_ attach-agent $node_(0) $tcp
    $ns_ attach-agent $node_(1) $sink
    $ns_ connect $tcp $sink
    set ftp [new Application/FTP]
    $ftp attach-agent $tcp
    $ns_ at 0.01 "$ftp start"
    ############################
    proc finish {} {
      global ns_tracefile
      $ns_ flush-trace 
      close $tracefile
      puts "simulation terminée"
      exit 0
    }
    for {set i 0} {$i < $opt(nn)} {incr i} {
       $ns_ at $opt(stop) "\$node_($i) reset"
    }
    $ns_ at $opt(stop) "finish"
    $ns_ at $opt(stop) "put\"done\";$ns_ halt"
    $ns_ run
    

    【讨论】:

    • 请查看编辑后的答案:更好的节点位置。
    • 模拟运行良好,但不存在 NAM
    • 如果你的意思是没有“nam 跟踪文件”,TP2.nam : ..... 获取我的模拟文件.tcl 的工作副本,以及文件 TP2.nam、TP2.tr → @ 987654322@
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    相关资源
    最近更新 更多