set myagent [new Agent/MyAgentOtcl]
Example C++ Network Component and The Linkage Object
When NS is first started, it executes the constructor for the static variable "class_my_agent", and thus an instance of "MyAgentClass" is created. In this process, the "Agent/MyAgentOtcl" class and its appropriate methods (member functions) are created in OTcl space. Whenever a user in OTcl space tries to create an instance of this object using the command "new Agent/MyAgentOtcl", it invokes "MyAgentClass::create" that creates an instance of "MyAgent" and returns the address. Note that creating a C++ object instance from OTcl does not mean that you can invoke member functions or access member variables of the C++ object instance from OTcl.
$myagent set my_var1_otcl 2
$myagent set my_var2_otcl 3.14
Variable Binding Creation Example
NS support four different binding functions for five different variable types as follows:
- bind(): real or integer variables - bind_time(): time variable - bind_bw(): bandwidth variable - bind_bool(): boolean variable |
Set the default value for that variable in the "ns-2/tcl/lib/ns-lib.tcl" file. Otherwise, you will get a warning message when you create an instant of your new object.
$myagent call-my-priv-func
Example OTcl command interpreter
Execute OTcl command from a C++ Object
Test OTcl Script and The Result