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
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 ());
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);
AttributeValue implementation for Boolean.
bool IsNull(void) const
Check for null implementation.
bool IsBroadcast(void) const
void AddHeader(const Header &header)
Add header to this packet.
Hold objects of type Ptr<T>.
void Unblock(Mac48Address dest, uint8_t tid)
Un-block the given destination address and TID (e.g.
void Block(Mac48Address dest, uint8_t tid)
Block the given destination address and TID from sending (e.g.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
uint8_t m_blockAckThreshold
the block ack threshold (use BA mechanism if number of packets in queue reaches this value.
TracedCallback< Time, Time > m_txopTrace
TXOP trace callback.
virtual bool IsTxopStarted(void) const
Return true if a TXOP has started.
Time m_failedAddBaTimeout
timeout after failed BA agreement
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i....
void SetQosFrameExchangeManager(const Ptr< QosFrameExchangeManager > qosFem)
Set the Frame Exchange Manager associated with this QoS STA.
bool IsQosTxop(void) const override
Check for QoS TXOP.
void DoInitialize(void) override
Initialize() implementation.
void SetAccessCategory(AcIndex ac)
Set the access category of this EDCAF.
Time m_startTxop
the start TXOP time
void NotifyChannelAccessed(Time txopDuration) override
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
void NotifyChannelReleased(void) override
Called by the FrameExchangeManager to notify the completion of the transmissions.
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 AddBaResponseTimeout(Mac48Address recipient, uint8_t tid)
Callback when ADDBA response is not received after timeout.
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...
void SetQosQueueSize(Ptr< WifiMacQueueItem > mpdu)
Set the Queue Size subfield of the QoS Control field of the given QoS data frame.
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
Time m_txopDuration
the duration of a TXOP
void DoDispose(void) override
Destructor implementation.
bool HasFramesToTransmit(void) override
Check if the Txop has frames to transmit.
virtual Time GetRemainingTxop(void) const
Return the remaining duration in the current TXOP.
bool IsQosOldPacket(Ptr< const WifiMacQueueItem > mpdu)
Check if the given MPDU is to be considered old according to the current starting sequence number of ...
uint8_t GetBlockAckThreshold(void) const
Return the current threshold for block ack mechanism.
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
AcIndex m_ac
the access category
void SetDroppedMpduCallback(DroppedMpdu callback) override
bool m_useExplicitBarAfterMissedBlockAck
flag whether explicit BlockAckRequest should be sent upon missed BlockAck Response
Time GetFailedAddBaTimeout(void) const
Get the timeout for failed BA agreement.
void CompleteMpduTx(Ptr< WifiMacQueueItem > mpdu)
Stores an MPDU (part of an A-MPDU) in block ack agreement (i.e.
void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager) override
Set WifiRemoteStationsManager this Txop is associated to.
Ptr< const WifiMacQueueItem > PrepareBlockAckRequest(Mac48Address recipient, uint8_t tid) const
bool GetBaAgreementEstablished(Mac48Address address, uint8_t tid) const
void ResetBa(Mac48Address recipient, uint8_t tid)
Reset BA agreement after BA negotiation failed.
void PushFront(Ptr< const Packet > packet, const WifiMacHeader &hdr)
void NotifyInternalCollision(void) override
Notify the Txop that internal collision has occurred.
Time GetAddBaResponseTimeout(void) const
Get the timeout for ADDBA response.
BlockAckType GetBlockAckType(Mac48Address recipient, uint8_t tid) const
uint16_t GetBlockAckInactivityTimeout(void) const
Get the BlockAck inactivity timeout.
Ptr< BlockAckManager > GetBaManager(void)
Get the Block Ack Manager associated with this QosTxop.
bool UseExplicitBarAfterMissedBlockAck(void) const
Return true if an explicit BlockAckRequest is sent after a missed BlockAck.
void SetFailedAddBaTimeout(Time failedAddBaTimeout)
Set the timeout for failed BA agreement.
uint16_t m_blockAckInactivityTimeout
the BlockAck inactivity timeout value (in TUs, i.e.
void GotAddBaResponse(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
Event handler when an ADDBA response is received.
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ack mechanism.
void GotDelBaFrame(const MgtDelBaHeader *delBaHdr, Mac48Address recipient)
Event handler when a DELBA frame is received.
void SetBlockAckInactivityTimeout(uint16_t timeout)
Set the BlockAck inactivity timeout.
BlockAckReqType GetBlockAckReqType(Mac48Address recipient, uint8_t tid) const
AcIndex GetAccessCategory(void) const override
Get the access category.
void SetAddBaResponseTimeout(Time addBaResponseTimeout)
Set the timeout to wait for ADDBA response.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< QosFrameExchangeManager > m_qosFem
the QoS Frame Exchange Manager
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
Ptr< QosBlockedDestinations > m_qosBlockedDestinations
the QoS blocked destinations
Time m_addBaResponseTimeout
timeout for ADDBA response
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...
void ScheduleBar(Ptr< const WifiMacQueueItem > bar, bool skipIfNoDataQueued=false)
Ptr< BlockAckManager > m_baManager
the block ack manager
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now(void)
Return the current simulation virtual time.
bool IsSuccess(void) const
Return whether the status code is success.
Simulation virtual time values and global simulation resolution.
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
bool IsStrictlyNegative(void) const
Exactly equivalent to t < 0.
bool IsZero(void) const
Exactly equivalent to t == 0.
AttributeValue implementation for Time.
Handle packet fragmentation and retransmissions for data and management frames.
void UpdateFailedCw(void)
Update the value of the CW variable to take into account a transmission failure.
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
virtual void NotifyChannelReleased(void)
Called by the FrameExchangeManager to notify the completion of the transmissions.
ChannelAccessStatus m_access
channel access status
virtual void NotifyChannelAccessed(Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted for the given amoun...
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
virtual void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > remoteManager)
Set WifiRemoteStationsManager this Txop is associated to.
void ResetCw(void)
Update the value of the CW variable to take into account a transmission success or a transmission abo...
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
virtual void GenerateBackoff(void)
Generate a new backoff now.
Ptr< WifiRemoteStationManager > m_stationManager
the wifi remote station manager
void DoDispose(void) override
Destructor implementation.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
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...
static const ConstIterator EMPTY
Invalid iterator to signal an empty queue.
ConstIterator PeekFirstAvailable(const Ptr< QosBlockedDestinations > blockedPackets=nullptr, ConstIterator pos=EMPTY) const
Return first available packet for transmission.
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.
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
Implements the IEEE 802.11 MAC trailer.
void ReportDataFailed(Ptr< const WifiMacQueueItem > mpdu)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
void ReportFinalDataFailed(Ptr< const WifiMacQueueItem > mpdu)
Should be invoked after calling ReportDataFailed if NeedRetransmission returns false.
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
bool NeedRetransmission(Ptr< const WifiMacQueueItem > mpdu)
Ptr< WifiMac > GetMac(void) const
Return the WifiMac.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
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...
U * PeekPointer(const Ptr< U > &p)
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
@ WIFI_MAC_DROP_EXPIRED_LIFETIME
@ WIFI_MAC_DROP_REACHED_RETRY_LIMIT
The different BlockAckRequest variants.
The different BlockAck variants.
Information needed to remove an MSDU from the queue.
WifiMacQueue * queue
pointer to the queue where the MSDU is enqueued
ConstIterator it
iterator pointing to the MSDU in the queue