ns2 中得到Agent的实例

下面代码说明了如何访问其他节点的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脚本。

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值