20#include "ns3/he-frame-exchange-manager.h"
34 TypeId(
"ns3::WifiDefaultAckManager")
38 .AddAttribute(
"UseExplicitBar",
39 "Specify whether to send Block Ack Requests (if true) or use"
40 " Implicit Block Ack Request ack policy (if false).",
44 .AddAttribute(
"BaThreshold",
45 "Immediate acknowledgment is requested upon transmission of a frame "
46 "whose sequence number is distant at least BaThreshold multiplied "
47 "by the transmit window size from the starting sequence number of "
48 "the transmit window. Set to zero to request a response for every "
54 "DlMuAckSequenceType",
55 "Type of the acknowledgment sequence for DL MU PPDUs.",
59 "DL_MU_BAR_BA_SEQUENCE",
63 "DL_MU_AGGREGATE_TF"))
64 .AddAttribute(
"MaxBlockAckMcs",
65 "The MCS used to send a BlockAck in a TB PPDU is the minimum between "
66 "the MCS used for the PSDU sent in the preceding DL MU PPDU and the "
67 "value of this attribute.",
90 auto receiver = mpdu->GetHeader().GetAddr1();
91 auto origReceiver = mpdu->GetOriginal()->GetHeader().GetAddr1();
93 uint8_t tid = mpdu->GetHeader().GetQosTid();
96 "An established Block Ack agreement is required");
98 uint16_t startingSeq = edca->GetBaStartingSequence(origReceiver, tid);
99 uint16_t maxDistFromStartingSeq = 0;
101 const auto* psduInfo = txParams.
GetPsduInfo(receiver);
102 NS_ASSERT_MSG(psduInfo && psduInfo->seqNumbers.contains(tid),
103 "There must be at least an MPDU with tid " << +tid);
105 const auto& seqNumbers = psduInfo->seqNumbers.at(tid);
106 NS_ASSERT_MSG(seqNumbers.contains(mpdu->GetHeader().GetSequenceNumber()),
107 "The sequence number of the given MPDU is not included in the TX parameters");
109 for (
const auto& seqNumber : seqNumbers)
112 "QoS data frame SeqN=" << seqNumber <<
" is too old");
114 uint16_t currDistToStartingSeq =
117 if (currDistToStartingSeq > maxDistFromStartingSeq)
119 maxDistFromStartingSeq = currDistToStartingSeq;
124 return maxDistFromStartingSeq;
133 uint8_t tid = mpdu->GetHeader().GetQosTid();
134 auto receiver = mpdu->GetHeader().GetAddr1();
135 auto origReceiver = mpdu->GetOriginal()->GetHeader().GetAddr1();
156 edca->GetWifiMacQueue()->GetNPackets(queueId) -
157 edca->GetBaManager()->GetNBufferedPackets(origReceiver, tid) - seqNumbers.size() <
164 if (
m_mac->GetBaAgreementEstablishedAsOriginator(origReceiver, tid)
166 .AllAckedMpdusInTxWindow(seqNumbers))
173 if (edca->GetTxopLimit(
m_linkId).IsStrictlyPositive() &&
186 NS_ASSERT(mpdu->GetHeader().IsQosData());
187 auto tid = mpdu->GetHeader().GetQosTid();
189 auto queue =
m_mac->GetTxopQueue(mpdu->GetQueueAc());
190 auto origReceiver = mpdu->GetOriginal()->GetHeader().GetAddr1();
191 auto agreement =
m_mac->GetBaAgreementEstablishedAsOriginator(origReceiver, tid);
193 auto mpduDist = agreement->get().GetDistance(mpdu->GetHeader().GetSequenceNumber());
195 Ptr<WifiMpdu> item = queue->PeekByTidAndAddress(tid, origReceiver);
199 auto itemDist = agreement->get().GetDistance(item->GetHeader().GetSequenceNumber());
200 if (itemDist == mpduDist)
202 NS_LOG_DEBUG(
"No previous MPDU in-flight on the same link");
206 "While searching for given MPDU ("
207 << *mpdu <<
"), found first another one (" << *item
208 <<
") with higher sequence number");
209 if (
auto linkIds = item->GetInFlightLinkIds(); linkIds.contains(
m_linkId))
214 item = queue->PeekByTidAndAddress(tid, origReceiver, item);
220std::unique_ptr<WifiAcknowledgment>
251 std::unique_ptr<WifiAcknowledgment> acknowledgment;
260 acknowledgment = std::make_unique<WifiNoAck>();
263 return acknowledgment;
272 auto acknowledgment = std::make_unique<WifiAckAfterTbPpdu>();
277 return acknowledgment;
305 "Unicast frames only can be aggregated if GCR is not used");
307 isGcr && apMac->GetGcrManager()->GetRetransmissionPolicyFor(hdr) ==
310 NS_LOG_DEBUG(
"Request to schedule a GCR Block Ack Request");
311 const auto recipient =
312 apMac->GetGcrManager()->GetIndividuallyAddressedRecipient(receiver);
313 auto acknowledgment = std::make_unique<WifiBarBlockAck>();
314 acknowledgment->blockAckReqTxVector =
316 acknowledgment->blockAckTxVector = acknowledgment->blockAckReqTxVector;
320 return acknowledgment;
322 auto acknowledgment = std::make_unique<WifiNoAck>();
327 return acknowledgment;
331 !
m_mac->GetBaAgreementEstablishedAsOriginator(receiver, hdr.
GetQosTid())) &&
335 "Non-QoS data frame or Block Ack agreement not established, request Normal Ack");
336 auto acknowledgment = std::make_unique<WifiNormalAck>();
337 acknowledgment->ackTxVector =
343 return acknowledgment;
350 NS_LOG_DEBUG(
"A response is not needed: no ack for now, use Block Ack policy");
358 auto acknowledgment = std::make_unique<WifiNoAck>();
363 return acknowledgment;
367 uint8_t tid =
GetTid(mpdu->GetPacket(), hdr);
371 NS_LOG_DEBUG(
"Sending a single MPDU, no previous frame to ack: request Normal Ack");
372 auto acknowledgment = std::make_unique<WifiNormalAck>();
373 acknowledgment->ackTxVector =
376 return acknowledgment;
385 NS_LOG_DEBUG(
"Request to schedule a Block Ack Request");
387 auto acknowledgment = std::make_unique<WifiBarBlockAck>();
388 acknowledgment->blockAckReqTxVector =
390 acknowledgment->blockAckTxVector = acknowledgment->blockAckReqTxVector;
391 acknowledgment->barType =
m_mac->GetBarTypeAsOriginator(receiver, tid);
392 acknowledgment->baType =
m_mac->GetBaTypeAsOriginator(receiver, tid);
394 return acknowledgment;
400 mpdu->GetPacket()->PeekHeader(baReqHdr);
401 if (baReqHdr.
IsGcr())
403 NS_LOG_DEBUG(
"GCR Block Ack Req, request GCR Block Ack");
404 auto acknowledgment = std::make_unique<WifiBlockAck>();
405 acknowledgment->blockAckTxVector =
409 return acknowledgment;
414 "A-MPDU using Implicit Block Ack Request policy or BlockAckReq, request Block Ack");
415 auto acknowledgment = std::make_unique<WifiBlockAck>();
416 acknowledgment->blockAckTxVector =
418 acknowledgment->baType =
m_mac->GetBaTypeAsOriginator(receiver, tid);
420 return acknowledgment;
423std::unique_ptr<WifiAcknowledgment>
432std::unique_ptr<WifiAcknowledgment>
444 "QoS data frames only can be aggregated when transmitting a "
445 "DL MU PPDU acknowledged via a sequence of BAR and BA frames");
489 m_mac->GetBaTypeAsOriginator(receiver, tid)});
490 return std::unique_ptr<WifiDlMuBarBaSequence>(acknowledgment);
516 <<
" to the list of stations receiving a BlockAckReq");
521 m_mac->GetBarTypeAsOriginator(receiver, tid),
523 m_mac->GetBaTypeAsOriginator(receiver, tid)});
526 return std::unique_ptr<WifiDlMuBarBaSequence>(acknowledgment);
543 <<
" as the station that will immediately reply with a Normal Ack");
550 return std::unique_ptr<WifiDlMuBarBaSequence>(acknowledgment);
553std::unique_ptr<WifiAcknowledgment>
578 uint16_t staId = apMac->GetAssociationId(receiver,
m_linkId);
581 "QoS data frames only can be aggregated when transmitting a "
582 "DL MU PPDU acknowledged via a MU-BAR sent as SU frame");
614 <<
" to the list of stations that will be solicited by the MU-BAR");
619 mpdu->GetOriginal()->GetHeader().GetAddr1(),
622 m_mac->GetBaTypeAsOriginator(receiver, tid)});
624 acknowledgment->
barTypes.push_back(
m_mac->GetBarTypeAsOriginator(receiver, tid));
629 return std::unique_ptr<WifiDlMuTfMuBar>(acknowledgment);
635 "QoS data frames only can be aggregated when transmitting a DL MU PPDU");
641std::unique_ptr<WifiAcknowledgment>
666 uint16_t staId = apMac->GetAssociationId(receiver,
m_linkId);
669 "QoS data frames only can be aggregated when transmitting a "
670 "DL MU PPDU acknowledged via a sequence of BAR and BA frames");
701 <<
" to the list of stations that will reply with a Block Ack");
707 edca->GetBaManager()->GetBlockAckReqHeader(
708 mpdu->GetOriginal()->GetHeader().GetAddr1(),
711 m_mac->GetBaTypeAsOriginator(receiver, tid)});
714 return std::unique_ptr<WifiDlMuAggregateTf>(acknowledgment);
721 "QoS data and MU-BAR Trigger frames only can be aggregated when transmitting a DL MU PPDU");
727std::unique_ptr<WifiAcknowledgment>
732 NS_ASSERT(mpdu->GetHeader().IsTrigger());
741 mpdu->GetPacket()->PeekHeader(trigger);
746 auto acknowledgment = std::make_unique<WifiUlMuMultiStaBa>();
748 for (
const auto& userInfo : trigger)
750 uint16_t aid12 = userInfo.GetAid12();
757 NS_ABORT_MSG_IF(aid12 == 0 || aid12 > 2007,
"Allocation of RA-RUs is not supported");
759 const auto it = apMac->GetStaList(
m_linkId).find(aid12);
761 const auto staAddress = it->second;
765 while (tid < 8 && !m_mac->GetBaAgreementEstablishedAsRecipient(staAddress, tid))
770 "No Block Ack agreement established with originator " << staAddress);
772 std::size_t index = acknowledgment->baType.m_bitmapLen.size();
773 acknowledgment->stationsReceivingMultiStaBa.emplace(std::make_pair(staAddress, tid),
778 acknowledgment->baType.m_bitmapLen.push_back(
779 m_mac->GetBaTypeAsRecipient(staAddress, tid).m_bitmapLen.at(0));
782 uint16_t staId = trigger.
begin()->GetAid12();
785 apMac->GetStaList(
m_linkId).find(staId)->second,
786 acknowledgment->tbPpduTxVector);
787 return acknowledgment;
789 else if (trigger.
IsBsrp())
791 return std::make_unique<WifiNoAck>();
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold variables of type enum.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
WifiAckManager is an abstract base class.
uint8_t m_linkId
ID of the link this Acknowledgment Manager is operating on.
Ptr< WifiMac > m_mac
MAC which is using this Acknowledgment Manager.
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager() const
WifiDefaultAckManager is the default ack manager.
bool IsResponseNeeded(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams) const
Determine whether the (A-)MPDU containing the given MPDU and the MPDUs (if any) included in the given...
static TypeId GetTypeId()
Get the type ID.
virtual std::unique_ptr< WifiAcknowledgment > GetAckInfoIfBarBaSequence(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams)
Compute the information about the acknowledgment of the current multi-user frame (as described by the...
bool m_useExplicitBar
true for sending BARs, false for using Implicit BAR policy
uint8_t m_maxMcsForBlockAckInTbPpdu
Max MCS used to send a BlockAck in a TB PPDU.
double m_baThreshold
Threshold to determine when a BlockAck must be requested.
virtual std::unique_ptr< WifiAcknowledgment > GetAckInfoIfTfMuBar(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams)
Compute the information about the acknowledgment of the current multi-user frame (as described by the...
~WifiDefaultAckManager() override
WifiAcknowledgment::Method m_dlMuAckType
Type of the ack sequence for DL MU PPDUs.
std::unique_ptr< WifiAcknowledgment > TryAggregateMsdu(Ptr< const WifiMpdu > msdu, const WifiTxParameters &txParams) override
Determine the acknowledgment method to use if the given MSDU is aggregated to the current frame.
uint16_t GetMaxDistFromStartingSeq(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams) const
Get the maximum distance between the starting sequence number of the Block Ack agreement which the gi...
bool ExistInflightOnSameLink(Ptr< const WifiMpdu > mpdu) const
std::unique_ptr< WifiAcknowledgment > TryAddMpdu(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams) override
Determine the acknowledgment method to use if the given MPDU is added to the current frame.
virtual std::unique_ptr< WifiAcknowledgment > GetAckInfoIfAggregatedMuBar(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams)
Compute the information about the acknowledgment of the current multi-user frame (as described by the...
virtual std::unique_ptr< WifiAcknowledgment > TryUlMuTransmission(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams)
Calculate the acknowledgment method for the TB PPDUs solicited by the given Trigger Frame.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
std::unique_ptr< WifiProtection > m_protection
protection method
std::unique_ptr< WifiAcknowledgment > m_acknowledgment
acknowledgment method
const PsduInfo * GetPsduInfo(Mac48Address receiver) const
Get a pointer to the information about the PSDU addressed to the given receiver, if present,...
bool LastAddedIsFirstMpdu(Mac48Address receiver) const
Check if the last added MPDU is the first MPDU for the given receiver.
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetGuardInterval(Time guardInterval)
Sets the guard interval duration (in nanoseconds)
void SetHeMuUserInfo(uint16_t staId, HeMuUserInfo userInfo)
Set the HE MU user-specific transmission information for the given STA-ID.
WifiPreamble GetPreambleType() const
HeMuUserInfo GetHeMuUserInfo(uint16_t staId) const
Get the HE MU user-specific transmission information for the given STA-ID.
void SetChannelWidth(MHz_u channelWidth)
Sets the selected channelWidth.
MHz_u GetChannelWidth() const
Time GetGuardInterval() const
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#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...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#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_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
This function is useful to get traffic id of different packet types.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeUintegerChecker()
std:: tuple< WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional< uint8_t > > WifiContainerQueueId
Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
bool IsEht(WifiPreamble preamble)
Return true if a preamble corresponds to an EHT transmission.
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
static constexpr uint16_t NO_USER_STA_ID
STA_ID for a RU that is intended for no user (Section 26.11.1 802.11ax-2021)
uint32_t GetMuBarSize(std::list< BlockAckReqType > types)
Return the total MU-BAR size (including FCS trailer).
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
bool IsGcr(Ptr< WifiMac > mac, const WifiMacHeader &hdr)
Return whether a given packet is transmitted using the GCR service.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
void SetQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy)
Set the QoS Ack policy to use for the MPDUs addressed to the given receiver and belonging to the give...
information related to a BlockAck frame sent by a station
WifiDlMuAggregateTf specifies that a DL MU PPDU made of PSDUs including each a MU-BAR Trigger Frame i...
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame.
information related to an Ack frame sent by a station
information related to a BlockAck frame sent by a station
information related to a BlockAckReq frame sent to a station
WifiDlMuBarBaSequence specifies that a DL MU PPDU is acknowledged through a sequence of BlockAckReq a...
std::map< Mac48Address, BlockAckReqInfo > stationsSendBlockAckReqTo
Set of stations receiving a BlockAckReq frame and replying with a BlockAck frame.
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame (no more than one)
std::map< Mac48Address, AckInfo > stationsReplyingWithNormalAck
Set of stations replying with an Ack frame (no more than one)
information related to a BlockAck frame sent by a station
WifiDlMuTfMuBar specifies that a DL MU PPDU is followed after a SIFS duration by a MU-BAR Trigger Fra...
std::list< BlockAckReqType > barTypes
BAR types.
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame.
WifiTxVector muBarTxVector
TXVECTOR used to transmit the MU-BAR Trigger Frame.
std::map< uint8_t, std::set< uint16_t > > seqNumbers
set of the sequence numbers of the MPDUs added for each TID