7.2 Example: Drop Tail

The following example illustrates the implementation of the Queue/DropTail object, which implements FIFO scheduling and drop-on-overflow buffer management typical of most present-day Internet routers. The following definitions declare the class and its OTcl linkage:

        /*
         * A bounded, drop-tail queue
         */
        class DropTail : public Queue {
         protected:
                void enque(Packet*);
                Packet* deque();
                PacketQueue q_;
        };
The base class Queue, from which DropTail is derived, provides most of the needed functionality. The drop-tail queue maintains exactly one FIFO queue, implemented by including an object of the PacketQueue class. Drop-tail implements its own versions of enque and 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 restrictions), and then checks the size of the packet queue versus qlim_. Drop-on-overflow is implemented by dropping the packet most recently added to the packet queue if the limit is reached or exceeded. Note: in the implementation of enque above, setting qlim_ to n actually means a queue size of n-1. Simple FIFO scheduling is implemented in the deque function by always returning the first packet in the packet queue.

Tom Henderson 2014-12-17