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

issue on class TrafficGenerator: improvement?



Hi!

Within the class Traffic Generator, there are the following functions
in ns-2.1b6-current (Jun 16):

-----------------
void TrafficGenerator::stop()
{
	timer_.cancel();
	running_ = 0;
}


void TrafficGenerator::timeout()
{
        if (! running_)
		return;

	/* send a packet */
	send(size_);
	/* figure out when to send the next one */
	nextPkttime_ = next_interval(size_);
	/* schedule it */
	if (nextPkttime_ > 0)
		timer_.resched(nextPkttime_);
}
-------------------

If next_interval (size_) in timeout() returns a value smaller or equal
than zero (E.g., I have set in the derived class CBR maxpkts_ to a
certain value), calling stop() leads to trouble, because timer_.cancel
has no timer to cancel anymore. You can reproduce this also by typing:

$$$$$$$$$$$$$
% set c [new Application/Traffic/CBR]
_o4
% $c stop
Attempting to cancel timer at 0x826fd70 which is not scheduled
ns: [Simulator instance] flush-trace: Cannot find instance of simulator
    while executing
"error "Cannot find instance of simulator""
    (procedure "Simulator" line 12)
    (Simulator instance line 12)
    invoked from within
"Simulator instance"
$$$$$$$$$$$$$$

Of course, it is easy to see here, that it does not make sense to stop
a non-running CBR traffic generator, but if you use the above
mentioned variable maxpkts_ together with something like:

$ns at 4.0 "$c stop"

it is really hard to see, where the problem lies (at least for a
newbie to ns like me).

I would suggest to add two small things to the above code to avoid
this behaviour:

At first, calling stop, when the traffic generator is not running,
should not lead to an abort of the tcl interpreter, which can be
avoided by adding one line to stop() as shown below.

Second, the traffic generator must go into 'not running' state
(running_ = 0), when next_interval() does not give another time to
schedule the next packet. In this way, a later call to stop() will not
cause an abort.

---------------
void TrafficGenerator::stop()
{
/* added JD */
	if (running_)
/* added end */
		timer_.cancel();

	running_ = 0;
}


void TrafficGenerator::timeout()
{
        if (! running_)
		return;

	/* send a packet */
	send(size_);
	/* figure out when to send the next one */
	nextPkttime_ = next_interval(size_);
	/* schedule it */
	if (nextPkttime_ > 0)
		timer_.resched(nextPkttime_);
/* added JD */
	else
		running_ = 0;
/* added JD end */
}
----------------

I do not have a complete picture about what's happening in the code
here, so there are perhaps smarter solutions to this problem and I
might not consider all problems introduced by these changes. But this
one worked at least for me (up to now :)

With best regards,

/J"org

------
J"org Diederich
Institute of Operating Systems and Computer Networks, 
Technical University Braunschweig, Germany
e-mail: [email protected]