Eraseth
Eraseth

Reputation: 523

Get attributes of an Agent in NS2

I actually need to know the attributes of my UDP Agent in my TCL script (to print some values and use it for statistics) and this is my first time with this script language. I tried to use the command info but I failed to use it.

This is my code :

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

I tried with :

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

No more result. Can you tell me what I did wrong and how to get the attributes of my Agent/UDP object.

Upvotes: 1

Views: 283

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137627

The problem is that there are multiple object systems about. Agent/UDP is an OTcl class, whereas info class operates on TclOO classes. TclOO (the standard object system from Tcl 8.6 onwards) is quite a lot newer than OTcl and has more features (it is faster too) but the syntax is a bit different in the detail so we don't expect ns-2 to ever be ported over. (There is a twisted heritage from OTcl to TclOO via XOTcl… but the syntax isn't one of the things that made the transition, as that was drawn more from another object system, [incr Tcl]. Tcl's been “blessed” with a plague of object systems.)

Documentation for OTcl isn't the easiest to find, but this page is helpful, as is the equivalent for instances. In particular, it tells us that we can do introspection via the info instproc (i.e., method):

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

Upvotes: 1

Related Questions