12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}}}void Queue::resume(){Packet* p = deque();if (p != 0)target_->recv(p, &qh_);else {if (unblock_on_resume_)blocked_ = 0;elseblocked_ = 1;}}<strong>The</strong> h<strong>and</strong>ler management here is somewh<strong>at</strong> subtle. When a new Queue object is cre<strong>at</strong>ed, it includes a QueueH<strong>and</strong>lerobject (qh_) which is initialized to contain a reference to the new Queue object (Queue& QueueH<strong>and</strong>ler::queue_).This is performed by the Queue co<strong>ns</strong>tructor using the expression qh_(*this). When a Queue receives a packet it callsthe subclass (i.e. queueing discipline-specific) version of the enque function with the packet. If the queue is not blocked,it is allowed to send a packet <strong>and</strong> calls the specific deque function which determines which packet to send, blocks thequeue (because a packet is now in tra<strong>ns</strong>it), <strong>and</strong> sends the packet to the queue’s dow<strong>ns</strong>tream neighbor. Note th<strong>at</strong> any futurepackets received from upstream neighbors will arrive to a blocked queue. When a dow<strong>ns</strong>tream neighbor wishes to causethe queue to become unblocked it schedules the QueueH<strong>and</strong>ler’s h<strong>and</strong>le function by passing &qh_ to the simul<strong>at</strong>or scheduler.<strong>The</strong> h<strong>and</strong>le function invokes resume, which will send the next-scheduled packet dow<strong>ns</strong>tream (<strong>and</strong> leave the queueblocked), or unblock the queue when no packet is ready to be sent. This process is made more clear by also referring to theLinkDelay::recv() method (Section 8.1).7.1.2 PacketQueue Class<strong>The</strong> Queue class may implement buffer management <strong>and</strong> scheduling but do not implement the low-level oper<strong>at</strong>io<strong>ns</strong> on aparticular queue. <strong>The</strong> PacketQueue class is used for this purpose, <strong>and</strong> is defined as follows (see queue.h):class PacketQueue {public:PacketQueue();int length(); /* queue length in packets */void enque(Packet* p);Packet* deque();Packet* lookup(int n);/* remove a specific packet, which must be in the queue */void remove(Packet*);protected:Packet* head_;Packet** tail_;int len_;// packet count};This class maintai<strong>ns</strong> a linked-list of packets, <strong>and</strong> is commonly used by particular scheduling <strong>and</strong> buffer management disciplinesto hold an ordered set of packets. Particular scheduling or buffer management schemes may make use of several72

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!