A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-default-ack-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
10
11#include "ap-wifi-mac.h"
12#include "ctrl-headers.h"
13#include "gcr-manager.h"
14#include "qos-utils.h"
15#include "wifi-mac-queue.h"
16#include "wifi-mpdu.h"
17#include "wifi-protection.h"
18#include "wifi-tx-parameters.h"
19
20#include "ns3/he-frame-exchange-manager.h"
21#include "ns3/log.h"
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("WifiDefaultAckManager");
27
29
32{
33 static TypeId tid =
34 TypeId("ns3::WifiDefaultAckManager")
36 .SetGroupName("Wifi")
37 .AddConstructor<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).",
41 BooleanValue(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 "
49 "transmitted frame.",
50 DoubleValue(0.0),
53 .AddAttribute(
54 "DlMuAckSequenceType",
55 "Type of the acknowledgment sequence for DL MU PPDUs.",
59 "DL_MU_BAR_BA_SEQUENCE",
61 "DL_MU_TF_MU_BAR",
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.",
71 return tid;
72}
73
78
83
84uint16_t
86 const WifiTxParameters& txParams) const
87{
88 NS_LOG_FUNCTION(this << *mpdu << &txParams);
89
90 auto receiver = mpdu->GetHeader().GetAddr1();
91 auto origReceiver = mpdu->GetOriginal()->GetHeader().GetAddr1();
92
93 uint8_t tid = mpdu->GetHeader().GetQosTid();
94 Ptr<QosTxop> edca = m_mac->GetQosTxop(tid);
95 NS_ABORT_MSG_IF(!m_mac->GetBaAgreementEstablishedAsOriginator(origReceiver, tid),
96 "An established Block Ack agreement is required");
97
98 uint16_t startingSeq = edca->GetBaStartingSequence(origReceiver, tid);
99 uint16_t maxDistFromStartingSeq = 0;
100
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);
104
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");
108
109 for (const auto& seqNumber : seqNumbers)
110 {
111 NS_ASSERT_MSG(!QosUtilsIsOldPacket(startingSeq, seqNumber),
112 "QoS data frame SeqN=" << seqNumber << " is too old");
113
114 uint16_t currDistToStartingSeq =
115 (seqNumber - startingSeq + SEQNO_SPACE_SIZE) % SEQNO_SPACE_SIZE;
116
117 if (currDistToStartingSeq > maxDistFromStartingSeq)
118 {
119 maxDistFromStartingSeq = currDistToStartingSeq;
120 }
121 }
122
123 NS_LOG_DEBUG("Returning " << maxDistFromStartingSeq);
124 return maxDistFromStartingSeq;
125}
126
127bool
129 const WifiTxParameters& txParams) const
130{
131 NS_LOG_FUNCTION(this << *mpdu << &txParams);
132
133 uint8_t tid = mpdu->GetHeader().GetQosTid();
134 auto receiver = mpdu->GetHeader().GetAddr1();
135 auto origReceiver = mpdu->GetOriginal()->GetHeader().GetAddr1();
136 Ptr<QosTxop> edca = m_mac->GetQosTxop(tid);
137 const auto& seqNumbers = txParams.GetPsduInfo(receiver)->seqNumbers.at(tid);
138
139 // An immediate response (Ack or Block Ack) is needed if any of the following holds:
140 // * the BA threshold is set to zero
141 if (m_baThreshold == 0.0)
142 {
143 return true;
144 }
145 // * the maximum distance between the sequence number of an MPDU to transmit
146 // and the starting sequence number of the transmit window is greater than
147 // or equal to the window size multiplied by the BaThreshold
148 if (GetMaxDistFromStartingSeq(mpdu, txParams) >=
149 m_baThreshold * edca->GetBaBufferSize(origReceiver, tid))
150 {
151 return true;
152 }
153 // * no other frame belonging to this BA agreement is queued (because, in such
154 // a case, a Block Ack is not going to be requested anytime soon)
155 if (const auto queueId = MakeWifiUnicastQueueId(WIFI_QOSDATA_QUEUE, origReceiver, tid);
156 edca->GetWifiMacQueue()->GetNPackets(queueId) -
157 edca->GetBaManager()->GetNBufferedPackets(origReceiver, tid) - seqNumbers.size() <
158 1)
159 {
160 return true;
161 }
162 // * the block ack TX window cannot advance because all the MPDUs in the TX window other than
163 // those being transmitted have been already acknowledged
164 if (m_mac->GetBaAgreementEstablishedAsOriginator(origReceiver, tid)
165 ->get()
166 .AllAckedMpdusInTxWindow(seqNumbers))
167 {
168 return true;
169 }
170
171 // * this is the initial frame of a transmission opportunity and it is not
172 // protected by RTS/CTS (see Annex G.3 of IEEE 802.11-2016)
173 if (edca->GetTxopLimit(m_linkId).IsStrictlyPositive() &&
174 edca->GetRemainingTxop(m_linkId) == edca->GetTxopLimit(m_linkId) &&
175 !(txParams.m_protection && txParams.m_protection->method == WifiProtection::RTS_CTS))
176 {
177 return true;
178 }
179
180 return false;
181}
182
183bool
185{
186 NS_ASSERT(mpdu->GetHeader().IsQosData());
187 auto tid = mpdu->GetHeader().GetQosTid();
188 NS_ASSERT(mpdu->IsQueued());
189 auto queue = m_mac->GetTxopQueue(mpdu->GetQueueAc());
190 auto origReceiver = mpdu->GetOriginal()->GetHeader().GetAddr1();
191 auto agreement = m_mac->GetBaAgreementEstablishedAsOriginator(origReceiver, tid);
192 NS_ASSERT(agreement);
193 auto mpduDist = agreement->get().GetDistance(mpdu->GetHeader().GetSequenceNumber());
194 const auto src = m_mac->GetFrameExchangeManager(m_linkId)->GetAddress();
195
196 Ptr<WifiMpdu> item = queue->PeekByTidAndAddress(tid, origReceiver, src);
197
198 while (item)
199 {
200 auto itemDist = agreement->get().GetDistance(item->GetHeader().GetSequenceNumber());
201 if (itemDist == mpduDist)
202 {
203 NS_LOG_DEBUG("No previous MPDU in-flight on the same link");
204 return false;
205 }
206 NS_ABORT_MSG_IF(itemDist > mpduDist,
207 "While searching for given MPDU ("
208 << *mpdu << "), found first another one (" << *item
209 << ") with higher sequence number");
210 if (auto linkIds = item->GetInFlightLinkIds(); linkIds.contains(m_linkId))
211 {
212 NS_LOG_DEBUG("Found MPDU inflight on the same link");
213 return true;
214 }
215 item = queue->PeekByTidAndAddress(tid, origReceiver, src, item);
216 }
217 NS_ABORT_MSG("Should not get here");
218 return false;
219}
220
221std::unique_ptr<WifiAcknowledgment>
223{
224 NS_LOG_FUNCTION(this << *mpdu << &txParams);
225
226 const auto& hdr = mpdu->GetHeader();
227
228 if (hdr.IsPsPoll())
229 {
230 NS_ASSERT(!txParams.m_acknowledgment);
231 return std::make_unique<WifiNoAck>();
232 }
233
234 // If the TXVECTOR indicates a DL MU PPDU, call a separate method
235 if (txParams.m_txVector.IsDlMu())
236 {
237 switch (m_dlMuAckType)
238 {
240 return GetAckInfoIfBarBaSequence(mpdu, txParams);
242 return GetAckInfoIfTfMuBar(mpdu, txParams);
244 return GetAckInfoIfAggregatedMuBar(mpdu, txParams);
245 default:
246 NS_ABORT_MSG("Unknown DL acknowledgment method");
247 return nullptr;
248 }
249 }
250
251 Mac48Address receiver = hdr.GetAddr1();
252
253 // Acknowledgment for TB PPDUs
254 if (txParams.m_txVector.IsUlMu())
255 {
256 if (hdr.IsQosData() && !hdr.HasData())
257 {
258 // QoS Null frame
259 std::unique_ptr<WifiAcknowledgment> acknowledgment;
260
261 if (txParams.m_acknowledgment)
262 {
264 acknowledgment = txParams.m_acknowledgment->Copy();
265 }
266 else
267 {
268 acknowledgment = std::make_unique<WifiNoAck>();
269 }
270 acknowledgment->SetQosAckPolicy(receiver, hdr.GetQosTid(), WifiMacHeader::NO_ACK);
271 return acknowledgment;
272 }
273
274 if (txParams.m_acknowledgment)
275 {
277 return nullptr;
278 }
279
280 auto acknowledgment = std::make_unique<WifiAckAfterTbPpdu>();
281 if (hdr.IsQosData())
282 {
283 acknowledgment->SetQosAckPolicy(receiver, hdr.GetQosTid(), WifiMacHeader::NORMAL_ACK);
284 }
285 return acknowledgment;
286 }
287
288 // if this is a Trigger Frame, call a separate method
289 if (hdr.IsTrigger())
290 {
291 return TryUlMuTransmission(mpdu, txParams);
292 }
293
294 // if the current acknowledgment method (if any) is already BLOCK_ACK, it will not
295 // change by adding an MPDU
296 if (txParams.m_acknowledgment &&
298 {
299 return nullptr;
300 }
301
302 if (receiver.IsGroup())
303 {
304 // if the current acknowledgment method (if any) is already BAR_BLOCK_ACK, it will not
305 // change by adding an MPDU
306 if (txParams.m_acknowledgment &&
308 {
309 return nullptr;
310 }
311 const auto isGcr = IsGcr(m_mac, hdr);
312 NS_ABORT_MSG_IF(!isGcr && !txParams.LastAddedIsFirstMpdu(receiver),
313 "Unicast frames only can be aggregated if GCR is not used");
314 if (auto apMac = DynamicCast<ApWifiMac>(m_mac);
315 isGcr && apMac->GetGcrManager()->GetRetransmissionPolicyFor(hdr) ==
317 {
318 NS_LOG_DEBUG("Request to schedule a GCR Block Ack Request");
319 const auto recipient =
320 apMac->GetGcrManager()->GetIndividuallyAddressedRecipient(receiver);
321 auto acknowledgment = std::make_unique<WifiBarBlockAck>();
322 acknowledgment->blockAckReqTxVector =
323 GetWifiRemoteStationManager()->GetBlockAckReqTxVector(recipient,
324 txParams.m_txVector);
325 acknowledgment->blockAckTxVector = acknowledgment->blockAckReqTxVector;
326 acknowledgment->barType = BlockAckReqType::GCR;
327 acknowledgment->baType = BlockAckType::GCR;
328 acknowledgment->SetQosAckPolicy(receiver, hdr.GetQosTid(), WifiMacHeader::BLOCK_ACK);
329 return acknowledgment;
330 }
331 auto acknowledgment = std::make_unique<WifiNoAck>();
332 if (hdr.IsQosData())
333 {
334 acknowledgment->SetQosAckPolicy(receiver, hdr.GetQosTid(), WifiMacHeader::NO_ACK);
335 }
336 return acknowledgment;
337 }
338
339 if ((!hdr.IsQosData() ||
340 !m_mac->GetBaAgreementEstablishedAsOriginator(receiver, hdr.GetQosTid())) &&
341 !hdr.IsBlockAckReq())
342 {
344 "Non-QoS data frame or Block Ack agreement not established, request Normal Ack");
345 auto acknowledgment = std::make_unique<WifiNormalAck>();
346 acknowledgment->ackTxVector =
347 GetWifiRemoteStationManager()->GetAckTxVector(receiver, txParams.m_txVector);
348 if (hdr.IsQosData())
349 {
350 acknowledgment->SetQosAckPolicy(receiver, hdr.GetQosTid(), WifiMacHeader::NORMAL_ACK);
351 }
352 return acknowledgment;
353 }
354
355 // we get here if mpdu is a QoS data frame related to an established Block Ack agreement
356 // or mpdu is a BlockAckReq frame
357 if (!hdr.IsBlockAckReq() && !IsResponseNeeded(mpdu, txParams))
358 {
359 NS_LOG_DEBUG("A response is not needed: no ack for now, use Block Ack policy");
360 if (txParams.m_acknowledgment &&
361 txParams.m_acknowledgment->method == WifiAcknowledgment::NONE)
362 {
363 // no change if the ack method is already NONE
364 return nullptr;
365 }
366
367 auto acknowledgment = std::make_unique<WifiNoAck>();
368 if (hdr.IsQosData())
369 {
370 acknowledgment->SetQosAckPolicy(receiver, hdr.GetQosTid(), WifiMacHeader::BLOCK_ACK);
371 }
372 return acknowledgment;
373 }
374
375 // we get here if a response is needed
376 uint8_t tid = GetTid(mpdu->GetPacket(), hdr);
377 if (!hdr.IsBlockAckReq() && txParams.LastAddedIsFirstMpdu(receiver) &&
379 {
380 NS_LOG_DEBUG("Sending a single MPDU, no previous frame to ack: request Normal Ack");
381 auto acknowledgment = std::make_unique<WifiNormalAck>();
382 acknowledgment->ackTxVector =
383 GetWifiRemoteStationManager()->GetAckTxVector(receiver, txParams.m_txVector);
384 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::NORMAL_ACK);
385 return acknowledgment;
386 }
387
388 // we get here if multiple MPDUs are being/have been sent
389 if (!hdr.IsBlockAckReq() && (txParams.LastAddedIsFirstMpdu(receiver) || m_useExplicitBar))
390 {
391 // in case of single MPDU, there are previous unacknowledged frames, thus
392 // we cannot use Implicit Block Ack Request policy, otherwise we get a
393 // normal ack as response
394 NS_LOG_DEBUG("Request to schedule a Block Ack Request");
395
396 auto acknowledgment = std::make_unique<WifiBarBlockAck>();
397 acknowledgment->blockAckReqTxVector =
398 GetWifiRemoteStationManager()->GetBlockAckReqTxVector(receiver, txParams.m_txVector);
399 acknowledgment->blockAckTxVector = acknowledgment->blockAckReqTxVector;
400 acknowledgment->barType = m_mac->GetBarTypeAsOriginator(receiver, tid);
401 acknowledgment->baType = m_mac->GetBaTypeAsOriginator(receiver, tid);
402 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::BLOCK_ACK);
403 return acknowledgment;
404 }
405
406 if (hdr.IsBlockAckReq())
407 {
408 CtrlBAckRequestHeader baReqHdr;
409 mpdu->GetPacket()->PeekHeader(baReqHdr);
410 if (baReqHdr.IsGcr())
411 {
412 NS_LOG_DEBUG("GCR Block Ack Req, request GCR Block Ack");
413 auto acknowledgment = std::make_unique<WifiBlockAck>();
414 acknowledgment->blockAckTxVector =
415 GetWifiRemoteStationManager()->GetBlockAckTxVector(receiver, txParams.m_txVector);
416 acknowledgment->baType = BlockAckType::GCR;
417 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::NORMAL_ACK);
418 return acknowledgment;
419 }
420 }
421
423 "A-MPDU using Implicit Block Ack Request policy or BlockAckReq, request Block Ack");
424 auto acknowledgment = std::make_unique<WifiBlockAck>();
425 acknowledgment->blockAckTxVector =
426 GetWifiRemoteStationManager()->GetBlockAckTxVector(receiver, txParams.m_txVector);
427 acknowledgment->baType = m_mac->GetBaTypeAsOriginator(receiver, tid);
428 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::NORMAL_ACK);
429 return acknowledgment;
430}
431
432std::unique_ptr<WifiAcknowledgment>
434{
435 NS_LOG_FUNCTION(this << *msdu << &txParams);
436
437 // Aggregating an MSDU does not change the acknowledgment method
438 return nullptr;
439}
440
441std::unique_ptr<WifiAcknowledgment>
443 const WifiTxParameters& txParams)
444{
445 NS_LOG_FUNCTION(this << *mpdu << &txParams);
446 NS_ASSERT(txParams.m_txVector.IsDlMu());
448
449 const WifiMacHeader& hdr = mpdu->GetHeader();
450 Mac48Address receiver = hdr.GetAddr1();
451
453 "QoS data frames only can be aggregated when transmitting a "
454 "DL MU PPDU acknowledged via a sequence of BAR and BA frames");
455 uint8_t tid = hdr.GetQosTid();
456 Ptr<QosTxop> edca = m_mac->GetQosTxop(QosUtilsMapTidToAc(tid));
457
458 NS_ASSERT(!txParams.m_acknowledgment ||
460
461 WifiDlMuBarBaSequence* acknowledgment = nullptr;
462 if (txParams.m_acknowledgment)
463 {
464 acknowledgment = static_cast<WifiDlMuBarBaSequence*>(txParams.m_acknowledgment.get());
465 }
466
467 if (!txParams.LastAddedIsFirstMpdu(receiver))
468 {
469 // an MPDU addressed to the same receiver has been already added
470 NS_ASSERT(acknowledgment);
471
472 if (acknowledgment->stationsSendBlockAckReqTo.contains(receiver) ||
473 acknowledgment->stationsReplyingWithBlockAck.contains(receiver))
474 {
475 // the receiver either is already listed among the stations that will
476 // receive a BlockAckReq frame or is the station that will immediately
477 // respond with a BlockAck frame, hence no change is needed
478 return nullptr;
479 }
480
481 // the receiver was scheduled for responding immediately with a Normal Ack.
482 // Given that we are adding an MPDU, the receiver must be scheduled for
483 // responding immediately with a Block Ack
484 NS_ASSERT(acknowledgment->stationsReplyingWithNormalAck.size() == 1 &&
485 acknowledgment->stationsReplyingWithNormalAck.begin()->first == receiver);
486
487 // acknowledgment points to the m_acknowledgment member of txParams, which is
488 // passed as const reference because it must not be modified. Therefore, we
489 // make a copy of the object pointed to by acknowledgment and make changes to
490 // the copy
491 acknowledgment = new WifiDlMuBarBaSequence(*acknowledgment);
492 acknowledgment->stationsReplyingWithNormalAck.clear();
493
494 acknowledgment->stationsReplyingWithBlockAck.emplace(
495 receiver,
497 GetWifiRemoteStationManager()->GetBlockAckTxVector(receiver, txParams.m_txVector),
498 m_mac->GetBaTypeAsOriginator(receiver, tid)});
499 return std::unique_ptr<WifiDlMuBarBaSequence>(acknowledgment);
500 }
501
502 // we get here if this is the first MPDU for this receiver
503 auto htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
504 NS_ASSERT(htFem);
505 if (auto bar = htFem->GetBar(QosUtilsMapTidToAc(tid), tid, receiver);
506 bar || (acknowledgment && (!acknowledgment->stationsReplyingWithNormalAck.empty() ||
507 !acknowledgment->stationsReplyingWithBlockAck.empty())))
508 {
509 // there is a pending BlockAckReq for this receiver or another receiver
510 // was selected for immediate response.
511 // Add this receiver to the list of stations receiving a BlockAckReq.
512 if (acknowledgment)
513 {
514 // txParams.m_acknowledgment points to an existing WifiDlMuBarBaSequence object.
515 // We have to return a copy of this object including the needed changes
516 acknowledgment = new WifiDlMuBarBaSequence(*acknowledgment);
517 }
518 else
519 {
520 // we have to create a new WifiDlMuBarBaSequence object
521 acknowledgment = new WifiDlMuBarBaSequence;
522 }
523
524 NS_LOG_DEBUG("Adding STA " << receiver
525 << " to the list of stations receiving a BlockAckReq");
526 acknowledgment->stationsSendBlockAckReqTo.emplace(
527 receiver,
529 GetWifiRemoteStationManager()->GetBlockAckReqTxVector(receiver,
530 txParams.m_txVector),
531 m_mac->GetBarTypeAsOriginator(receiver, tid),
532 GetWifiRemoteStationManager()->GetBlockAckTxVector(receiver, txParams.m_txVector),
533 m_mac->GetBaTypeAsOriginator(receiver, tid)});
534
535 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::BLOCK_ACK);
536 return std::unique_ptr<WifiDlMuBarBaSequence>(acknowledgment);
537 }
538
539 // Add the receiver as the station that will immediately reply with a Normal Ack
540 if (acknowledgment)
541 {
542 // txParams.m_acknowledgment points to an existing WifiDlMuBarBaSequence object.
543 // We have to return a copy of this object including the needed changes
544 acknowledgment = new WifiDlMuBarBaSequence(*acknowledgment);
545 }
546 else
547 {
548 // we have to create a new WifiDlMuBarBaSequence object
549 acknowledgment = new WifiDlMuBarBaSequence;
550 }
551
552 NS_LOG_DEBUG("Adding STA " << receiver
553 << " as the station that will immediately reply with a Normal Ack");
554 acknowledgment->stationsReplyingWithNormalAck.emplace(
555 receiver,
557 GetWifiRemoteStationManager()->GetAckTxVector(receiver, txParams.m_txVector)});
558
559 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::NORMAL_ACK);
560 return std::unique_ptr<WifiDlMuBarBaSequence>(acknowledgment);
561}
562
563std::unique_ptr<WifiAcknowledgment>
565 const WifiTxParameters& txParams)
566{
567 NS_LOG_FUNCTION(this << *mpdu << &txParams);
568 NS_ASSERT(txParams.m_txVector.IsDlMu());
570
571 const WifiMacHeader& hdr = mpdu->GetHeader();
572 Mac48Address receiver = hdr.GetAddr1();
573
574 NS_ASSERT(!txParams.m_acknowledgment ||
576
577 WifiDlMuTfMuBar* acknowledgment = nullptr;
578 if (txParams.m_acknowledgment)
579 {
580 acknowledgment = static_cast<WifiDlMuTfMuBar*>(txParams.m_acknowledgment.get());
581 }
582
583 if (txParams.LastAddedIsFirstMpdu(receiver))
584 {
585 // we get here if this is the first MPDU for this receiver.
587 NS_ABORT_MSG_IF(!apMac, "HE APs only can send DL MU PPDUs");
588 uint16_t staId = apMac->GetAssociationId(receiver, m_linkId);
589
591 "QoS data frames only can be aggregated when transmitting a "
592 "DL MU PPDU acknowledged via a MU-BAR sent as SU frame");
593 uint8_t tid = hdr.GetQosTid();
594
595 // Add the receiver to the list of stations that will reply with a Block Ack
596 if (acknowledgment)
597 {
598 // txParams.m_acknowledgment points to an existing WifiDlMuTfMuBar object.
599 // We have to return a copy of this object including the needed changes
600 acknowledgment = new WifiDlMuTfMuBar(*acknowledgment);
601 }
602 else
603 {
604 // we have to create a new WifiDlMuTfMuBar object
605 acknowledgment = new WifiDlMuTfMuBar;
606 }
607
608 // determine the TX vector used to send the BlockAck frame
609 WifiTxVector blockAckTxVector;
610 auto preamble = IsEht(txParams.m_txVector.GetPreambleType()) ? WIFI_PREAMBLE_EHT_TB
612 blockAckTxVector.SetPreambleType(preamble);
613 blockAckTxVector.SetChannelWidth(txParams.m_txVector.GetChannelWidth());
614 // 800ns GI is not allowed for HE TB
615 blockAckTxVector.SetGuardInterval(
616 std::max(txParams.m_txVector.GetGuardInterval(), NanoSeconds(1600)));
617 const auto& userInfo = txParams.m_txVector.GetHeMuUserInfo(staId);
618 blockAckTxVector.SetHeMuUserInfo(
619 staId,
620 {userInfo.ru, std::min(userInfo.mcs, m_maxMcsForBlockAckInTbPpdu), userInfo.nss});
621
622 NS_LOG_DEBUG("Adding STA "
623 << receiver
624 << " to the list of stations that will be solicited by the MU-BAR");
625 Ptr<QosTxop> edca = m_mac->GetQosTxop(QosUtilsMapTidToAc(tid));
626 acknowledgment->stationsReplyingWithBlockAck.emplace(
627 receiver,
628 WifiDlMuTfMuBar::BlockAckInfo{edca->GetBaManager()->GetBlockAckReqHeader(
629 mpdu->GetOriginal()->GetHeader().GetAddr1(),
630 tid),
631 blockAckTxVector,
632 m_mac->GetBaTypeAsOriginator(receiver, tid)});
633
634 acknowledgment->barTypes.push_back(m_mac->GetBarTypeAsOriginator(receiver, tid));
635 acknowledgment->muBarTxVector =
636 GetWifiRemoteStationManager()->GetRtsTxVector(receiver,
637 txParams.m_txVector.GetChannelWidth());
638 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::BLOCK_ACK);
639 return std::unique_ptr<WifiDlMuTfMuBar>(acknowledgment);
640 }
641
642 // an MPDU addressed to the same receiver has been already added
643 NS_ASSERT(acknowledgment);
645 "QoS data frames only can be aggregated when transmitting a DL MU PPDU");
646
647 // no change is needed
648 return nullptr;
649}
650
651std::unique_ptr<WifiAcknowledgment>
653 const WifiTxParameters& txParams)
654{
655 NS_LOG_FUNCTION(this << *mpdu << &txParams);
656 NS_ASSERT(txParams.m_txVector.IsDlMu());
658
659 const WifiMacHeader& hdr = mpdu->GetHeader();
660 Mac48Address receiver = hdr.GetAddr1();
661
662 NS_ASSERT(!txParams.m_acknowledgment ||
664
665 WifiDlMuAggregateTf* acknowledgment = nullptr;
666 if (txParams.m_acknowledgment)
667 {
668 acknowledgment = static_cast<WifiDlMuAggregateTf*>(txParams.m_acknowledgment.get());
669 }
670
671 if (txParams.LastAddedIsFirstMpdu(receiver))
672 {
673 // we get here if this is the first MPDU for this receiver.
675 NS_ABORT_MSG_IF(!apMac, "HE APs only can send DL MU PPDUs");
676 uint16_t staId = apMac->GetAssociationId(receiver, m_linkId);
677
679 "QoS data frames only can be aggregated when transmitting a "
680 "DL MU PPDU acknowledged via a sequence of BAR and BA frames");
681 uint8_t tid = hdr.GetQosTid();
682
683 // Add the receiver to the list of stations that will reply with a Block Ack
684 if (acknowledgment)
685 {
686 // txParams.m_acknowledgment points to an existing WifiDlMuAggregateTf object.
687 // We have to return a copy of this object including the needed changes
688 acknowledgment = new WifiDlMuAggregateTf(*acknowledgment);
689 }
690 else
691 {
692 // we have to create a new WifiDlMuAggregateTf object
693 acknowledgment = new WifiDlMuAggregateTf;
694 }
695
696 // determine the TX vector used to send the BlockAck frame
697 WifiTxVector blockAckTxVector;
698 auto preamble = IsEht(txParams.m_txVector.GetPreambleType()) ? WIFI_PREAMBLE_EHT_TB
700 blockAckTxVector.SetPreambleType(preamble);
701 blockAckTxVector.SetChannelWidth(txParams.m_txVector.GetChannelWidth());
702 // 800ns GI is not allowed for HE TB
703 blockAckTxVector.SetGuardInterval(
704 std::max(txParams.m_txVector.GetGuardInterval(), NanoSeconds(1600)));
705 const auto& userInfo = txParams.m_txVector.GetHeMuUserInfo(staId);
706 blockAckTxVector.SetHeMuUserInfo(
707 staId,
708 {userInfo.ru, std::min(userInfo.mcs, m_maxMcsForBlockAckInTbPpdu), userInfo.nss});
709
710 NS_LOG_DEBUG("Adding STA " << receiver
711 << " to the list of stations that will reply with a Block Ack");
712 Ptr<QosTxop> edca = m_mac->GetQosTxop(QosUtilsMapTidToAc(tid));
713 acknowledgment->stationsReplyingWithBlockAck.emplace(
714 receiver,
718 txParams.m_txVector.GetChannelWidth(),
719 {m_mac->GetBarTypeAsOriginator(receiver, tid)}),
720 edca->GetBaManager()->GetBlockAckReqHeader(
721 mpdu->GetOriginal()->GetHeader().GetAddr1(),
722 tid),
723 blockAckTxVector,
724 m_mac->GetBaTypeAsOriginator(receiver, tid)});
725
726 acknowledgment->SetQosAckPolicy(receiver, tid, WifiMacHeader::NO_EXPLICIT_ACK);
727 return std::unique_ptr<WifiDlMuAggregateTf>(acknowledgment);
728 }
729
730 // an MPDU addressed to the same receiver has been already added
731 NS_ASSERT(acknowledgment);
733 !hdr.IsQosData(),
734 "QoS data and MU-BAR Trigger frames only can be aggregated when transmitting a DL MU PPDU");
735
736 // no change is needed
737 return nullptr;
738}
739
740std::unique_ptr<WifiAcknowledgment>
742 const WifiTxParameters& txParams)
743{
744 NS_LOG_FUNCTION(this << *mpdu << &txParams);
745 NS_ASSERT(mpdu->GetHeader().IsTrigger());
746
748 NS_ABORT_MSG_IF(!apMac, "HE APs only can send Trigger Frames");
749
750 auto heFem = DynamicCast<HeFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
751 NS_ABORT_MSG_IF(!heFem, "HE APs only can send Trigger Frames");
752
753 CtrlTriggerHeader trigger;
754 mpdu->GetPacket()->PeekHeader(trigger);
755
756 if (trigger.IsBasic())
757 {
758 // the only supported ack method for now is through a multi-STA BlockAck frame
759 auto acknowledgment = std::make_unique<WifiUlMuMultiStaBa>();
760
761 for (const auto& userInfo : trigger)
762 {
763 uint16_t aid12 = userInfo.GetAid12();
764
765 if (aid12 == NO_USER_STA_ID)
766 {
767 NS_LOG_INFO("Unallocated RU");
768 continue;
769 }
770 const auto maxAid =
772 NS_ABORT_MSG_IF(aid12 < MIN_AID || aid12 > maxAid,
773 "Allocation of RA-RUs is not supported");
774
775 const auto it = apMac->GetStaList(m_linkId).find(aid12);
776 NS_ASSERT(it != apMac->GetStaList(m_linkId).end());
777 const auto staAddress = it->second;
778
779 // find a TID for which a BA agreement exists with the given originator
780 uint8_t tid = 0;
781 while (tid < 8 && !m_mac->GetBaAgreementEstablishedAsRecipient(staAddress, tid))
782 {
783 tid++;
784 }
785 NS_ASSERT_MSG(tid < 8,
786 "No Block Ack agreement established with originator " << staAddress);
787
788 std::size_t index = acknowledgment->baType.m_bitmapLen.size();
789 acknowledgment->stationsReceivingMultiStaBa.emplace(std::make_pair(staAddress, tid),
790 index);
791
792 // we assume the Block Acknowledgment context is used for the multi-STA BlockAck frame
793 // (since it requires the longest TX time due to the presence of a bitmap)
794 acknowledgment->baType.m_bitmapLen.push_back(
795 m_mac->GetBaTypeAsRecipient(staAddress, tid).m_bitmapLen.at(0));
796 }
797
798 uint16_t staId = trigger.begin()->GetAid12();
799 acknowledgment->tbPpduTxVector = trigger.GetHeTbTxVector(staId);
800 acknowledgment->multiStaBaTxVector = GetWifiRemoteStationManager()->GetBlockAckTxVector(
801 apMac->GetStaList(m_linkId).find(staId)->second,
802 acknowledgment->tbPpduTxVector);
803 return acknowledgment;
804 }
805 else if (trigger.IsBsrp())
806 {
807 return std::make_unique<WifiNoAck>();
808 }
809
810 return nullptr;
811}
812
813} // namespace ns3
Headers for BlockAckRequest.
Headers for Trigger frames.
bool IsBasic() const
Check if this is a Basic Trigger frame.
bool IsBsrp() const
Check if this is a Buffer Status Report Poll Trigger frame.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold variables of type enum.
Definition enum.h:52
an EUI-48 address
bool IsGroup() const
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
Hold an unsigned integer type.
Definition uinteger.h:34
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...
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.
Implements the IEEE 802.11 MAC header.
uint8_t GetQosTid() const
Return the Traffic ID of a QoS header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
bool IsQosData() const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
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.
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,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:76
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:99
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#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.
Definition log.h:274
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1364
WifiContainerQueueId MakeWifiUnicastQueueId(WifiContainerQueueType type, Mac48Address addr1, std::optional< tid_t > tid=std::nullopt)
Helper function to create WifiContainerQueueId for unicast queues.
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
This function is useful to get traffic id of different packet types.
Definition qos-utils.cc:165
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition qos-utils.cc:123
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet.
Definition qos-utils.cc:156
@ WIFI_PREAMBLE_EHT_TB
@ WIFI_PREAMBLE_HE_TB
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
uint32_t GetMuBarSize(TriggerFrameVariant variant, MHz_u bw, const std::list< BlockAckReqType > &types)
Return the total MU-BAR size (including FCS trailer).
Definition wifi-utils.cc:79
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition enum.h:181
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:643
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).
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
bool IsGcr(Ptr< WifiMac > mac, const WifiMacHeader &hdr)
Return whether a given packet is transmitted using the GCR service.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
static constexpr uint16_t MAX_AID
The maximum value for the association ID (Sec. 9.4.1.8 of 802.11-2020).
static constexpr uint16_t EHT_MAX_AID
The maximum value for the association ID updated since 802.11be (Sec. 9.4.1.8 of 802....
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition enum.h:223
bool IsEht(WifiPreamble preamble)
Return true if a preamble corresponds to an EHT transmission.
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