【问题标题】:cbrgen Starting Simulation startcbrgen 开始 模拟开始
【发布时间】:2014-07-18 13:51:10
【问题描述】:

我需要帮助来解决这个问题:

Starting Simulation...
    ns: start": invalid command name "start""
    while executing
   "start""

我有一个文件 bash 和一个文件 tcl,但我不知道为什么它总是给我这个问题。

这是文件 cbrgen 中的第二个问题

proc create-cbr-connection { src dst } {
global rng cbr_cnt opt

set stime [$rng uniform 0.0 10.0]

puts "#\n# $src connecting to $dst at time $stime\n#"

##puts "set cbr_($cbr_cnt) \[\$ns_ create-connection \
    ##CBR \$node_($src) CBR \$node_($dst) 0\]";

puts "set udp_($cbr_cnt) \[new Agent/UDP\]"
puts "\$ns_ attach-agent \$node_($src) \$udp_($cbr_cnt)"
puts "set null_($cbr_cnt) \[new Agent/Null\]"
puts "\$ns_ attach-agent \$node_($dst) \$null_($cbr_cnt)"
puts "set cbr_($cbr_cnt) \[new Application/Traffic/CBR\]"
puts "\$cbr_($cbr_cnt) set packetSize_ $opt(pktsize)"
puts "\$cbr_($cbr_cnt) set interval_ $opt(interval)"
puts "\$cbr_($cbr_cnt) set random_ 1"                                                           
puts "\$cbr_($cbr_cnt) set maxpkts_ 10000"
puts "\$cbr_($cbr_cnt) attach-agent \$udp_($cbr_cnt)"
puts "\$ns_ connect \$udp_($cbr_cnt) \$null_($cbr_cnt)"

set start [expr {10*rand()}]
puts "\$ns_ at $start \"\$cbr_($cbr_cnt) start\""
puts "\$ns_ at 100 \"\$cbr_($cbr_cnt) stop\""

【问题讨论】:

  • 您的代码示例太长了。将其缩小到您认为可能导致问题的部分。
  • 我认为这是部分:set start [expr {10*rand()}] puts "\$ns_ at $start\"\$cbr_($cbr_cnt) start\"" puts " \$ns_ 在 100\"\$cbr_($cbr_cnt) 停止\""

标签: bash tcl ns2


【解决方案1】:

看来你是在写代码来写代码。这比仅仅编写代码要困难得多。

直接的错误是您正在调用的模拟器正在尝试运行名为start 的命令,但您没有在该上下文中定义一个。显然,这不起作用,并且您会收到错误消息:它的意思正是它所说的。

更深入地挖掘,您的代码生成器似乎(在您编辑掉的代码中)通过以下方式编写对start 的调用:

puts $ns_ "blah blah blah...;start"

此时是否应该写一个对start 的调用?如果不是,那是你的问题; 是 Tcl 中的命令终止符,如果不加引号,即使它很少使用。)

否则,问题是您必须提供start 的定义,可能是通过一个过程。我不知道它应该做什么,但两个选项是写:

puts $ns_ [list proc start {} { ... the definition in here ... }]

list 构造了一个无引号命令,这在这里很有用。)

或者更好的是,将您的过程定义写入一个单独的文件,该文件不会根据cbrgen 所做的更改,例如static_definitions.tclsource,通过在顶部附近写入生成的文件:

puts $ns_ [list source [file normalize static_definitions.tcl]]
# This is just the paranoid upgrade of this simpler form:
#      puts $ns_ "source static_definitions.tcl"

Tcl 的 source 很像 C/C++ 的 #include,除了它是 Tcl 的一部分而不是预处理器的一部分……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多