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.

PacketQueue objects. <strong>The</strong> PacketQueue class maintai<strong>ns</strong> current counts of the number of packets held in the queuewhich is returned by the length() method. <strong>The</strong> enque function places the specified packet <strong>at</strong> the end of the queue <strong>and</strong>upd<strong>at</strong>es the len_ member variable. <strong>The</strong> deque function retur<strong>ns</strong> the packet <strong>at</strong> the head of the queue <strong>and</strong> removes it fromthe queue (<strong>and</strong> upd<strong>at</strong>es the counters), or retur<strong>ns</strong> NULL if the queue is empty. <strong>The</strong> lookup function retur<strong>ns</strong> the nth packetfrom the head of the queue, or NULL otherwise. <strong>The</strong> remove function deletes the packet stored in the given address fromthe queue (<strong>and</strong> upd<strong>at</strong>es the counters). It causes an abnormal program termin<strong>at</strong>ion if the packet does not exist.7.2 Example: Drop Tail<strong>The</strong> following example illustr<strong>at</strong>es the implement<strong>at</strong>ion of the Queue/DropTail object, which implements FIFO scheduling<strong>and</strong> drop-on-overflow buffer management typical of most present-day Internet routers. <strong>The</strong> following definitio<strong>ns</strong> declare theclass <strong>and</strong> its OTcl linkage:/** A bounded, drop-tail queue*/class DropTail : public Queue {protected:void enque(Packet*);Packet* deque();PacketQueue q_;};<strong>The</strong> base class Queue, from which DropTail is derived, provides most of the needed functionality. <strong>The</strong> drop-tail queuemaintai<strong>ns</strong> exactly one FIFO queue, implemented by including an object of the PacketQueue class. Drop-tail implementsits own versio<strong>ns</strong> of enque <strong>and</strong> deque as follows:/** drop-tail*/void DropTail::enque(Packet* p){q_.enque(p);if (q_.length() >= qlim_) {q_.remove(p);drop(p);}}Packet* DropTail::deque(){return (q_.deque());}Here, the enque function first stores the packet in the internal packet queue (which has no size restrictio<strong>ns</strong>), <strong>and</strong> then checksthe size of the packet queue versus qlim_. Drop-on-overflow is implemented by dropping the packet most recently addedto the packet queue if the limit is reached or exceeded. Note: in the implement<strong>at</strong>ion of enque above, setting qlim_ to nactually mea<strong>ns</strong> a queue size of n-1. Simple FIFO scheduling is implemented in the deque function by always returning thefirst packet in the packet queue.73

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

Saved successfully!

Ooh no, something went wrong!