Hi Jana,

Interesting Problem !! But, unfortunately I am also new to NS-2, so I 
can't answer your question in the way you expected, but I can propose an 
alternate solution, purely on the C++ platform.

If you need just one instance of the ContextAgent object, you can create 
a Global variable or a member variable in AODV class, where you can 
register your pointer to the newly created ContextAgent Object. Now, in 
your AODV code when you need to access the member variables of the 
ContextAgent object, you simply dereference this pointer and access the 
variables. Obviously, you can acess them, as AODV has been declared as a 
Friend Class.

Alternately, if you need more than one instances of the ContextAgent 
class, you can create a Global or a member variable in AODV class, of 
the type HashTable or something simmilar, in which you can register an 
identifier and the pointer to the ContextAgent object, everytime you 
create it. Whenever you need to access the variables of the ContextAgent 
class, you will also have to pass along this identifier, so as to access 
the appropriate object. This identifier could be the node name or 
anything you please.

This could be a way out of your situation, even though it will be much 
better and smarter, if you are able to find the way of accessing objects 
created in your TCL script, in the C++ code !!

Hope this helps.

Regards,
Prashant Batra

Jana Henniger wrote:
> I’m new to ns-2 and C++ and need help concerning OTCL-Linkage.
> I’ve created a new class ContextAgent which has AODV as friendclass. 
> ContextAgent has two public variables that are bound to OTCL using the 
> bind()-function (as it is used in the Example ex-linkage.cc from the tutorial 
> “ns by example”). That works, as far as I could see.
>
> My problem is, how can I call on the variables from the AODV-function 
> sendRequest()?
> Since the ContextAgent is created in the simulation script, I don’t know the 
> name of it to assign it to an object of the type ContextAgent.
>
> I send parts of my source code for better understanding. Please help!!
>
> *************************************************
>
> class ContextAgent : public Agent{
>
> friend class AODV;
>
> public:
>       ContextAgent();
>       int rq_context;
>       int rt_context;
> }
>
> //LinkObject
> static class ContextAgentClass : public TclClass {
> public:
>       ContextAgentClass() : TclClass("Agent/Context"){}
>       TclObject* create(int, const char*const*) {
>               return (new ContextAgent());
>       }
> } class_context_agent;
>
> //Constructor
> ContextAgent::ContextAgent() : Agent(PT_AODV) {
>       bind("rq_cxt_otcl", &rq_context);
>       bind("rt_cxt_otcl", &rt_context);
> };
>
> *************************************
>
> class AODV: public Agent {
>  ...
> private:
>       ContextAgent  *ContextAgentObject;
>  ...
> };
>
> **************************************
>
> // call in AODV-function
> void
> AODV::sendRequest(nsaddr_t dst) {
>  ...
>       ContextAgentObject = ????;
>       rq->rq_cxt = ContextAgentObject->rq_context;
>  ...
> }
>
> **************************************
>
> # tcl-code
>  ...
>       set context1 [new Agent/Context]
>         $ns_ attach-agent $node_(1) $context1
>         $context1 set rq_cxt_otcl 0   
>         $context1 set rt_cxt_otcl 5   
>  ...
>
>
>   

Reply via email to