A NS2 problem "invalid command name "Agent/MyAgentOtcl", solved!
Saturday, March 25, 2006 5:35:00 AM

Problem:
I installed ns2.29.2 on my Debian box several days ago. After looking into the hyacinth project for some days, I start to try making a new component on ns2. As "NS By Example" told me, add the following two files to it (I rename the ex-linkage.{cc,tcl} to free.{cc,tcl}).
------------------------------------------------------------------------------
File: free.cc
#include <stdio.h>
#include <string.h>
#include "agent.h"
class MyAgent : public Agent {
public:
MyAgent();
protected:
int command(int argc, const char*const* argv);
private:
int my_var1;
double my_var2;
void MyPrivFunc(void);
};
static class MyAgentClass : public TclClass {
public:
MyAgentClass() : TclClass("Agent/MyAgentOtcl") { }
TclObject* create(int, const char*const*) {
return (new MyAgent());
}
} class_my_agent;
MyAgent::MyAgent() : Agent(PT_UDP) {
bind("my_var1_otcl", &my_var1);
bind("my_var2_otcl", &my_var2);
}
int MyAgent::command(int argc, const char*const* argv) {
if(argc ==2) {
if(strcmp(argv[1], "call-my-priv-fun") == 0) {
MyPrivFunc();
return(TCL_OK);
}
}
return(Agent::command(argc, argv));
}
void MyAgent::MyPrivFunc(void) {
Tcl& tcl = Tcl::instance();
tcl.eval("puts \"Message From MyPrivFunc\"");
tcl.evalf("puts \" my_var1 = %d\"", my_var1);
tcl.evalf("puts \" my_var2 = %f\"", my_var2);
}
------------------------------------------------------------------------------
File: free.tcl
set myagent [new Agent/MyAgentOtcl]
$myagent call-my-priv-fun
puts "start \n"
------------------------------------------------------------------------------
First, I add free.o in OBJ_CC part of Makefile, after I "make" in ns2 directory, and run "ns free.tcl", a error occured as follows:
invalid command name "Agent/MyAgentOtcl"
while executing
"Agent/MyAgentOtcl create _o3 "
invoked from within
"catch "$className create $o $args" msg"
(procedure "new" line 3)
invoked from within
"new Agent/MyAgentOtcl"
invoked from within
"set myagent [new Agent/MyAgentOtcl]"
(file "./free.tcl" line 6)
I googled to find the solution of this problem, however maybe it's too easy to answer. Many people asked the same question, but no helpful answer. Finally, I found the solution on a chinese forum on ns2-simulation.
Solution:
Just run " make install ", after you run "make".
Also, maybe you should declare the default value of all the Otcl variables of your *.cc file in /ns/tcl/lib/ns-default.tcl, this will keep away from some ugly warnings.








JeannieLee # Thursday, April 20, 2006 7:18:56 AM
make clean
make depend
make
make install
but the error information remained the same
my msn: loislee8@hotmail.com
can we talk about it
Salviosalviobarros # Thursday, February 24, 2011 6:59:10 PM
Can we discuss by msn: sassa_xarope@hotmail.com
Please let me know when you be available
Regards
salvio