From aa9cefe5024c9bb383486779df518f6da6e8d72e Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Sun, 27 Nov 2022 19:29:43 +0100 Subject: [PATCH] network: ScheduleNow() not only the wake callback, but also the check on its condition The wake callback is scheduled "now" to let the flow of operations associated with dequeue/remove complete before the flow control mechanism is triggered. Move the check on the conditions for calling the wake callback after the flow of operations is completed as well, in case the latter affect such conditions. --- .../utils/net-device-queue-interface.cc | 5 ++-- .../utils/net-device-queue-interface.h | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/network/utils/net-device-queue-interface.cc b/src/network/utils/net-device-queue-interface.cc index 2382119ab..32b40644e 100644 --- a/src/network/utils/net-device-queue-interface.cc +++ b/src/network/utils/net-device-queue-interface.cc @@ -22,7 +22,6 @@ #include "ns3/abort.h" #include "ns3/queue-item.h" #include "ns3/queue-limits.h" -#include "ns3/simulator.h" #include "ns3/uinteger.h" namespace ns3 @@ -89,7 +88,7 @@ NetDeviceQueue::Wake() // Request the queue disc to dequeue a packet if (wasStoppedByDevice && !m_wakeCallback.IsNull()) { - Simulator::ScheduleNow(&NetDeviceQueue::m_wakeCallback, this); + m_wakeCallback(); } } @@ -142,7 +141,7 @@ NetDeviceQueue::NotifyTransmittedBytes(uint32_t bytes) // Request the queue disc to dequeue a packet if (wasStoppedByQueueLimits && !m_wakeCallback.IsNull()) { - Simulator::ScheduleNow(&NetDeviceQueue::m_wakeCallback, this); + m_wakeCallback(); } } diff --git a/src/network/utils/net-device-queue-interface.h b/src/network/utils/net-device-queue-interface.h index b4efb6d51..ea2eeea9e 100644 --- a/src/network/utils/net-device-queue-interface.h +++ b/src/network/utils/net-device-queue-interface.h @@ -25,6 +25,7 @@ #include "ns3/object-factory.h" #include "ns3/object.h" #include "ns3/ptr.h" +#include "ns3/simulator.h" #include #include @@ -361,19 +362,21 @@ void NetDeviceQueue::PacketDequeued(QueueType* queue, Ptr item) { NS_LOG_FUNCTION(this << queue << item); - - // Inform BQL - NotifyTransmittedBytes(item->GetSize()); - NS_ASSERT_MSG(m_device, "Aggregated NetDevice not set"); - // 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->WouldOverflow(1, m_device->GetMtu())) - { - Wake(); - } + Simulator::ScheduleNow([=]() { + // Inform BQL + NotifyTransmittedBytes(item->GetSize()); + + // 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->WouldOverflow(1, m_device->GetMtu())) + { + Wake(); + } + }); } template