下面代码说明了如何访问其他节点的Agent,以AODV协议为例
添加以下代码到aodv.cc. 用这种方法也可以访问其他对象,比如 mobilenode, 等等.
AODV* aodvagent;
// set i to be the node id
char command[256];
// [Agent/AODV info instances] 返回一个aodvagent的数组
sprintf(command, "foreach aodvagent [Agent/AODV info instances]\
{\nif { [$aodvagent id] == %d} {\nset i $aodvagent}}\nset t $i\n", i);
Tcl& tcl = Tcl::instance();
tcl.eval(command);
const char* ref = tcl.result();
aodvagent = (AODV*)tcl.lookup(ref);
这种方法需要在Agent的成员函数command中含有返回agent节点地址的命令:
if (argc == 2) {
Tcl& tcl = Tcl::instance();
if(strncasecmp(argv[1], "id", 2) == 0) {
tcl.resultf("%d", ra_addr_);
return TCL_OK;
}
//other command
...
}
添加新的Application后报错:
invalid command name "Application/Fire"
while executing
"Application/Fire create _o1931 "
导致的原因是新加的Class没有编译,检查是否把新的object加入到ns的Makefile的OBJ_CC中,加入后编译在运行ns脚本。