cbrgen启动模拟开始

时间:2014-07-18 13:51:10

标签: bash tcl ns2

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

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\""

1 个答案:

答案 0 :(得分:0)

您似乎正在编写代码来编写代码。这比仅仅编写代码要困难得多。

立即错误是您正在调用的模拟器正在尝试运行名为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的一部分而不是预处理器的一部分......