获取 NS2 中代理的属性

Get attributes of an Agent in NS2

我实际上需要知道我的 TCL 脚本中 UDP 代理的属性(打印一些值并将其用于统计),这是我第一次使用这种脚本语言。我尝试使用命令 info 但我没有使用它。

这是我的代码:

#Setup a UDP connection
set udp [new Agent/UDP]
puts [$udp info class] # Work and print "Agent/UDP"
puts [info class variables Agent/UDP] #Fail with the error  "Agent/UDP does not refer to an object"

我试过:

puts [info class variables udp] #Fail (same error) 
puts [info class variables $udp] #Error : _o87 does not refer to an object

没有更多结果。 你能告诉我我做错了什么以及如何获取我的 Agent/UDP 对象的属性吗?

问题是关于有多个对象系统。 Agent/UDP 是一个 OTcl class,而 info class 在 TclOO classes 上运行。 TclOO(从 Tcl 8.6 开始的标准对象系统)比 OTcl 更新很多并且有更多的特性(它也更快)但是语法在细节上有点不同所以我们不期望 ns-2 永远是移植过来。 (从 OTcl 通过 XOTcl 到 TclOO 有一个扭曲的继承......但是语法不是进行转换的原因之一,因为它更多地来自 another 对象系统,[incr Tcl]。Tcl 因对象系统的瘟疫而“幸运”。)

OTcl 的文档不是最容易找到的,但是 this page is helpful, as is the equivalent for instances。特别是,它告诉我们可以通过 info instproc(即方法)进行内省:

set udp [new Agent/UDP]
puts [$udp info vars]
puts [$udp info commands]