NS2 Notebook: How to Get Instance of Routing Agent

Back to NS2 Menu


This simple example shows how to access the AODV routing agent of other nodes. Use the following code in aodv.cc. This method can also be used to access other objects such as mobilenode, etc.

AODV* aodvagent;

// set i to be the node id

char command[256];

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);

 

 

Pedro Vale Estrela provides detailed comments on the code and give some other examples on how to call oTCL code from C++ counterpart. His NS page contains many other nice tips!

© Copyright 2008. All rights reserved. Powered by Free Site Templates