From 44d311cd3b111b68a0bdb6874856be54b7675b2c Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Wed, 15 Dec 2021 17:03:09 -0300 Subject: [PATCH] network: Add function to check if a queue would overflow --- src/network/utils/net-device-queue-interface.h | 8 ++------ src/network/utils/queue.cc | 13 +++++++++++++ src/network/utils/queue.h | 9 +++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/network/utils/net-device-queue-interface.h b/src/network/utils/net-device-queue-interface.h index d33b4f64f..ea537d3b4 100644 --- a/src/network/utils/net-device-queue-interface.h +++ b/src/network/utils/net-device-queue-interface.h @@ -347,12 +347,10 @@ NetDeviceQueue::PacketEnqueued (QueueType* queue, PtrGetSize ()); NS_ASSERT_MSG (m_device, "Aggregated NetDevice not set"); - Ptr p = Create (m_device->GetMtu ()); - // After enqueuing a packet, we need to check whether the queue is able to // store another packet. If not, we stop the queue - if (queue->GetCurrentSize () + p > queue->GetMaxSize ()) + if (queue->WouldOverflow (1, m_device->GetMtu ())) { NS_LOG_DEBUG ("The device queue is being stopped (" << queue->GetCurrentSize () << " inside)"); @@ -370,13 +368,11 @@ NetDeviceQueue::PacketDequeued (QueueType* queue, PtrGetSize ()); NS_ASSERT_MSG (m_device, "Aggregated NetDevice not set"); - Ptr p = Create (m_device->GetMtu ()); - // After dequeuing a packet, if there is room for another packet we // call Wake () that ensures that the queue is not stopped and restarts // the queue disc if the queue was stopped - if (queue->GetCurrentSize () + p <= queue->GetMaxSize ()) + if (!queue->WouldOverflow (1, m_device->GetMtu ())) { Wake (); } diff --git a/src/network/utils/queue.cc b/src/network/utils/queue.cc index 9eceefd46..c113d2a36 100644 --- a/src/network/utils/queue.cc +++ b/src/network/utils/queue.cc @@ -220,4 +220,17 @@ QueueBase::GetMaxSize (void) const return m_maxSize; } +bool +QueueBase::WouldOverflow (uint32_t nPackets, uint32_t nBytes) const +{ + if (m_maxSize.GetUnit () == QueueSizeUnit::PACKETS) + { + return (m_nPackets + nPackets > m_maxSize.GetValue ()); + } + else + { + return (m_nBytes + nBytes > m_maxSize.GetValue ()); + } +} + } // namespace ns3 diff --git a/src/network/utils/queue.h b/src/network/utils/queue.h index 915f8aee2..3814657ba 100644 --- a/src/network/utils/queue.h +++ b/src/network/utils/queue.h @@ -178,6 +178,15 @@ public: */ QueueSize GetMaxSize (void) const; + /** + * \brief Check if the queue would overflow with additional bytes or packets + * Note: the check is performed according to the queue's operating mode (bytes or packets). + * \param nPackets number of additional packets + * \param nBytes number of additional bytes + * \return true if the queue should overflow, false otherwise. + */ + bool WouldOverflow (uint32_t nPackets, uint32_t nBytes) const; + #if 0 // average calculation requires keeping around // a buffer with the date of arrival of past received packets