network: Add function to check if a queue would overflow
This commit is contained in:
@@ -347,12 +347,10 @@ NetDeviceQueue::PacketEnqueued (QueueType* queue, Ptr<const typename QueueType::
|
||||
NotifyQueuedBytes (item->GetSize ());
|
||||
|
||||
NS_ASSERT_MSG (m_device, "Aggregated NetDevice not set");
|
||||
Ptr<Packet> p = Create<Packet> (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, Ptr<const typename QueueType::
|
||||
NotifyTransmittedBytes (item->GetSize ());
|
||||
|
||||
NS_ASSERT_MSG (m_device, "Aggregated NetDevice not set");
|
||||
Ptr<Packet> p = Create<Packet> (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 ();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user