25 #include "ns3/pointer.h"    26 #include "ns3/simulator.h"    27 #include "ns3/random-variable-stream.h"    41 #include "ns3/ht-frame-exchange-manager.h"    44 #undef NS_LOG_APPEND_CONTEXT    45 #define NS_LOG_APPEND_CONTEXT if (m_stationManager != 0 && m_stationManager->GetMac () != 0) { std::clog << "[mac=" << m_stationManager->GetMac ()->GetAddress () << "] "; }    58     .SetGroupName (
"Wifi")
    60     .AddAttribute (
"UseExplicitBarAfterMissedBlockAck",
    61                    "Specify whether explicit BlockAckRequest should be sent upon missed BlockAck Response.",
    65     .AddAttribute (
"AddBaResponseTimeout",
    66                    "The timeout to wait for ADDBA response after the Ack to "    67                    "ADDBA request is received.",
    72     .AddAttribute (
"FailedAddBaTimeout",
    73                    "The timeout after a failed BA agreement. During this "    74                    "timeout, the originator resumes sending packets using normal "    75                    "MPDU. After that, BA agreement is reset and the originator "    76                    "will retry BA negotiation.",
    81     .AddAttribute (
"BlockAckManager",
    82                    "The BlockAckManager object.",
    85                    MakePointerChecker<BlockAckManager> ())
    86     .AddTraceSource (
"TxopTrace",
    87                      "Trace source for TXOP start and duration times",
    89                      "ns3::TracedValueCallback::Time")
   132   uint8_t queueSize = 
static_cast<uint8_t
> (std::ceil (
std::min (bufferSize, 64769u) / 256.0));
   133   NS_LOG_DEBUG (
"Buffer size=" << bufferSize << 
" Queue Size=" << +queueSize);
   149   m_baManager->GetRetransmitQueue ()->TraceConnectWithoutContext (
"Expired",
   197   return Create<const WifiMacQueueItem> (bar, hdr);
   203   m_baManager->ScheduleBar (bar, skipIfNoDataQueued);
   226   bool baManagerHasPackets = 
m_baManager->HasPackets ();
   233   bool ret = (baManagerHasPackets || queueIsNotEmpty);
   241   return m_txMiddle->GetNextSequenceNumberFor (hdr);
   247   return m_txMiddle->PeekNextSequenceNumberFor (hdr);
   255   if (!mpdu->GetHeader ().IsQosData ())
   260   Mac48Address recipient = mpdu->GetHeader ().GetAddr1 ();
   261   uint8_t tid = mpdu->GetHeader ().GetQosTid ();
   269                            mpdu->GetHeader ().GetSequenceNumber ()))
   288   auto peek = [
this, &tid, &recipient, &queueIt] () -> WifiMacQueue::ConstIterator
   290       if (tid == 8 && recipient.IsBroadcast ())  
   296           return queueIt.
queue->end ();
   309       queueIt.
it = peek ();
   313           NS_LOG_DEBUG (
"Removing an old packet from BlockAckManager retransmit queue: " << **queueIt.
it);
   315           queueIt.
it = peek ();
   317       if (queueIt.
it != 
m_baManager->GetRetransmitQueue ()->end ())
   319           NS_LOG_DEBUG (
"Packet peeked from BlockAckManager retransmit queue: " << **queueIt.
it);
   326   queueIt.
it = peek ();
   331       uint16_t sequence = 
m_txMiddle->PeekNextSequenceNumberFor (&(*queueIt.
it)->GetHeader ());
   332       if ((*queueIt.
it)->GetHeader ().IsQosData ())
   335           uint8_t tid = (*queueIt.
it)->GetHeader ().GetQosTid ();
   340               NS_LOG_DEBUG (
"Packet beyond the end of the current transmit window");
   347       if (!(*queueIt.
it)->IsFragment () && !hdr.
IsRetry ())
   364   NS_LOG_FUNCTION (
this << *peekedItem << &txParams << availableTime << initialFrame);
   366   Mac48Address recipient = peekedItem->GetHeader ().GetAddr1 ();
   371   Time actualAvailableTime = (initialFrame && txParams.
GetSize (recipient) == 0
   374   if (!
m_qosFem->TryAddMpdu (peekedItem, txParams, actualAvailableTime))
   380   NS_ASSERT_MSG (peekedItem->GetQueueIteratorPairs ().size () == 1,
   381                  "An item in the MAC queue cannot contain an A-MSDU");
   383   NS_ASSERT ((*peekedIt.it)->GetPacket () == peekedItem->GetPacket ());
   393       uint8_t tid = peekedItem->GetHeader ().GetQosTid ();
   397                                        peekedItem->GetHeader ().GetSequenceNumber ()));
   404       NS_LOG_DEBUG (
"Got MPDU from BA manager queue: " << *peekedItem);
   418   if (peekedItem->GetHeader ().IsQosData ())
   420       uint8_t tid = peekedItem->GetHeader ().GetQosTid ();
   426                  || 
IsInWindow (peekedItem->GetHeader ().GetSequenceNumber (),
   432           && !peekedItem->GetHeader ().IsRetry () && !peekedItem->IsFragment ())
   435           mpdu = htFem->GetMsduAggregator ()->GetNextAmsdu (peekedItem, txParams, availableTime, peekedIt);
   474   return m_baManager->GetBlockAckReqType (recipient, tid);
   480   return m_baManager->GetBlockAckType (recipient, tid);
   512           WifiMacQueue::ConstIterator testIt;
   515           if (mpdu->GetHeader ().IsQosData ()
   518               uint8_t tid = mpdu->GetHeader ().GetQosTid ();
   519               testIt = 
m_baManager->GetRetransmitQueue ()->PeekByTidAndAddress (tid, receiver);
   521               if (testIt != 
m_baManager->GetRetransmitQueue ()->end ())
   525                   NS_ASSERT ((*testIt)->GetPacket () == mpdu->GetPacket ());
   526                   m_baManager->GetRetransmitQueue ()->Remove (testIt);
   533               if (mpdu->GetHeader ().IsQosData ())
   535                   uint8_t tid = mpdu->GetHeader ().GetQosTid ();
   536                   testIt = 
m_queue->PeekByTidAndAddress (tid, receiver);
   537                   NS_ASSERT (testIt != 
m_queue->end () && (*testIt)->GetPacket () == mpdu->GetPacket ());
   603   if (remainingTxop.IsStrictlyNegative ())
   608   return remainingTxop;
   623   m_queue->PushFront (Create<WifiMacQueueItem> (packet, hdr));
   634   uint8_t tid = respHdr->
GetTid ();
   637       NS_LOG_DEBUG (
"block ack agreement established with " << recipient << 
" tid " << +tid);
   645       uint16_t startingSeq = 
m_txMiddle->GetNextSeqNumberByTidAndAddress (tid, recipient);
   646       WifiMacQueue::ConstIterator peekedIt = 
m_queue->PeekByTidAndAddress (tid, recipient);
   647       if (peekedIt != 
m_queue->end () && (*peekedIt)->GetHeader ().IsRetry ())
   649           startingSeq = (*peekedIt)->GetHeader ().GetSequenceNumber ();
   651       m_baManager->UpdateAgreement (respHdr, recipient, startingSeq);
   656       m_baManager->NotifyAgreementRejected (recipient, tid);
   669   NS_LOG_DEBUG (
"received DELBA frame from=" << recipient);
   727       m_baManager->NotifyAgreementNoReply (recipient, tid);
   748       m_baManager->NotifyAgreementReset (recipient, tid);
 AcIndex m_ac
the access category 
void ScheduleBar(Ptr< const WifiMacQueueItem > bar, bool skipIfNoDataQueued=false)
bool IsSuccess(void) const
Return whether the status code is success. 
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay. 
Ptr< const WifiMacQueueItem > PeekNextMpdu(uint8_t tid=8, Mac48Address recipient=Mac48Address::GetBroadcast())
Peek the next frame to transmit to the given receiver and of the given TID from the block ack manager...
bool IsBroadcast(void) const
Simulation virtual time values and global simulation resolution. 
Ptr< WifiMac > GetMac(void) const
Return the WifiMac. 
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle 
void ResetBa(Mac48Address recipient, uint8_t tid)
Reset BA agreement after BA negotiation failed. 
  AttributeValue implementation for Boolean. 
void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager) override
Set WifiRemoteStationsManager this Txop is associated to. 
void DoDispose(void) override
Destructor implementation. 
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system. 
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time). 
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Time m_startTxop
the start TXOP time 
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
 Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager 
