diff --git a/src/network/utils/drop-tail-queue.cc b/src/network/utils/drop-tail-queue.cc index 5a8785a7c..084164c3b 100644 --- a/src/network/utils/drop-tail-queue.cc +++ b/src/network/utils/drop-tail-queue.cc @@ -72,6 +72,20 @@ DropTailQueue::DoDequeue (void) return item; } +Ptr +DropTailQueue::DoRemove (void) +{ + NS_LOG_FUNCTION (this); + NS_ASSERT (m_packets.size () == GetNPackets ()); + + Ptr item = m_packets.front (); + m_packets.pop (); + + NS_LOG_LOGIC ("Removed " << item); + + return item; +} + Ptr DropTailQueue::DoPeek (void) const { diff --git a/src/network/utils/drop-tail-queue.h b/src/network/utils/drop-tail-queue.h index 8f796ecda..9b4c4893b 100644 --- a/src/network/utils/drop-tail-queue.h +++ b/src/network/utils/drop-tail-queue.h @@ -49,6 +49,7 @@ public: private: virtual bool DoEnqueue (Ptr item); virtual Ptr DoDequeue (void); + virtual Ptr DoRemove (void); virtual Ptr DoPeek (void) const; std::queue > m_packets; //!< the items in the queue diff --git a/src/network/utils/queue.cc b/src/network/utils/queue.cc index 0788b9b30..228fef2ff 100644 --- a/src/network/utils/queue.cc +++ b/src/network/utils/queue.cc @@ -158,6 +158,32 @@ Queue::Dequeue (void) return item; } +Ptr +Queue::Remove (void) +{ + NS_LOG_FUNCTION (this); + + if (m_nPackets.Get () == 0) + { + NS_LOG_LOGIC ("Queue empty"); + return 0; + } + + Ptr item = DoRemove (); + + if (item != 0) + { + NS_ASSERT (m_nBytes.Get () >= item->GetPacketSize ()); + NS_ASSERT (m_nPackets.Get () > 0); + + m_nBytes -= item->GetPacketSize (); + m_nPackets--; + + Drop (item); + } + return item; +} + void Queue::DequeueAll (void) { diff --git a/src/network/utils/queue.h b/src/network/utils/queue.h index b1309490d..93f28592d 100644 --- a/src/network/utils/queue.h +++ b/src/network/utils/queue.h @@ -64,10 +64,15 @@ public: */ bool Enqueue (Ptr item); /** - * Remove an item from the front of the Queue + * Remove an item from the front of the Queue, counting it as dequeued * \return 0 if the operation was not successful; the item otherwise. */ Ptr Dequeue (void); + /** + * Remove an item from the front of the Queue, counting it as dropped + * \return 0 if the operation was not successful; the item otherwise. + */ + Ptr Remove (void); /** * Get a copy of the item at the front of the queue without removing it * \return 0 if the operation was not successful; the item otherwise. @@ -221,10 +226,15 @@ private: */ virtual bool DoEnqueue (Ptr item) = 0; /** - * Pull an item from the queue + * Pull the item to dequeue from the queue * \return the item. */ virtual Ptr DoDequeue (void) = 0; + /** + * Pull the item to drop from the queue + * \return the item. + */ + virtual Ptr DoRemove (void) = 0; /** * Peek the front item in the queue * \return the item.