Re: [ns] OTCL-Linkage
Hi Jana, I dont' know if you have resolved you problem, but here is something that I came accross. To access a variable declared in ur TCL scrip, u can use the follwing method :- Tcl& tcl = Tcl::instance(); tcl.lookup(char* s); The 'lookup()' function of Tcl class takes a pointer to the name of the variable in the TCL script and returns you a TclObject class object, which you can further typecast into your specific object type and use. - Prashant Henni Girl wrote: > Hello Prashant Batra, > > actually I thought about a solution with global variables, > but I want to use my new class the same way the AODV protocol is used > just with some extensions and without affecting AODV. > That's why I think it's best to go on looking for a solution accessing > objects created in my tcl script. > Thank you anyway. > > jana > > >
Re: [ns] OTCL-Linkage
Hello Prashant Batra, actually I thought about a solution with global variables, but I want to use my new class the same way the AODV protocol is used just with some extensions and without affecting AODV. That's why I think it's best to go on looking for a solution accessing objects created in my tcl script. Thank you anyway. jana -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
Re: [ns] OTCL-Linkage
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 > ... > > >
Re: [ns] OTCL-Linkage
Hi Jana, I can't see the solution straight away and without looking at it longer I can't tell you. Your solution looks ok but I am concerned about your use of friend. Does it actually create an AODV agent? I'd suggest using gdb with breakpoints to work out what is going on. 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 > ... > > >
Re: [ns] OTCL-Linkage
Hi Jana, I suggest you first check whether the bound variables work with AODV in the first place. If they do not work then you will need to get a reference to the AODV agent in .tcl simulation script. You can start looking in tcl/lib P. 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 > ... > > >