void ReportFinalDataFailed(Ptr< const WifiMacQueueItem > mpdu)
Should be invoked after calling ReportDataFailed if NeedRetransmission returns false. 
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
U * PeekPointer(const Ptr< U > &p)
Information needed to remove an MSDU from the queue. 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
ConstIterator it
iterator pointing to the MSDU in the queue 
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit. 
Ptr< BlockAckManager > GetBaManager(void)
Get the Block Ack Manager associated with this QosTxop. 
void ReportDataFailed(Ptr< const WifiMacQueueItem > mpdu)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires. 
void SetBlockAckInactivityTimeout(uint16_t timeout)
Set the BlockAck inactivity timeout. 
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet. ...
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0. 
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
void GotDelBaFrame(const MgtDelBaHeader *delBaHdr, Mac48Address recipient)
Event handler when a DELBA frame is received. 
virtual Time GetRemainingTxop(void) const
Return the remaining duration in the current TXOP. 
virtual void GenerateBackoff(void)
Generate a new backoff now. 
void SetAccessCategory(AcIndex ac)
Set the access category of this EDCAF. 
The different BlockAckRequest variants. 
static TypeId GetTypeId(void)
Get the type ID. 
uint8_t GetBlockAckThreshold(void) const
Return the current threshold for block ack mechanism. 
bool UseExplicitBarAfterMissedBlockAck(void) const
Return true if an explicit BlockAckRequest is sent after a missed BlockAck. 
Time m_failedAddBaTimeout
timeout after failed BA agreement 
bool NeedRetransmission(Ptr< const WifiMacQueueItem > mpdu)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source. 
ConstIterator PeekByTidAndAddress(uint8_t tid, Mac48Address dest, ConstIterator pos=EMPTY) const
Search and return, if present in the queue, the first packet having the receiver address equal to des...
bool IsQosTxop(void) const override
Check for QoS TXOP. 
void AssignSequenceNumber(Ptr< WifiMacQueueItem > mpdu) const
Assign a sequence number to the given MPDU, if it is not a fragment and it is not a retransmitted fra...
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure. 
Time GetAddBaResponseTimeout(void) const
Get the timeout for ADDBA response. 
Ptr< QosFrameExchangeManager > m_qosFem
the QoS Frame Exchange Manager 
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item. 
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
 Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
