diff --git a/src/wifi/model/mac-low.cc b/src/wifi/model/mac-low.cc index 0bb590da4..73f2f374f 100644 --- a/src/wifi/model/mac-low.cc +++ b/src/wifi/model/mac-low.cc @@ -674,7 +674,7 @@ MacLow::StartTransmission (Ptr packet, //queue when previous RTS request has failed. m_ampdu = false; } - else if (m_currentHdr.IsQosData () && m_aggregateQueue[GetTid (packet, *hdr)]->GetNPackets () > 0) + else if (m_currentHdr.IsQosData () && !m_aggregateQueue[GetTid (packet, *hdr)]->IsEmpty ()) { //m_aggregateQueue > 0 occurs when a RTS/CTS exchange failed before an A-MPDU transmission. //In that case, we transmit the same A-MPDU as previously. @@ -2026,7 +2026,7 @@ MacLow::SendDataAfterCts (Mac48Address source, Time duration) if (m_currentHdr.IsQosData ()) { uint8_t tid = GetTid (m_currentPacket, m_currentHdr); - if (m_aggregateQueue[GetTid (m_currentPacket, m_currentHdr)]->GetNPackets () != 0) + if (!m_aggregateQueue[GetTid (m_currentPacket, m_currentHdr)]->IsEmpty ()) { for (std::vector::size_type i = 0; i != m_txPackets[tid].size (); i++) { @@ -3006,7 +3006,7 @@ MacLow::AggregateToAmpdu (Ptr packet, const WifiMacHeader hdr) void MacLow::FlushAggregateQueue (uint8_t tid) { - if (m_aggregateQueue[tid]->GetNPackets () > 0) + if (!m_aggregateQueue[tid]->IsEmpty ()) { NS_LOG_DEBUG ("Flush aggregate queue"); m_aggregateQueue[tid]->Flush (); diff --git a/src/wifi/model/wifi-mac-queue.cc b/src/wifi/model/wifi-mac-queue.cc index 28bd5ea69..029cc83c8 100644 --- a/src/wifi/model/wifi-mac-queue.cc +++ b/src/wifi/model/wifi-mac-queue.cc @@ -163,15 +163,18 @@ WifiMacQueue::Enqueue (Ptr item) NS_ASSERT_MSG (GetMode () == QueueBase::QUEUE_MODE_PACKETS, "WifiMacQueues must be in packet mode"); - // if the queue is full, check if the time-to-live of the oldest packet has - // expired. If so, it can be removed so as to make room for the new packet. - if (GetNPackets () == GetMaxPackets ()) + // if the queue is full, remove the first stale packet (if any) encountered + // starting from the head of the queue, in order to make room for the new packet. + if (QueueBase::GetNPackets () == GetMaxPackets ()) { auto it = Head (); - TtlExceeded (it); + while (it != Tail () && !TtlExceeded (it)) + { + it++; + } } - if (GetNPackets () == GetMaxPackets () && m_dropPolicy == DROP_OLDEST) + if (QueueBase::GetNPackets () == GetMaxPackets () && m_dropPolicy == DROP_OLDEST) { NS_LOG_DEBUG ("Remove the oldest item in the queue"); DoRemove (Head ()); @@ -188,15 +191,18 @@ WifiMacQueue::PushFront (Ptr item) NS_ASSERT_MSG (GetMode () == QueueBase::QUEUE_MODE_PACKETS, "WifiMacQueues must be in packet mode"); - // if the queue is full, check if the time-to-live of the oldest packet has - // expired. If so, it can be removed so as to make room for the new packet. - if (GetNPackets () == GetMaxPackets ()) + // if the queue is full, remove the first stale packet (if any) encountered + // starting from the head of the queue, in order to make room for the new packet. + if (QueueBase::GetNPackets () == GetMaxPackets ()) { auto it = Head (); - TtlExceeded (it); + while (it != Tail () && !TtlExceeded (it)) + { + it++; + } } - if (GetNPackets () == GetMaxPackets () && m_dropPolicy == DROP_OLDEST) + if (QueueBase::GetNPackets () == GetMaxPackets () && m_dropPolicy == DROP_OLDEST) { NS_LOG_DEBUG ("Remove the oldest item in the queue"); DoRemove (Head ());