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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

};<strong>The</strong> enque <strong>and</strong> deque functio<strong>ns</strong> are pure virtual, indic<strong>at</strong>ing the Queue class is to be used as a base class; particular queuesare derived from Queue <strong>and</strong> implement these two functio<strong>ns</strong> as necessary. Particular queues do not, in general, override therecv function because it invokes the the particular enque <strong>and</strong> deque.<strong>The</strong> Queue class does not contain much internal st<strong>at</strong>e. Often these are special monitoring objects (Chapter 26). <strong>The</strong> qlim_member is co<strong>ns</strong>tructed to dict<strong>at</strong>e a bound on the maximum queue occupancy, but this is not enforced by the Queue classitself; it must be used by the particular queue subclasses if they need this value. <strong>The</strong> blocked_ member is a booleanindic<strong>at</strong>ing whether the queue is able to send a packet immedi<strong>at</strong>ely to its dow<strong>ns</strong>tream neighbor. When a queue is blocked, it isable to enqueue packets but not send them.7.1.1 Queue blockingA queue may be either blocked or unblocked <strong>at</strong> any given time. Generally, a queue is blocked when a packet is in tra<strong>ns</strong>itbetween it <strong>and</strong> its dow<strong>ns</strong>tream neighbor (most of the time if the queue is occupied). A blocked queue will remain blocked aslong as it dow<strong>ns</strong>tream link is busy <strong>and</strong> the queue has <strong>at</strong> least one packet to send. A queue becomes unblocked only when itsresume function is invoked (by mea<strong>ns</strong> of a dow<strong>ns</strong>tream neighbor scheduling it via a callback), usually when no packets arequeued. <strong>The</strong> callback is implemented by using the following class <strong>and</strong> methods:class QueueH<strong>and</strong>ler : public H<strong>and</strong>ler {public:inline QueueH<strong>and</strong>ler(Queue& q) : queue_(q) {}void h<strong>and</strong>le(Event*); /* calls queue_.resume() */priv<strong>at</strong>e:Queue& queue_;};void QueueH<strong>and</strong>ler::h<strong>and</strong>le(Event*){queue_.resume();}Queue::Queue() : drop_(0), blocked_(0), qh_(*this){Tcl& tcl = Tcl::i<strong>ns</strong>tance();bind("limit_", &qlim_);}void Queue::recv(Packet* p, H<strong>and</strong>ler*){enque(p);if (!blocked_) {/** We’re not block. Get a packet <strong>and</strong> 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_);71

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

Saved successfully!

Ooh no, something went wrong!