[EMAIL PROTECTED] wrote:
> The agent.h file defines the argument to connect as nsaddr_t and not
> ns_addr_t. (My ns version is ns-2.30)

Same here, I'm using 2.30 as well. You need to change the
definition/declaration to ns_addr_t.


> And i need to dynamically connect src agent to dst agent, and not agent to
> node (which is what i think i was doing).

That solely depends on where you get the address from that you pass to
Agent::connect(). Agent::connect() is a unidirectional link so you need to
make sure you get the right address.


> i.e i need to perfomr the tcl command "$ns connect $agent1 $agent2" inside
> my c++ code giving me the freedom to choose $agent2. (Does this command
> call the Agent::connect function?...i am not sure because in the
> Agent::command it falls under the category argc == 3, but here we have 4
> arguments)

I'll tell you how I do it: I have this application which uses ns-2's
existing UDP agent. Within that application, I call it like this:


if (agent_) {
                agent_->connect(&dst);
        }
        else {
                cerr << "cannot establish UDP link: no agent attached" << endl;
                return;
        }


To get the remote agent's address, I implemented a command()
"sub-function" in my application C++ object to set a default destination
(you need something to start with).

If I want to reply to an incoming message, I use the source address as
parameter for Agent::connect().


> so i added the following code, in my C++ file
> char x[50];
> int q = 5;
> int w = 6;
> sprintf(x, "$ns connect $p(%d) $p(%d)", q, w);
> Tcl& tcl = Tcl::instance();
> tcl.eval(x);
>
> But the agent $p(5) is connected to $someagent (connection of which was
> done at configuration time) and not to $p(6) as i have done in the code.
> Where am i going wrong.

It's kinda hard to tell what the problem is as you use fixed values and I
must assume that this is right (which might not be the case).

When I debugged my connect implementation, I let C++ show me the
addresses/ports of the agents in question and used additional output in
Agent::connect() and <MyApplication>::process_data(). Latter was only
possible because I used AppData for my custom packet types, but you can do
something similar even if you're not using that class.

Debugger is helpful is well. I'm pretty sure you'll need it to figure out
where exactly things go wrong.


Cheers,

--Timo




---------------------------------------------------------------------------
>> I need to connect agents dynamically for my purpose, so i have changed
>> the
>> agent.cc code as suggested by the comments in it.
>>
>> /* This function is a placeholder in case applications want to
>> dynamically
>> *  connect to agents (presently, must be done at configuration time).
>> */
>> void Agent::connect(nsaddr_t dst)
>> {
>>
>>          dst_ = dst;
>>
>> }
>>
>> Then i get the following compilation error:
>>
>> common/agent.cc: In member function &#8216;virtual void
>> Agent::connect(nsaddr_t)&#8217;:
>> common/agent.cc:393: error: no match for &#8216;operator=&#8217; in
>> &#8216;((Agent*)this)->Agent::dst_ = dst&#8217;
>> ./config.h:80: note: candidates are: ns_addr_t&
>> ns_addr_t::operator=(const
>> ns_addr_t&)
>> make: *** [common/agent.o] Error 1
>
> Well, the compile error says it all: You are trying to use the copy
> operator ("=") for an object (a struct) although no such operator is
> defined. C++ does not provide the "=" operator for structs by default.
>
> Actually, you are using the wrong ns2 address type. There's been some
> discussion on the mailing list that nsaddr_t has been obsoleted by
> ns_addr_t  (mind the additional underscore). Check config.h to see for
> implementation details.
>
> Luckily, some while ago I had to implement on-the-fly connectivity myself.
> This is what my implemention of the connect method looks like:
>
> void Agent::connect(ns_addr_t* dst)
> {
>       this->daddr() = dst->addr_;
>       this->dport() = dst->port_;
> }
>
> I cannot remember if ns_addr_t was a pointer by default and you removed
> that asterisk or whether it was no pointer variable originally and I made
> it one. If you don't use pointers, I'd recommend references (actually,
> that'd have been a better approach anyway). In each case, you should
> verify that your definition matches the declaration in common/agent.h and
> if you don't use pointers make sure you're using the "." operator instead
> of "->" on the `dst' parameter.
>
>
>> What i need to do is the following:  Use a single agent to send packets
>> to
>> multiple agents sitting on diff nodes. I need the freedom to choose the
>> destination agent in my agent C++ code depending upon the case.
>>
>> So one way of doing this would to dynamically connect the agents in the
>> c++ code using the function (connect((nsaddr_t)atoi("_o480")); where
>> _0480
>> is the value returned by ns for "$my-dst-agent"
>
> I think that's gonna fail. Not just because you're not employing ns_addr_t
> structure but because you're trying to get a node address from its name
> within connect(). Again, take a look at how ns_addr_t is defined: It's a
> struct containing an address and a port part. Both are just simple
> discrete values and assigned by ns-2 in a linear fashion as nodes are
> created (AFAIK).
>
> What you need to do is determine a node's address using Agent's member
> functions after looking up the node with the lookup() method used quite
> often in command() definitions (this might just be what $my-dst-agent
> does, but I am not sure as I haven't used it) and then pass that to the
> connect function.
>
>
> HTH,
>
> --Timo
>
>
>


Reply via email to