NS2中获取Agent的实例 (转)

下面代码说明了如何访问其他节点的Agent,以AODV协议为例

添加以下代码到aodv.cc. 用这种方法也可以访问其他对象,比如 mobilenode, 等等.

  1. AODV* aodvagent;   
  2.   
  3. // set to be the node id   
  4.   
  5. char command[256];   
  6.   
  7. // [Agent/AODV info instances] 返回一个aodvagent的数组   
  8. sprintf(command, "foreach aodvagent [Agent/AODV info instances]\   
  9. {\nif [$aodvagent id] == %d} {\nset $aodvagent}}\nset $i\n", i);   
  10.   
  11. Tcl& tcl Tcl::instance();   
  12. tcl.eval_r(command);   
  13. const charref tcl.result();   
  14.   
  15. aodvagent (AODV*)tcl.lookup(ref);  

这种方法需要在Agent的成员函数command中含有返回agent节点地址的命令:

  1. if (argc == 2) {   
  2.         Tcl& tcl Tcl::instance();   
  3.         if(strncasecmp(argv[1], "id"2) == 0) {   
  4.             tcl.resultf("%d"ra_addr_);   
  5.             return TCL_OK;   
  6.         }   
  7.                 //other command   
  8.                 ...   
  9.  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值