[ns] Setting variables in C++ using Tcl

Shruti Gorappa shruti at doc.ece.uci.edu
Thu Apr 13 14:16:49 PDT 2006


I would like to set values in a packet header using Tcl. For example, 
set the packetSize_ variable in the Ping header (found in 
ns-allinone-2.29/ns-2.29/ns-tutorial/examples). However, when I set 
packetSize_ in Tcl, it does not change the default value. The 
tcl/lib/ns-default.tcl file has the value set to 64, and that value is 
not changed. The constructor in ping.cc calls bind() to bind the Tcl and 
C++ values. Is there anything else that needs to be done in order to 
bind these values? 

I noticed this problem when I made a new header and tried to pass values 
from my tcl script to C++. The values in C++ were all 0. I went back to 
the Ping example and found the same thing happening there. I read the 
manual and the tutorial by Marc Greis, and I think I have followed all 
the necessary steps.

However, when I call this code in my C++ code explicitly (I have this in the command() function), the packetSize value is 

 Tcl& tcl = Tcl::instance();
 tcl.eval("Agent/MyAgent set packetSize_ 128");
 const char* size_=tcl.result();

My guess is that this is not the right way to set the variables, and because I bind the Tcl and C++ variables, I should just be able to set them in my .tcl script.
Does anyone know what the likely problem is? I have otcl and tclcl in the appropriate path variables according to the installation instructions. Is there a problem with my ns2 installation, or am I missing something while doing the binding? Thanks.

Shruti

-- 
Shruti Gorappa

Distributed Object Computing Laboratory
608 Engineering Tower
University of California, Irvine

sgorappa at uci.edu
http://doc.ece.uci.edu/~shruti
(949) 824-7548




More information about the Ns-users mailing list