wifi: Avoid calling WifiMacQueue::GetNPackets whenever possible

This commit is contained in:
Stefano Avallone
2017-06-05 23:24:03 +02:00
parent 30c922ba2c
commit 3cab87c732
2 changed files with 19 additions and 13 deletions

View File

@@ -674,7 +674,7 @@ MacLow::StartTransmission (Ptr<const Packet> 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<Item>::size_type i = 0; i != m_txPackets[tid].size (); i++)
{
@@ -3006,7 +3006,7 @@ MacLow::AggregateToAmpdu (Ptr<const Packet> 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 ();

View File

@@ -163,15 +163,18 @@ WifiMacQueue::Enqueue (Ptr<WifiMacQueueItem> 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<WifiMacQueueItem> 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 ());