wifi: WifiMacQueue needs to override some QueueBase methods

This commit is contained in:
Stefano Avallone
2017-06-05 11:23:19 +02:00
parent 06b2fe00ed
commit 6dffcbb2fa
4 changed files with 70 additions and 17 deletions

View File

@@ -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;

View File

@@ -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<const Packet> 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<const Packet> packet;

View File

@@ -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);

View File

@@ -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<WifiMacQueueItem>::IsEmpty (void);
template<> uint32_t WifiQueue<WifiMacQueueItem>::GetNPackets (void);
template<> uint32_t WifiQueue<WifiMacQueueItem>::GetNBytes (void);
/// Declare WifiMacQueue as a specialization of template class WifiQueue
typedef WifiQueue<WifiMacQueueItem> WifiMacQueue;