[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New Agent creation



Hi everyone,
my question is this:
when you create a new agent, what are the places that you have to define
this agent in, other than the .cc and .h files? (~ns/tcl/lib/ns-lib.tcl
maybe?)
I have created a very simple M/M/1 model agent, with mm1_agent.cc and
mm1_agent.h, and i re-compiled ns with the new modules added, and obtained
the object,
but when i try to attach this new agent to a node in a simulation using the
$simulator attach methos, i get the following error:

>
>    (_o22 cmd line 1)
>    invoked from within
>"_o22 cmd target _o8"
>    invoked from within
>"catch "$self cmd $args" ret"
>    (procedure "_o22" line 2)
>    (SplitObject unknown line 2)
>    invoked from within
>"$agent target [$self entry]"
>    (procedure "_o7" line 6)
>    (Node attach line 6)
>    invoked from within
>"$node attach $agent"
>    (procedure "_o3" line 2)
>    (Simulator attach-agent line 2)
>    invoked from within
>"$ns attach-agent $n0 $src0"
>    (file "mm1.tcl" line 18)
>

my cc and include files are attached if you're intrested.
Thanks!


#include "mm1_agent.h"
#include "random.h"
#include "tcp.h"
#include "agent.h"

extern double tcplib_telnet_interarrival();

static class MM1Class : public TclClass {
public:
	MM1Class() : TclClass("Agent/MM1") {}
	TclObject* create(int argc, const char*const* argv) {
		return (new MM1_Agent());
	}
} class_mm1; 

MM1_Agent::MM1_Agent() : Agent(PT_TCP), timer_(this), running_(0), interval_(1)
{
	bind_time("interval_", &interval_);
}

int MM1_Agent::command(int argc, const char*const* argv)
{
        Tcl& tcl = Tcl::instance();

	if (argc == 2) {
		if (strcmp(argv[1], "start") == 0) {
			start();
			return (TCL_OK);
		}
		if (strcmp(argv[1], "stop") == 0) {
			stop();
			return (TCL_OK);
		}
	}
        return (TclObject::command(argc, argv));

}

void MM1_AgentTimer::expire(Event*)
{
        t_->timeout();
}

void MM1_Agent::sendit()
{
	Packet* p = allocpkt();
	send(p, 0);
}


void MM1_Agent::timeout()
{
        if (running_) {
                /* send the freakin packet */
                sendit();
                /* reschedule the timer */
                double t = next();
                timer_.resched(t);
        }
}


void MM1_Agent::start()
{
        running_ = 1;
	double t = next();
	timer_.sched(t);
}

void MM1_Agent::stop()
{
        running_ = 0;
}


double MM1_Agent::next()
{
        if (interval_ == 0)
	        /* use tcplib */
	        return tcplib_telnet_interarrival();
	else
	        return Random::exponential() * interval_;
}

#ifndef ns_mm1_h
#define ns_mm1_h

#include "agent.h"
#include "tclcl.h"
#include "timer-handler.h"

class MM1_AgentTimer;
class MM1_Agent;


class MM1_AgentTimer : public TimerHandler {
 public:
	MM1_AgentTimer(MM1_Agent* t) : TimerHandler(), t_(t) {}
	inline virtual void expire(Event*);
 protected:
	MM1_Agent* t_;
};

class MM1_Agent : public Agent {
 public:
	MM1_Agent();
	void timeout();
 protected:
	int command(int argc, const char*const* argv);
	void start();
	void stop();
	inline double next();

	MM1_AgentTimer timer_;
	int running_;
	double interval_;
	void sendit();
};

#endif


--

-sherif