bool IsZero(void) const
Exactly equivalent to t == 0. 
  AttributeValue implementation for Time. 
uint16_t GetBlockAckInactivityTimeout(void) const
Get the BlockAck inactivity timeout. 
void SetQosFrameExchangeManager(const Ptr< QosFrameExchangeManager > qosFem)
Set the Frame Exchange Manager associated with this QoS STA. 
void SetFailedAddBaTimeout(Time failedAddBaTimeout)
Set the timeout for failed BA agreement. 
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled. 
Ptr< BlockAckManager > m_baManager
the block ack manager 
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes. 
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions. ...
void DoInitialize(void) override
Initialize() implementation. 
ChannelAccessStatus m_access
channel access status 
void GotAddBaResponse(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
Event handler when an ADDBA response is received. 
static const ConstIterator EMPTY
Invalid iterator to signal an empty queue. 
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header. 
void PushFront(Ptr< const Packet > packet, const WifiMacHeader &hdr)
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i...
void SetAddBaResponseTimeout(Time addBaResponseTimeout)
Set the timeout to wait for ADDBA response. 
Ptr< const Packet > GetPacket(void) const
Get the packet stored in this item. 
bool IsFragment(void) const
Return true if this item contains an MSDU fragment, false otherwise. 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
Time m_txopDuration
the duration of a TXOP 
BlockAckType GetBlockAckType(Mac48Address recipient, uint8_t tid) const
Hold objects of type Ptr<T>. 
void CompleteMpduTx(Ptr< WifiMacQueueItem > mpdu)
Stores an MPDU (part of an A-MPDU) in block ack agreement (i.e. 
Ptr< WifiMacQueue > m_queue
the wifi MAC queue 
void NotifyChannelAccessed(Time txopDuration) override
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
void DoDispose(void) override
Destructor implementation. 
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
 Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void SetDroppedMpduCallback(DroppedMpdu callback) override
static Time Now(void)
Return the current simulation virtual time. 
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback 
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ack mechanism. 
uint8_t m_blockAckThreshold
the block ack threshold (use BA mechanism if number of packets in queue reaches this value...
AcIndex GetAccessCategory(void) const override
Get the access category. 
virtual void NotifyChannelAccessed(Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver. 
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
BlockAckReqType GetBlockAckReqType(Mac48Address recipient, uint8_t tid) const
bool IsQosOldPacket(Ptr< const WifiMacQueueItem > mpdu)
Check if the given MPDU is to be considered old according to the current starting sequence number of ...
bool HasFramesToTransmit(void) override
Check if the Txop has frames to transmit. 
WifiMacQueue * queue
pointer to the queue where the MSDU is enqueued 
void SetQosQueueSize(Ptr< WifiMacQueueItem > mpdu)
Set the Queue Size subfield of the QoS Control field of the given QoS data frame. ...
The different BlockAck variants. 
void NotifyChannelReleased(void) override
Called by the FrameExchangeManager to notify the completion of the transmissions. ...
void Unblock(Mac48Address dest, uint8_t tid)
Un-block the given destination address and TID (e.g. 
bool GetBaAgreementEstablished(Mac48Address address, uint8_t tid) const
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG. 
bool m_useExplicitBarAfterMissedBlockAck
flag whether explicit BlockAckRequest should be sent upon missed BlockAck Response ...
Time Seconds(double value)
Construct a Time in the indicated unit. 
Ptr< const WifiMacQueueItem > PrepareBlockAckRequest(Mac48Address recipient, uint8_t tid) const
Ptr< const AttributeChecker > MakeBooleanChecker(void)
  
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism...
Ptr< QosBlockedDestinations > m_qosBlockedDestinations
the QoS blocked destinations 
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
void Block(Mac48Address dest, uint8_t tid)
Block the given destination address and TID from sending (e.g. 
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range. 
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to. 
TracedCallback< Time, Time > m_txopTrace
TXOP trace callback. 
ConstIterator PeekFirstAvailable(const Ptr< QosBlockedDestinations > blockedPackets=nullptr, ConstIterator pos=EMPTY) const
Return first available packet for transmission. 
Ptr< WifiMacQueueItem > GetNextMpdu(Ptr< const WifiMacQueueItem > peekedItem, WifiTxParameters &txParams, Time availableTime, bool initialFrame, WifiMacQueueItem::QueueIteratorPair &queueIt)
Prepare the frame to transmit starting from the MPDU that has been previously peeked by calling PeekN...
Time GetFailedAddBaTimeout(void) const
Get the timeout for failed BA agreement. 
uint16_t m_blockAckInactivityTimeout
the BlockAck inactivity timeout value (in TUs, i.e. 
bool IsNull(void) const
Check for null implementation. 
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager 
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
a unique identifier for an interface. 
TypeId SetParent(TypeId tid)
Set the parent TypeId. 
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void AddBaResponseTimeout(Mac48Address recipient, uint8_t tid)
Callback when ADDBA response is not received after timeout. 
void AddHeader(const Header &header)
Add header to this packet. 
Time m_addBaResponseTimeout
timeout for ADDBA response 
Implements the IEEE 802.11 MAC trailer. 
virtual bool IsTxopStarted(void) const
Return true if a TXOP has started. 
void NotifyInternalCollision(void) override
Notify the Txop that internal collision has occurred. 
Handle packet fragmentation and retransmissions for data and management frames.