38#include "ns3/ht-frame-exchange-manager.h"
40#include "ns3/pointer.h"
41#include "ns3/random-variable-stream.h"
42#include "ns3/simulator.h"
44#undef NS_LOG_APPEND_CONTEXT
45#define NS_LOG_APPEND_CONTEXT \
48 std::clog << "[mac=" << m_mac->GetAddress() << "] "; \
66 .AddAttribute(
"UseExplicitBarAfterMissedBlockAck",
67 "Specify whether explicit BlockAckRequest should be sent upon missed "
72 .AddAttribute(
"AddBaResponseTimeout",
73 "The timeout to wait for ADDBA response after the Ack to "
74 "ADDBA request is received.",
81 "The timeout after a failed BA agreement. During this "
82 "timeout, the originator resumes sending packets using normal "
83 "MPDU. After that, BA agreement is reset and the originator "
84 "will retry BA negotiation.",
88 .AddAttribute(
"BlockAckManager",
89 "The BlockAckManager object.",
92 MakePointerChecker<BlockAckManager>())
93 .AddTraceSource(
"TxopTrace",
94 "Trace source for TXOP start and duration times",
96 "ns3::QosTxop::TxopTracedCallback");
112 m_queue->TraceConnectWithoutContext(
135std::unique_ptr<Txop::LinkEntity>
138 return std::make_unique<QosLinkEntity>();
153 uint8_t queueSize =
static_cast<uint8_t
>(std::ceil(
std::min(bufferSize, 64769U) / 256.0));
154 NS_LOG_DEBUG(
"Buffer size=" << bufferSize <<
" Queue Size=" << +queueSize);
203 m_mac->GetChannelAccessManager(linkId)->DisableEdcaFor(
this, link.muEdcaTimer);
211 return (link.muEdcaTimerStartTime.IsStrictlyPositive() &&
212 link.muEdcaTimer.IsStrictlyPositive() &&
299 return Create<const WifiMpdu>(bar, hdr);
320 bool baManagerHasPackets{
m_baManager->GetBar(
false)};
322 m_queue->WipeAllExpiredMpdus();
326 return baManagerHasPackets || queueIsNotEmpty;
332 return m_txMiddle->GetNextSequenceNumberFor(hdr);
338 return m_txMiddle->PeekNextSequenceNumberFor(hdr);
346 if (!mpdu->GetHeader().IsQosData())
352 uint8_t tid = mpdu->GetHeader().GetQosTid();
360 mpdu->GetHeader().GetSequenceNumber()))
373 auto peek = [
this, &linkId, &tid, &recipient, &item]() ->
Ptr<WifiMpdu> {
382 return m_queue->PeekByTidAndAddress(tid, recipient, item);
388 while (item && !item->IsFragment())
390 if ((item->GetHeader().IsRetry() || item->IsInFlight()) &&
IsQosOldPacket(item))
392 NS_LOG_DEBUG(
"Removing an old packet from EDCA queue: " << *item);
401 else if (item->IsInFlight())
406 else if (item->GetHeader().HasData() &&
407 !
m_mac->CanForwardPacketsTo(item->GetHeader().GetAddr1()))
409 NS_LOG_DEBUG(
"Skipping frame that cannot be forwarded: " << *item);
436 NS_LOG_DEBUG(
"Packet beyond the end of the current transmit window");
442 if (!item->IsFragment() && !hdr.
IsRetry())
446 NS_LOG_DEBUG(
"Packet peeked from EDCA queue: " << *item);
461 NS_LOG_FUNCTION(
this << +linkId << *peekedItem << &txParams << availableTime << initialFrame);
463 Mac48Address recipient = peekedItem->GetHeader().GetAddr1();
468 Time actualAvailableTime =
469 (initialFrame && txParams.
GetSize(recipient) == 0 ?
Time::Min() : availableTime);
471 auto qosFem = StaticCast<QosFrameExchangeManager>(
m_mac->GetFrameExchangeManager(linkId));
472 if (!qosFem->TryAddMpdu(peekedItem, txParams, actualAvailableTime))
482 if (peekedItem->GetHeader().IsQosData())
484 uint8_t tid = peekedItem->GetHeader().GetQosTid();
490 IsInWindow(peekedItem->GetHeader().GetSequenceNumber(),
496 !peekedItem->GetHeader().IsRetry() && !peekedItem->IsFragment() &&
497 !peekedItem->IsInFlight())
499 auto htFem = StaticCast<HtFrameExchangeManager>(qosFem);
500 mpdu = htFem->GetMsduAggregator()->GetNextAmsdu(peekedItem, txParams, availableTime);
527 if (!mpdu->IsFragment() && !mpdu->GetHeader().IsRetry() && !mpdu->IsInFlight())
529 uint16_t sequence =
m_txMiddle->GetNextSequenceNumberFor(&mpdu->GetHeader());
530 mpdu->GetHeader().SetSequenceNumber(sequence);
537 return m_baManager->GetBlockAckReqType(recipient, tid);
543 return m_baManager->GetBlockAckType(recipient, tid);
562 return (!link.startTxop.IsZero());
571 if (link.startTxop.IsStrictlyPositive())
584 NS_ASSERT(link.startTxop.IsStrictlyPositive());
586 Time remainingTxop = link.txopDuration;
593 return remainingTxop;
600 uint8_t tid = respHdr->
GetTid();
603 NS_LOG_DEBUG(
"block ack agreement established with " << recipient <<
" tid " << +tid);
611 uint16_t startingSeq =
m_txMiddle->GetNextSeqNumberByTidAndAddress(tid, recipient);
612 auto peekedItem =
m_queue->PeekByTidAndAddress(tid, recipient);
613 if (peekedItem && peekedItem->GetHeader().IsRetry())
615 startingSeq = peekedItem->GetHeader().GetSequenceNumber();
617 m_baManager->UpdateAgreement(respHdr, recipient, startingSeq);
622 m_baManager->NotifyAgreementRejected(recipient, tid);
636 NS_LOG_DEBUG(
"received DELBA frame from=" << recipient);
643 NS_ASSERT(mpdu->GetHeader().IsQosData());
686 m_baManager->NotifyAgreementNoReply(recipient, tid);
705 if (
m_baManager->ExistsAgreement(recipient, tid) &&
void NotifyDiscardedMpdu(Ptr< const WifiMpdu > mpdu)
AttributeValue implementation for Boolean.
auto Bind(BoundArgs... bargs)
Bind a variable number of arguments.
bool IsNull() const
Check for null implementation.
void AddHeader(const Header &header)
Add header to this packet.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
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...
QosTxop(AcIndex ac=AC_UNDEF)
Constructor.
std::unique_ptr< LinkEntity > CreateLinkEntity() const override
Create a LinkEntity object.
uint8_t m_blockAckThreshold
the block ack threshold (use BA mechanism if number of packets in queue reaches this value.
Ptr< BlockAckManager > GetBaManager()
Get the Block Ack Manager associated with this QosTxop.
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 SetMuCwMin(uint16_t cwMin, uint8_t linkId)
Set the minimum contention window size to use while the MU EDCA Timer is running for the given link.
bool UseExplicitBarAfterMissedBlockAck() const
Return true if an explicit BlockAckRequest is sent after a missed BlockAck.
bool EdcaDisabled(uint8_t linkId) const
Return true if the EDCA is disabled (the MU EDCA Timer is running and the MU AIFSN is zero) for the g...
Time GetAddBaResponseTimeout() const
Get the timeout for ADDBA response.
AcIndex GetAccessCategory() const
Get the access category of this object.
void AddBaResponseTimeout(Mac48Address recipient, uint8_t tid)
Callback when ADDBA response is not received after timeout.
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
Ptr< const WifiMpdu > PrepareBlockAckRequest(Mac48Address recipient, uint8_t tid) const
void DoDispose() override
Destructor implementation.
void SetMuCwMax(uint16_t cwMax, uint8_t linkId)
Set the maximum contention window size to use while the MU EDCA Timer is running for the given link.
void ScheduleBar(Ptr< const WifiMpdu > bar, bool skipIfNoDataQueued=false)
bool MuEdcaTimerRunning(uint8_t linkId) const
Return true if the MU EDCA Timer is running for the given link, false otherwise.
void StartMuEdcaTimerNow(uint8_t linkId)
Start the MU EDCA Timer for the given link.
uint8_t GetBlockAckThreshold() const
Return the current threshold for block ack mechanism.
void NotifyChannelReleased(uint8_t linkId) override
Called by the FrameExchangeManager to notify the completion of the transmissions.
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
uint16_t GetBlockAckInactivityTimeout() const
Get the BlockAck inactivity timeout.
TxopTracedCallback m_txopTrace
TXOP trace callback.
virtual Time GetRemainingTxop(uint8_t linkId) const
Return the remaining duration in the current TXOP on the given link.
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
void SetMuAifsn(uint8_t aifsn, uint8_t linkId)
Set the number of slots that make up an AIFS while the MU EDCA Timer is running for the given link.
uint8_t GetQosQueueSize(uint8_t tid, Mac48Address receiver) const
Get the value for the Queue Size subfield of the QoS Control field of a QoS data frame of the given T...
bool GetBaAgreementEstablished(Mac48Address address, uint8_t tid) const
void ResetBa(Mac48Address recipient, uint8_t tid)
Reset BA agreement after BA negotiation failed.
Time GetFailedAddBaTimeout() const
Get the timeout for failed BA agreement.
BlockAckType GetBlockAckType(Mac48Address recipient, uint8_t tid) const
static TypeId GetTypeId()
Get the type ID.
void AssignSequenceNumber(Ptr< WifiMpdu > mpdu) const
Assign a sequence number to the given MPDU, if it is not a fragment and it is not a retransmitted fra...
void SetFailedAddBaTimeout(Time failedAddBaTimeout)
Set the timeout for failed BA agreement.
uint16_t m_blockAckInactivityTimeout
the BlockAck inactivity timeout value (in TUs, i.e.
Ptr< WifiMpdu > PeekNextMpdu(uint8_t linkId, uint8_t tid=8, Mac48Address recipient=Mac48Address::GetBroadcast(), Ptr< WifiMpdu > item=nullptr)
Peek the next frame to transmit on the given link to the given receiver and of the given TID from the...
QosLinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
void GotAddBaResponse(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
Event handler when an ADDBA response is received.
Ptr< WifiMpdu > GetNextMpdu(uint8_t linkId, Ptr< WifiMpdu > peekedItem, WifiTxParameters &txParams, Time availableTime, bool initialFrame)
Prepare the frame to transmit on the given link starting from the MPDU that has been previously peeke...
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ack mechanism.
bool IsQosOldPacket(Ptr< const WifiMpdu > mpdu)
Check if the given MPDU is to be considered old according to the current starting sequence number of ...
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
void CompleteMpduTx(Ptr< WifiMpdu > mpdu)
Stores an MPDU (part of an A-MPDU) in block ack agreement (i.e.
void SetAddBaResponseTimeout(Time addBaResponseTimeout)
Set the timeout to wait for ADDBA response.
bool HasFramesToTransmit(uint8_t linkId) override
Check if the Txop has frames to transmit over the given link.
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
bool IsQosTxop() const override
Check for QoS TXOP.
Ptr< QosBlockedDestinations > m_qosBlockedDestinations
the QoS blocked destinations
Time m_addBaResponseTimeout
timeout for ADDBA response
void NotifyChannelAccessed(uint8_t linkId, Time txopDuration) override
Called by the FrameExchangeManager to notify that channel access has been granted on the given link f...
void SetMuEdcaTimer(Time timer, uint8_t linkId)
Set the MU EDCA Timer for the given link.
Ptr< BlockAckManager > m_baManager
the block ack manager
virtual bool IsTxopStarted(uint8_t linkId) const
Return true if a TXOP has started on the given link.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
bool IsSuccess() const
Return whether the status code is success.
Simulation virtual time values and global simulation resolution.
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
AttributeValue implementation for Time.
Handle packet fragmentation and retransmissions for data and management frames.
Ptr< WifiMac > m_mac
the wifi MAC
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
void DoDispose() override
Destructor implementation.
uint32_t GetMinCw() const
Return the minimum contention window size.
virtual void NotifyChannelReleased(uint8_t linkId)
Called by the FrameExchangeManager to notify the completion of the transmissions.
LinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
virtual void GenerateBackoff(uint8_t linkId)
Generate a new backoff for the given link now.
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
virtual void NotifyChannelAccessed(uint8_t linkId, Time txopDuration=Seconds(0))
Called by the FrameExchangeManager to notify that channel access has been granted on the given link f...
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
uint32_t GetMaxCw() const
Return the maximum contention window size.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This queue implements the timeout procedure described in (Section 9.19.2.6 "Retransmit procedures" pa...
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,...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
std::tuple< WifiContainerQueueType, Mac48Address, uint8_t > WifiContainerQueueId
Tuple (queue type, Address, TID) identifying a container queue.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
static constexpr uint8_t SINGLE_LINK_OP_ID
Link ID for single link operations (helps tracking places where correct link ID is to be used to supp...
@ WIFI_QOSDATA_UNICAST_QUEUE
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
@ WIFI_MAC_DROP_QOS_OLD_PACKET
The different BlockAckRequest variants.
The different BlockAck variants.
Structure holding information specific to a single link.
uint8_t muAifsn
the MU AIFSN
uint32_t muCwMax
the MU CW maximum
Time startTxop
the start TXOP time
uint32_t muCwMin
the MU CW minimum
Time txopDuration
the duration of a TXOP
Time muEdcaTimer
the MU EDCA Timer
uint32_t cwMax
the maximum contention window
uint32_t cwMin
the minimum contention window