Thank you Timo for your reply.

Some more querries...

The agent.h file defines the argument to connect as nsaddr_t and not
ns_addr_t. (My ns version is ns-2.30)

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

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)

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.

Thank you for your patient reading.

Yours Sincerely
OVS Bharadwaj

---------------------------------------------------------------------------
> 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 ‘virtual void
> Agent::connect(nsaddr_t)’:
> common/agent.cc:393: error: no match for ‘operator=’ in
> ‘((Agent*)this)->Agent::dst_ = dst’
> ./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