Add a new method to queue class for checking if a packet is going to be dropped diff -r 31da0db925b6 src/node/drop-tail-queue.cc --- a/src/node/drop-tail-queue.cc Wed Jul 08 23:00:49 2009 +0800 +++ b/src/node/drop-tail-queue.cc Thu Jul 09 21:25:49 2009 +0800 @@ -78,25 +78,38 @@ NS_LOG_FUNCTION_NOARGS (); return m_mode; } + +bool +DropTailQueue::WillDrop (Ptr p) const +{ + NS_LOG_FUNCTION (p); + + if (m_mode == PACKETS && (m_packets.size () >= m_maxPackets)) + { + NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt"); + return true; + } + + if (m_mode == BYTES && (m_bytesInQueue + p->GetSize () >= m_maxBytes)) + { + NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt"); + return true; + } + + // the packet is not going to be dropped + return false; +} bool DropTailQueue::DoEnqueue (Ptr p) { NS_LOG_FUNCTION (this << p); - if (m_mode == PACKETS && (m_packets.size () >= m_maxPackets)) - { - NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt"); - Drop (p); - return false; - } - - if (m_mode == BYTES && (m_bytesInQueue + p->GetSize () >= m_maxBytes)) - { - NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt"); - Drop (p); - return false; - } + if (WillDrop (p)) + { + Drop (p); + return false; + } m_bytesInQueue += p->GetSize (); m_packets.push(p); diff -r 31da0db925b6 src/node/drop-tail-queue.h --- a/src/node/drop-tail-queue.h Wed Jul 08 23:00:49 2009 +0800 +++ b/src/node/drop-tail-queue.h Thu Jul 09 21:25:49 2009 +0800 @@ -68,6 +68,10 @@ * \returns The encapsulation mode of this device. */ DropTailQueue::Mode GetMode (void); + /** + * \see Queue::WillDrop () + */ + bool WillDrop (Ptr p) const; private: virtual bool DoEnqueue (Ptr p); diff -r 31da0db925b6 src/node/queue.h --- a/src/node/queue.h Wed Jul 08 23:00:49 2009 +0800 +++ b/src/node/queue.h Thu Jul 09 21:25:49 2009 +0800 @@ -60,6 +60,12 @@ */ bool Enqueue (Ptr p); /** + * \brief Check if the packet is going to be dropped + * \param p The packet that is going to enqueue into a net device + * \return True of the packet is decided to be dropped, false otherwise + */ + virtual bool WillDrop (Ptr p) const = 0; + /** * Remove a packet from the front of the Queue * \return 0 if the operation was not successful; the packet otherwise. */