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

Re: [ns] priqueue.cc bug and fix



On Mon, 14 Aug 2000, you wrote:
> Hello,
> 
> Thanks for posting this as it is very useful for me. However, I'm not very sure abt how
> to fix my priqueue. Do I just insert those that are different from the original queue or
> do I need to delete some stuff. And what does all the numbers by the side means? eg. 64,
> 73c64.  Thanks.
> 

you don't need to delete anything.
In the following, replace {name of your routing protocol} by the
name of your routing protocol :-)

First edit the  PriQueue::recv function in priqueue.cc so that
it looks like the following:

void
PriQueue::recv(Packet *p, Handler *h)
{
        struct hdr_cmn *ch = HDR_CMN(p);

        if(Prefer_Routing_Protocols) {

                switch(ch->ptype()) {
		case PT_DSR:
		case PT_MESSAGE:
                case PT_TORA:
                case PT_AODV:
			recvHighPriority(p, h);
                        break;
			//robin
	    case PT_{name of your routing protocol}:
                        recvHighPriority{name of your routing protocol}(p, h);
                        break;

                default:
                        Queue::recv(p, h);
                }
        }
        else {
                Queue::recv(p, h);
        }
}


then add

void 
PriQueue::recvHighPriority{name of your routing protocol}(Packet *p, Handler *)
	// insert packet at front of queue, with caution (see priqueue.h)
	//-Robin
{
	//first get the pointer on the last routing packet
	Packet* search_p = q_->head();

	if (!search_p)
		q_->enqueHead(p);
	else {
		Packet* last_rt_p = 0;
		bool end_of_queue_reached = 0;
		struct hdr_cmn *ch = HDR_CMN(search_p);	
		
		while ((ch->ptype()==PT_{name of your routing protocol}) && (!end_of_queue_reached)) {
			if (!search_p->next_)
				end_of_queue_reached = 1;
			else {
				last_rt_p = search_p;
				search_p = search_p->next_;
			}
		}//of the while loop

		//2 mutually exclusive possibilities to get out of the previous
		//loop:
		//-either the end of the queue was reached, the queue was 
		//composed of {name of your routing protocol} packets only: Insert packet at the end of it.
		//-or(exclusive as I said) last_rt_p is the pointer on the
		//last {name of your routing protocol} packet of the queue. Note that if the first packet of 
		//the queue was not a {name of your routing protocol} packet, last_rt_p stays NULL and p
		//will be conveniently added at the head of the queue by 
		//PacketQueue::add(p,last_rt_p) (i.e. PacketQueue::add(p,NULL)).
		
		if (end_of_queue_reached)
			q_->enque(p);
		else 
			q_->add(p,last_rt_p);
	}

	if (q_->length() >= qlim_)
		{
			Packet *to_drop = q_->lookup(q_->length()-1);
			q_->remove(to_drop);
			drop(to_drop);
		}
	
	if (!blocked_) {
		/*
		 * We're not blocked.  Get a packet and send it on.
		 * We perform an extra check because the queue
		 * might drop the packet even if it was
		 * previously empty!  (e.g., RED can do this.)
		 */
		p = deque();
		if (p != 0) {
			blocked_ = 1;
			target_->recv(p, &qh_);
		}
	} 
}

somewhere in priqueue.cc, say line 143, it would be after the
PriQueue::recvHighPriority function definition.



then add 

void recvHighPriority{name of your routing protocol}(Packet *, Handler *);
  //insert packet at front of queue, 
  //BUT there might be several routing protocol packets
  //at the front of the queue already, and inserting 
  //bluntly this one ahead of them would boil down to
  //implementing a LIFO queue, which we don't want.
  //so the packet is inserted at the end of
  //the routing protocol packet queue which might exist
  //at the front of the queue.

line 64 of priqueue.h, in the class PriQueue definition just
after void    recvHighPriority(Packet *, Handler *);
        // insert packet at front of queue

that's all for priqueue.{cc,h}.
now in queue.h, line 77 or so add after
/* Remove a packet, located after a given packet. Either could
be 0. */ 	
void remove(Packet *, Packet *);

this:
	/* Adds a packet, located after a given packet. Either could be 0.-{name of your routing protocol} */
	void add(Packet *, Packet *);

and in  queue.cc, line 79 or so, after the PacketQueue::remove(Packet* pkt,
Packet *prev) function definition, add:

/*
 * Adds packet pkt located after packet prev on the queue.  Either p or prev
 * could be NULL.  If prev is NULL then pkt must be added at the head of the queue.
 *-{name of your routing protocol}
 */
void PacketQueue::add(Packet* pkt, Packet *prev) //XXX: screwy
{
	if (pkt){
		if (!prev)
			PacketQueue::enqueHead(pkt) ;/* increments len_ internally */
		else {
			pkt->next_=prev->next_;
			prev->next_ = pkt;
			if (!pkt->next_)
				tail_ = pkt;
			++len_;
		}
	}
	return;
}


and you are done.
--
Robin


keywords: AORV TORA routing protocol inversed order DSR