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

Re: packets number & a bug in PacketQueue::remove (?)



Yuri,

Thank you very much for your answer: the INT_MAX was not my problem, but your
suggest has been usefull.

First of all I'd like to ask you if my coprehension of events scheduling in
NS is correct. Accordingly to what I've understood, every packet/event has a
uid_ (init=0) and Scheduler has its static uid_ (init=1) which is at any time
the total number of scheduled events since that moment. Initially when an
event is scheduled its uid_ (0) becomes equal to Scheduler uid_; then when it
is dispatched it becomes -uid_. A packet is scheduled and dispatched more
times during the simulation, but every scheduling action is preceded by a
dispatch action and viceversa. If I occured in "Scheduler: Event UID not
valid!" (in Scheduler::schedule) it means that I'm trying to schedule a
packet/event a second time without any dispatch action between.

Second: my problem was due to a little bug (in my opinion) in
PacketQueue::remove (Packet*) in queue.cc. Suppose to have two element, A end
B, so:

len_=2
head_->A
tail_->B
Anext_->B
Bnext_->0

If you call remove(B), the result is:

len_=1
head_->A
tail_->A
Anext_->B   <---!!!

It's all right except that Anext_ is not 0 but point still to B, so if you
visit the queue with the next_ pointers you would occur in mistakes. I modify
with:

void PacketQueue::remove(Packet* target)
{
    for (Packet *pp= 0, *p= head_; p; pp= p, p= p->next_) {
        if (p == target) {
            if (!pp) deque();
            else {
                if (p == tail_)
                    tail_= pp;
                // else   <-------------COMMENT THIS LINE
                    pp->next_= p->next_;
                --len_;
            }
            return;
        }
    }
    fprintf(stderr, "PacketQueue:: remove() couldn't find target\n");
    abort();
}

Third: in NS Notes&Documentations the Link Scheduler is described as the
default scheduler, but in ns-default.tcl the init instproc of class Simulator
is:

Simulator instproc init args {
 $self create_packetformat

 #the calendar scheduler doesn't work on big mobile network runs
 #it dies around 240 secs...
 #$self use-scheduler List

 $self use-scheduler Calendar
 .....

Max.

Yuri Pryadkin wrote:

> Massimo,
>
> Each time a new event is scheduled, it's assigned a unique ID (static
> int Scheduler::uid_).  Given a large number of events, it may wrap
> around and become negative.  What is maximum possible int value on
> your system (INT_MAX in limits.h)?  Is it possible that the number of
> events in your simulations exceed that value?
>
>  -Yuri

--
Massimo Pegorer, student
Dipartimento di Elettronica e Informatica
Universita' degli Studi di Padova
Padova - ITALIA