From 6dffcbb2fa4c80ef90af71d2728d3934437c319c Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Mon, 5 Jun 2017 11:23:19 +0200 Subject: [PATCH] wifi: WifiMacQueue needs to override some QueueBase methods --- src/wifi/model/dca-txop.cc | 8 +++--- src/wifi/model/edca-txop-n.cc | 8 +++--- src/wifi/model/wifi-mac-queue.cc | 44 ++++++++++++++++++++++++++++---- src/wifi/model/wifi-mac-queue.h | 27 +++++++++++++++++--- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/src/wifi/model/dca-txop.cc b/src/wifi/model/dca-txop.cc index 1f418ccf6..099190b94 100644 --- a/src/wifi/model/dca-txop.cc +++ b/src/wifi/model/dca-txop.cc @@ -240,7 +240,7 @@ DcaTxop::RestartAccessIfNeeded (void) { NS_LOG_FUNCTION (this); if ((m_currentPacket != 0 - || m_queue->HasPackets ()) + || !m_queue->IsEmpty ()) && !m_dcf->IsAccessRequested ()) { m_manager->RequestAccess (m_dcf); @@ -252,7 +252,7 @@ DcaTxop::StartAccessIfNeeded (void) { NS_LOG_FUNCTION (this); if (m_currentPacket == 0 - && m_queue->HasPackets () + && !m_queue->IsEmpty () && !m_dcf->IsAccessRequested ()) { m_manager->RequestAccess (m_dcf); @@ -360,7 +360,7 @@ bool DcaTxop::NeedsAccess (void) const { NS_LOG_FUNCTION (this); - return m_queue->HasPackets () || m_currentPacket != 0; + return !m_queue->IsEmpty () || m_currentPacket != 0; } void @@ -369,7 +369,7 @@ DcaTxop::NotifyAccessGranted (void) NS_LOG_FUNCTION (this); if (m_currentPacket == 0) { - if (!m_queue->HasPackets ()) + if (m_queue->IsEmpty ()) { NS_LOG_DEBUG ("queue empty"); return; diff --git a/src/wifi/model/edca-txop-n.cc b/src/wifi/model/edca-txop-n.cc index daef99e44..a16a089e3 100644 --- a/src/wifi/model/edca-txop-n.cc +++ b/src/wifi/model/edca-txop-n.cc @@ -153,7 +153,7 @@ bool EdcaTxopN::NeedsAccess (void) const { NS_LOG_FUNCTION (this); - return m_queue->HasPackets () || m_currentPacket != 0 || m_baManager->HasPackets (); + return !m_queue->IsEmpty () || m_currentPacket != 0 || m_baManager->HasPackets (); } uint16_t EdcaTxopN::GetNextSequenceNumberFor (WifiMacHeader *hdr) @@ -186,7 +186,7 @@ EdcaTxopN::NotifyAccessGranted (void) m_startTxop = Simulator::Now (); if (m_currentPacket == 0) { - if (!m_queue->HasPackets () && !m_baManager->HasPackets ()) + if (m_queue->IsEmpty () && !m_baManager->HasPackets ()) { NS_LOG_DEBUG ("queue is empty"); return; @@ -724,7 +724,7 @@ EdcaTxopN::RestartAccessIfNeeded (void) { NS_LOG_FUNCTION (this); if ((m_currentPacket != 0 - || m_queue->HasPackets () || m_baManager->HasPackets ()) + || !m_queue->IsEmpty () || m_baManager->HasPackets ()) && !m_dcf->IsAccessRequested ()) { Ptr packet; @@ -765,7 +765,7 @@ EdcaTxopN::StartAccessIfNeeded (void) { //NS_LOG_FUNCTION (this); if (m_currentPacket == 0 - && (m_queue->HasPackets () || m_baManager->HasPackets ()) + && (!m_queue->IsEmpty () || m_baManager->HasPackets ()) && !m_dcf->IsAccessRequested ()) { Ptr packet; diff --git a/src/wifi/model/wifi-mac-queue.cc b/src/wifi/model/wifi-mac-queue.cc index 5ceae0da5..28bd5ea69 100644 --- a/src/wifi/model/wifi-mac-queue.cc +++ b/src/wifi/model/wifi-mac-queue.cc @@ -403,7 +403,7 @@ WifiMacQueue::GetNPacketsByTidAndAddress (uint8_t tid, WifiMacHeader::AddressTyp template<> bool -WifiMacQueue::HasPackets (void) +WifiMacQueue::IsEmpty (void) { NS_LOG_FUNCTION (this); @@ -411,12 +411,46 @@ WifiMacQueue::HasPackets (void) { if (!TtlExceeded (it)) { - NS_LOG_DEBUG ("returns true"); - return true; + NS_LOG_DEBUG ("returns false"); + return false; } } - NS_LOG_DEBUG ("returns false"); - return false; + NS_LOG_DEBUG ("returns true"); + return true; +} + +template<> +uint32_t +WifiMacQueue::GetNPackets (void) +{ + NS_LOG_FUNCTION (this); + + // remove packets that stayed in the queue for too long + for (auto it = Head (); it != Tail (); ) + { + if (!TtlExceeded (it)) + { + it++; + } + } + return QueueBase::GetNPackets (); +} + +template<> +uint32_t +WifiMacQueue::GetNBytes (void) +{ + NS_LOG_FUNCTION (this); + + // remove packets that stayed in the queue for too long + for (auto it = Head (); it != Tail (); ) + { + if (!TtlExceeded (it)) + { + it++; + } + } + return QueueBase::GetNBytes (); } NS_OBJECT_TEMPLATE_CLASS_DEFINE (WifiQueue,WifiMacQueueItem); diff --git a/src/wifi/model/wifi-mac-queue.h b/src/wifi/model/wifi-mac-queue.h index 9815826f7..09e023c20 100644 --- a/src/wifi/model/wifi-mac-queue.h +++ b/src/wifi/model/wifi-mac-queue.h @@ -284,13 +284,27 @@ public: uint32_t GetNPacketsByTidAndAddress (uint8_t tid, WifiMacHeader::AddressType type, Mac48Address addr); + /** - * This method must be used (instead of the IsEmpty method of the base class) - * to check whether there are packets with unexpired time to live in the queue + * \return true if the queue is empty; false otherwise * - * \return true if there are packets with unexpired time to live + * Overrides the IsEmpty method provided by QueueBase */ - bool HasPackets (void); + bool IsEmpty (void); + + /** + * \return The number of packets currently stored in the Queue + * + * Overrides the GetNPackets method provided by QueueBase + */ + uint32_t GetNPackets (void); + + /** + * \return The number of bytes currently occupied by the packets in the Queue + * + * Overrides the GetNBytes method provided by QueueBase + */ + uint32_t GetNBytes (void); private: /** @@ -307,6 +321,11 @@ private: DropPolicy m_dropPolicy; //!< Drop behavior of queue }; +/// Forward declare overridden methods to avoid specializing after instantiation +template<> bool WifiQueue::IsEmpty (void); +template<> uint32_t WifiQueue::GetNPackets (void); +template<> uint32_t WifiQueue::GetNBytes (void); + /// Declare WifiMacQueue as a specialization of template class WifiQueue typedef WifiQueue WifiMacQueue;