A Discrete-Event Network Simulator
API
qos-txop.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, 2009 INRIA
3  * Copyright (c) 2009 MIRKO BANCHI
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Mirko Banchi <mk.banchi@gmail.com>
20  * Stefano Avallone <stavalli@unina.it>
21  */
22 
23 #include "qos-txop.h"
24 
25 #include "channel-access-manager.h"
26 #include "ctrl-headers.h"
27 #include "mac-tx-middle.h"
28 #include "mgt-action-headers.h"
29 #include "mpdu-aggregator.h"
30 #include "msdu-aggregator.h"
32 #include "wifi-mac-queue.h"
33 #include "wifi-mac-trailer.h"
34 #include "wifi-phy.h"
35 #include "wifi-psdu.h"
36 #include "wifi-tx-parameters.h"
37 
38 #include "ns3/ht-frame-exchange-manager.h"
39 #include "ns3/log.h"
40 #include "ns3/pointer.h"
41 #include "ns3/random-variable-stream.h"
42 #include "ns3/simulator.h"
43 
44 #undef NS_LOG_APPEND_CONTEXT
45 #define NS_LOG_APPEND_CONTEXT \
46  if (m_mac) \
47  { \
48  std::clog << "[mac=" << m_mac->GetAddress() << "] "; \
49  }
50 
51 namespace ns3
52 {
53 
54 NS_LOG_COMPONENT_DEFINE("QosTxop");
55 
57 
58 TypeId
60 {
61  static TypeId tid =
62  TypeId("ns3::QosTxop")
64  .SetGroupName("Wifi")
65  .AddConstructor<QosTxop>()
66  .AddAttribute("UseExplicitBarAfterMissedBlockAck",
67  "Specify whether explicit BlockAckRequest should be sent upon missed "
68  "BlockAck Response.",
69  BooleanValue(true),
72  .AddAttribute("AddBaResponseTimeout",
73  "The timeout to wait for ADDBA response after the Ack to "
74  "ADDBA request is received.",
79  .AddAttribute(
80  "FailedAddBaTimeout",
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.",
85  TimeValue(MilliSeconds(200)),
88  .AddAttribute("BlockAckManager",
89  "The BlockAckManager object.",
90  PointerValue(),
92  MakePointerChecker<BlockAckManager>())
93  .AddAttribute("NMaxInflights",
94  "The maximum number of links (in the range 1-15) on which an MPDU can be "
95  "simultaneously in-flight.",
96  UintegerValue(1),
98  MakeUintegerChecker<uint8_t>(1, 15))
99  .AddTraceSource("TxopTrace",
100  "Trace source for TXOP start and duration times",
102  "ns3::QosTxop::TxopTracedCallback");
103  return tid;
104 }
105 
108  m_ac(ac)
109 {
110  NS_LOG_FUNCTION(this);
111  m_baManager = CreateObject<BlockAckManager>();
112  m_baManager->SetQueue(m_queue);
113  m_baManager->SetBlockDestinationCallback(
114  Callback<void, Mac48Address, uint8_t>([this](Mac48Address recipient, uint8_t tid) {
116  m_ac,
118  recipient,
119  m_mac->GetLocalAddress(recipient),
120  {tid});
121  }));
122  m_baManager->SetUnblockDestinationCallback(
123  Callback<void, Mac48Address, uint8_t>([this](Mac48Address recipient, uint8_t tid) {
124  // save the status of AC queues before unblocking the transmissions to the recipient
125  std::map<uint8_t, bool> hasFramesToTransmit;
126  for (const auto& [id, link] : GetLinks())
127  {
128  hasFramesToTransmit[id] = HasFramesToTransmit(id);
129  }
130 
132  m_ac,
134  recipient,
135  m_mac->GetLocalAddress(recipient),
136  {tid});
137 
138  // start access (if needed) on all the links
139  for (const auto& [id, link] : GetLinks())
140  {
141  StartAccessAfterEvent(id, hasFramesToTransmit.at(id), CHECK_MEDIUM_BUSY);
142  }
143  }));
144  m_queue->TraceConnectWithoutContext(
145  "Expired",
147 }
148 
150 {
151  NS_LOG_FUNCTION(this);
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION(this);
158  if (m_baManager)
159  {
160  m_baManager->Dispose();
161  }
162  m_baManager = nullptr;
163  Txop::DoDispose();
164 }
165 
166 std::unique_ptr<Txop::LinkEntity>
168 {
169  return std::make_unique<QosLinkEntity>();
170 }
171 
173 QosTxop::GetLink(uint8_t linkId) const
174 {
175  return static_cast<QosLinkEntity&>(Txop::GetLink(linkId));
176 }
177 
178 uint8_t
179 QosTxop::GetQosQueueSize(uint8_t tid, Mac48Address receiver) const
180 {
181  WifiContainerQueueId queueId{WIFI_QOSDATA_QUEUE, WIFI_UNICAST, receiver, tid};
182  uint32_t bufferSize = m_queue->GetNBytes(queueId);
183  // A queue size value of 254 is used for all sizes greater than 64 768 octets.
184  uint8_t queueSize = static_cast<uint8_t>(std::ceil(std::min(bufferSize, 64769U) / 256.0));
185  NS_LOG_DEBUG("Buffer size=" << bufferSize << " Queue Size=" << +queueSize);
186  return queueSize;
187 }
188 
189 void
191 {
192  NS_LOG_FUNCTION(this << &callback);
194  m_baManager->SetDroppedOldMpduCallback(callback.Bind(WIFI_MAC_DROP_QOS_OLD_PACKET));
195 }
196 
197 void
198 QosTxop::SetMuCwMin(uint16_t cwMin, uint8_t linkId)
199 {
200  NS_LOG_FUNCTION(this << cwMin << +linkId);
201  GetLink(linkId).muCwMin = cwMin;
202 }
203 
204 void
205 QosTxop::SetMuCwMax(uint16_t cwMax, uint8_t linkId)
206 {
207  NS_LOG_FUNCTION(this << cwMax << +linkId);
208  GetLink(linkId).muCwMax = cwMax;
209 }
210 
211 void
212 QosTxop::SetMuAifsn(uint8_t aifsn, uint8_t linkId)
213 {
214  NS_LOG_FUNCTION(this << +aifsn << +linkId);
215  GetLink(linkId).muAifsn = aifsn;
216 }
217 
218 void
219 QosTxop::SetMuEdcaTimer(Time timer, uint8_t linkId)
220 {
221  NS_LOG_FUNCTION(this << timer << +linkId);
222  GetLink(linkId).muEdcaTimer = timer;
223 }
224 
225 void
227 {
228  NS_LOG_FUNCTION(this << +linkId);
229  auto& link = GetLink(linkId);
230  link.muEdcaTimerStartTime = Simulator::Now();
231  if (EdcaDisabled(linkId))
232  {
233  NS_LOG_DEBUG("Disable EDCA for " << link.muEdcaTimer.As(Time::MS));
234  m_mac->GetChannelAccessManager(linkId)->DisableEdcaFor(this, link.muEdcaTimer);
235  }
236 }
237 
238 bool
239 QosTxop::MuEdcaTimerRunning(uint8_t linkId) const
240 {
241  auto& link = GetLink(linkId);
242  return (link.muEdcaTimerStartTime.IsStrictlyPositive() &&
243  link.muEdcaTimer.IsStrictlyPositive() &&
244  link.muEdcaTimerStartTime + link.muEdcaTimer > Simulator::Now());
245 }
246 
247 bool
248 QosTxop::EdcaDisabled(uint8_t linkId) const
249 {
250  return (MuEdcaTimerRunning(linkId) && GetLink(linkId).muAifsn == 0);
251 }
252 
253 uint32_t
254 QosTxop::GetMinCw(uint8_t linkId) const
255 {
256  if (!MuEdcaTimerRunning(linkId))
257  {
258  return GetLink(linkId).cwMin;
259  }
260  NS_ASSERT(!EdcaDisabled(linkId));
261  return GetLink(linkId).muCwMin;
262 }
263 
264 uint32_t
265 QosTxop::GetMaxCw(uint8_t linkId) const
266 {
267  if (!MuEdcaTimerRunning(linkId))
268  {
269  return GetLink(linkId).cwMax;
270  }
271  NS_ASSERT(!EdcaDisabled(linkId));
272  return GetLink(linkId).muCwMax;
273 }
274 
275 uint8_t
276 QosTxop::GetAifsn(uint8_t linkId) const
277 {
278  if (!MuEdcaTimerRunning(linkId))
279  {
280  return GetLink(linkId).aifsn;
281  }
282  return GetLink(linkId).muAifsn;
283 }
284 
287 {
288  return m_baManager;
289 }
290 
291 uint16_t
293 {
294  return m_baManager->GetRecipientBufferSize(address, tid);
295 }
296 
297 uint16_t
299 {
300  return m_baManager->GetOriginatorStartingSequence(address, tid);
301 }
302 
303 std::pair<CtrlBAckRequestHeader, WifiMacHeader>
304 QosTxop::PrepareBlockAckRequest(Mac48Address recipient, uint8_t tid) const
305 {
306  NS_LOG_FUNCTION(this << recipient << +tid);
308 
309  auto recipientMld = m_mac->GetMldAddress(recipient);
310 
311  CtrlBAckRequestHeader reqHdr =
312  m_baManager->GetBlockAckReqHeader(recipientMld.value_or(recipient), tid);
313 
314  WifiMacHeader hdr;
316  hdr.SetAddr1(recipient);
317  hdr.SetAddr2(m_mac->GetLocalAddress(recipient));
318  hdr.SetDsNotTo();
319  hdr.SetDsNotFrom();
320  hdr.SetNoRetry();
321  hdr.SetNoMoreFragments();
322 
323  return {reqHdr, hdr};
324 }
325 
326 bool
328 {
330 }
331 
332 bool
334 {
335  // remove MSDUs with expired lifetime starting from the head of the queue
336  m_queue->WipeAllExpiredMpdus();
337  bool queueIsNotEmpty = (bool)(m_queue->PeekFirstAvailable(linkId));
338 
339  NS_LOG_FUNCTION(this << queueIsNotEmpty);
340  return queueIsNotEmpty;
341 }
342 
343 uint16_t
345 {
346  return m_txMiddle->GetNextSequenceNumberFor(hdr);
347 }
348 
349 uint16_t
351 {
352  return m_txMiddle->PeekNextSequenceNumberFor(hdr);
353 }
354 
355 bool
357 {
358  NS_LOG_FUNCTION(this << *mpdu);
359 
360  if (!mpdu->GetHeader().IsQosData())
361  {
362  return false;
363  }
364 
365  Mac48Address recipient = mpdu->GetHeader().GetAddr1();
366  uint8_t tid = mpdu->GetHeader().GetQosTid();
367 
368  if (!m_mac->GetBaAgreementEstablishedAsOriginator(recipient, tid))
369  {
370  return false;
371  }
372 
373  return QosUtilsIsOldPacket(GetBaStartingSequence(recipient, tid),
374  mpdu->GetHeader().GetSequenceNumber());
375 }
376 
378 QosTxop::PeekNextMpdu(uint8_t linkId, uint8_t tid, Mac48Address recipient, Ptr<const WifiMpdu> mpdu)
379 {
380  NS_LOG_FUNCTION(this << +linkId << +tid << recipient << mpdu);
381 
382  // lambda to peek the next frame
383  auto peek = [this, &linkId, &tid, &recipient, &mpdu]() -> Ptr<WifiMpdu> {
384  if (tid == 8 && recipient.IsBroadcast()) // undefined TID and recipient
385  {
386  return m_queue->PeekFirstAvailable(linkId, mpdu);
387  }
388  WifiContainerQueueId queueId(WIFI_QOSDATA_QUEUE, WIFI_UNICAST, recipient, tid);
389  if (auto mask = m_mac->GetMacQueueScheduler()->GetQueueLinkMask(m_ac, queueId, linkId);
390  !mask || mask->none())
391  {
392  return m_queue->PeekByQueueId(queueId, mpdu);
393  }
394  return nullptr;
395  };
396 
397  auto item = peek();
398  // remove old packets (must be retransmissions or in flight, otherwise they did
399  // not get a sequence number assigned)
400  while (item && !item->IsFragment())
401  {
402  if (item->GetHeader().IsCtl())
403  {
404  NS_LOG_DEBUG("Skipping control frame: " << *item);
405  mpdu = item;
406  item = peek();
407  continue;
408  }
409 
410  if (item->HasSeqNoAssigned() && IsQosOldPacket(item))
411  {
412  NS_LOG_DEBUG("Removing an old packet from EDCA queue: " << *item);
414  {
416  }
417  mpdu = item;
418  item = peek();
419  m_queue->Remove(mpdu);
420  continue;
421  }
422 
423  if (auto linkIds = item->GetInFlightLinkIds(); !linkIds.empty()) // MPDU is in-flight
424  {
425  // if the MPDU is not already in-flight on the link for which we are requesting an
426  // MPDU and the number of links on which the MPDU is in-flight is less than the
427  // maximum number, then we can transmit this MPDU
428  if (linkIds.count(linkId) == 0 && linkIds.size() < m_nMaxInflights)
429  {
430  break;
431  }
432 
433  // if no BA agreement, we cannot have multiple MPDUs in-flight
434  if (item->GetHeader().IsQosData() &&
435  !m_mac->GetBaAgreementEstablishedAsOriginator(item->GetHeader().GetAddr1(),
436  item->GetHeader().GetQosTid()))
437  {
438  NS_LOG_DEBUG("No BA agreement and an MPDU is already in-flight");
439  return nullptr;
440  }
441 
442  NS_LOG_DEBUG("Skipping in flight MPDU: " << *item);
443  mpdu = item;
444  item = peek();
445  continue;
446  }
447 
448  if (item->GetHeader().HasData() &&
449  !m_mac->CanForwardPacketsTo(item->GetHeader().GetAddr1()))
450  {
451  NS_LOG_DEBUG("Skipping frame that cannot be forwarded: " << *item);
452  mpdu = item;
453  item = peek();
454  continue;
455  }
456  break;
457  }
458 
459  if (!item)
460  {
461  return nullptr;
462  }
463 
464  WifiMacHeader& hdr = item->GetHeader();
465 
466  // peek the next sequence number and check if it is within the transmit window
467  // in case of QoS data frame
468  uint16_t sequence = item->HasSeqNoAssigned() ? hdr.GetSequenceNumber()
469  : m_txMiddle->PeekNextSequenceNumberFor(&hdr);
470  if (hdr.IsQosData())
471  {
472  Mac48Address recipient = hdr.GetAddr1();
473  uint8_t tid = hdr.GetQosTid();
474 
475  if (m_mac->GetBaAgreementEstablishedAsOriginator(recipient, tid) &&
476  !IsInWindow(sequence,
477  GetBaStartingSequence(recipient, tid),
478  GetBaBufferSize(recipient, tid)))
479  {
480  NS_LOG_DEBUG("Packet beyond the end of the current transmit window");
481  return nullptr;
482  }
483  }
484 
485  // Assign a sequence number if this is not a fragment nor it already has one assigned
486  if (!item->IsFragment() && !item->HasSeqNoAssigned())
487  {
488  hdr.SetSequenceNumber(sequence);
489  }
490  NS_LOG_DEBUG("Packet peeked from EDCA queue: " << *item);
491  return item;
492 }
493 
495 QosTxop::GetNextMpdu(uint8_t linkId,
496  Ptr<WifiMpdu> peekedItem,
497  WifiTxParameters& txParams,
498  Time availableTime,
499  bool initialFrame)
500 {
501  NS_ASSERT(peekedItem);
502  NS_LOG_FUNCTION(this << +linkId << *peekedItem << &txParams << availableTime << initialFrame);
503 
504  Mac48Address recipient = peekedItem->GetHeader().GetAddr1();
505 
506  // The TXOP limit can be exceeded by the TXOP holder if it does not transmit more
507  // than one Data or Management frame in the TXOP and the frame is not in an A-MPDU
508  // consisting of more than one MPDU (Sec. 10.22.2.8 of 802.11-2016)
509  Time actualAvailableTime =
510  (initialFrame && txParams.GetSize(recipient) == 0 ? Time::Min() : availableTime);
511 
512  auto qosFem = StaticCast<QosFrameExchangeManager>(m_mac->GetFrameExchangeManager(linkId));
513  if (!qosFem->TryAddMpdu(peekedItem, txParams, actualAvailableTime))
514  {
515  return nullptr;
516  }
517 
518  NS_ASSERT(peekedItem->IsQueued());
519  Ptr<WifiMpdu> mpdu;
520 
521  // If it is a non-broadcast QoS Data frame and it is not a retransmission nor a fragment,
522  // attempt A-MSDU aggregation
523  if (peekedItem->GetHeader().IsQosData())
524  {
525  uint8_t tid = peekedItem->GetHeader().GetQosTid();
526 
527  // we should not be asked to dequeue an MPDU that is beyond the transmit window.
528  // Note that PeekNextMpdu() temporarily assigns the next available sequence number
529  // to the peeked frame
531  IsInWindow(
532  peekedItem->GetHeader().GetSequenceNumber(),
533  GetBaStartingSequence(peekedItem->GetOriginal()->GetHeader().GetAddr1(), tid),
534  GetBaBufferSize(peekedItem->GetOriginal()->GetHeader().GetAddr1(), tid)));
535 
536  // try A-MSDU aggregation if the MPDU does not contain an A-MSDU and does not already
537  // have a sequence number assigned (may be a retransmission)
538  if (m_mac->GetHtSupported() && !recipient.IsBroadcast() &&
539  !peekedItem->GetHeader().IsQosAmsdu() && !peekedItem->HasSeqNoAssigned() &&
540  !peekedItem->IsFragment())
541  {
542  auto htFem = StaticCast<HtFrameExchangeManager>(qosFem);
543  mpdu = htFem->GetMsduAggregator()->GetNextAmsdu(peekedItem, txParams, availableTime);
544  }
545 
546  if (mpdu)
547  {
548  NS_LOG_DEBUG("Prepared an MPDU containing an A-MSDU");
549  }
550  // else aggregation was not attempted or failed
551  }
552 
553  if (!mpdu)
554  {
555  mpdu = peekedItem;
556  }
557 
558  // Assign a sequence number if this is not a fragment nor a retransmission
559  AssignSequenceNumber(mpdu);
560  NS_LOG_DEBUG("Got MPDU from EDCA queue: " << *mpdu);
561 
562  return mpdu;
563 }
564 
565 void
567 {
568  NS_LOG_FUNCTION(this << *mpdu);
569 
570  if (!mpdu->IsFragment() && !mpdu->HasSeqNoAssigned())
571  {
572  // in case of 11be MLDs, sequence numbers refer to the MLD address
573  auto origMpdu = m_queue->GetOriginal(mpdu);
574  uint16_t sequence = m_txMiddle->GetNextSequenceNumberFor(&origMpdu->GetHeader());
575  mpdu->AssignSeqNo(sequence);
576  }
577 }
578 
579 void
580 QosTxop::NotifyChannelAccessed(uint8_t linkId, Time txopDuration)
581 {
582  NS_LOG_FUNCTION(this << +linkId << txopDuration);
583 
584  NS_ASSERT(txopDuration != Time::Min());
585  GetLink(linkId).startTxop = Simulator::Now();
586  GetLink(linkId).txopDuration = txopDuration;
588 }
589 
590 std::optional<Time>
591 QosTxop::GetTxopStartTime(uint8_t linkId) const
592 {
593  auto& link = GetLink(linkId);
594  NS_LOG_FUNCTION(this << link.startTxop.has_value());
595  return link.startTxop;
596 }
597 
598 void
600 {
601  NS_LOG_FUNCTION(this << +linkId);
602  auto& link = GetLink(linkId);
603 
604  if (link.startTxop)
605  {
606  NS_LOG_DEBUG("Terminating TXOP. Duration = " << Simulator::Now() - *link.startTxop);
607  m_txopTrace(*link.startTxop, Simulator::Now() - *link.startTxop, linkId);
608  }
609 
610  // generate a new backoff value if either the TXOP duration is not null (i.e., some frames
611  // were transmitted) or no frame was transmitted but the queue actually contains frame to
612  // transmit and the user indicated that a backoff value should be generated in this situation.
613  // This behavior reflects the following specs text (Sec. 35.3.16.4 of 802.11be D4.0):
614  // An AP or non-AP STA affiliated with an MLD that has gained the right to initiate the
615  // transmission of a frame as described in 10.23.2.4 (Obtaining an EDCA TXOP) for an AC but
616  // does not transmit any frame corresponding to that AC for the reasons stated above may:
617  // - invoke a backoff for the EDCAF associated with that AC as allowed per h) of 10.23.2.2
618  // (EDCA backoff procedure).
619  auto hasTransmitted = link.startTxop.has_value() && Simulator::Now() > *link.startTxop;
620 
621  m_queue->WipeAllExpiredMpdus();
622  if ((hasTransmitted) ||
623  (!m_queue->IsEmpty() && m_mac->GetChannelAccessManager(linkId)->GetGenerateBackoffOnNoTx()))
624  {
625  GenerateBackoff(linkId);
626  if (!m_queue->IsEmpty())
627  {
629  }
630  }
631  link.startTxop.reset();
632  GetLink(linkId).access = NOT_REQUESTED;
633 }
634 
635 Time
636 QosTxop::GetRemainingTxop(uint8_t linkId) const
637 {
638  auto& link = GetLink(linkId);
639  NS_ASSERT(link.startTxop.has_value());
640 
641  Time remainingTxop = link.txopDuration;
642  remainingTxop -= (Simulator::Now() - *link.startTxop);
643  if (remainingTxop.IsStrictlyNegative())
644  {
645  remainingTxop = Seconds(0);
646  }
647  NS_LOG_FUNCTION(this << remainingTxop);
648  return remainingTxop;
649 }
650 
651 void
653 {
654  NS_LOG_FUNCTION(this << respHdr << recipient);
655  uint8_t tid = respHdr.GetTid();
656 
657  if (respHdr.GetStatusCode().IsSuccess())
658  {
659  NS_LOG_DEBUG("block ack agreement established with " << recipient << " tid " << +tid);
660  // A (destination, TID) pair is "blocked" (i.e., no more packets are sent)
661  // when an Add BA Request is sent to the destination. However, when the
662  // Add BA Request timer expires, the (destination, TID) pair is "unblocked"
663  // and packets to the destination are sent again (under normal ack policy).
664  // Thus, there may be a packet needing to be retransmitted when the
665  // Add BA Response is received. In this case, the starting sequence number
666  // shall be set equal to the sequence number of such packet.
667  uint16_t startingSeq = m_txMiddle->GetNextSeqNumberByTidAndAddress(tid, recipient);
668  auto peekedItem = m_queue->PeekByTidAndAddress(tid, recipient);
669  if (peekedItem && peekedItem->GetHeader().IsRetry())
670  {
671  startingSeq = peekedItem->GetHeader().GetSequenceNumber();
672  }
673  m_baManager->UpdateOriginatorAgreement(respHdr, recipient, startingSeq);
674  }
675  else
676  {
677  NS_LOG_DEBUG("discard ADDBA response" << recipient);
678  m_baManager->NotifyOriginatorAgreementRejected(recipient, tid);
679  }
680 }
681 
682 void
684 {
685  NS_LOG_FUNCTION(this << delBaHdr << recipient);
686  NS_LOG_DEBUG("received DELBA frame from=" << recipient);
687  m_baManager->DestroyOriginatorAgreement(recipient, delBaHdr->GetTid());
688 }
689 
690 void
692 {
693  NS_LOG_FUNCTION(this << recipient << tid);
694  m_baManager->NotifyOriginatorAgreementNoReply(recipient, tid);
695 }
696 
697 void
699 {
700  NS_ASSERT(mpdu->GetHeader().IsQosData());
701  // If there is an established BA agreement, store the packet in the queue of outstanding packets
702  if (m_mac->GetBaAgreementEstablishedAsOriginator(mpdu->GetHeader().GetAddr1(),
703  mpdu->GetHeader().GetQosTid()))
704  {
705  NS_ASSERT(mpdu->IsQueued());
706  NS_ASSERT(m_queue->GetAc() == mpdu->GetQueueAc());
707  m_baManager->StorePacket(m_queue->GetOriginal(mpdu));
708  }
709 }
710 
711 void
713 {
714  NS_LOG_FUNCTION(this << +threshold);
715  m_blockAckThreshold = threshold;
716  m_baManager->SetBlockAckThreshold(threshold);
717 }
718 
719 void
721 {
722  NS_LOG_FUNCTION(this << timeout);
724 }
725 
726 uint8_t
728 {
729  NS_LOG_FUNCTION(this);
730  return m_blockAckThreshold;
731 }
732 
733 uint16_t
735 {
737 }
738 
739 void
741 {
742  NS_LOG_FUNCTION(this << recipient << +tid);
743  // If agreement is still pending, ADDBA response is not received
744  if (auto agreement = m_baManager->GetAgreementAsOriginator(recipient, tid);
745  agreement && agreement->get().IsPending())
746  {
747  NotifyOriginatorAgreementNoReply(recipient, tid);
749  }
750 }
751 
752 void
753 QosTxop::ResetBa(Mac48Address recipient, uint8_t tid)
754 {
755  NS_LOG_FUNCTION(this << recipient << +tid);
756  // This function is scheduled when waiting for an ADDBA response. However,
757  // before this function is called, a DELBA request may arrive, which causes
758  // the agreement to be deleted. Hence, check if an agreement exists before
759  // notifying that the agreement has to be reset.
760  if (auto agreement = m_baManager->GetAgreementAsOriginator(recipient, tid);
761  agreement && !agreement->get().IsEstablished())
762  {
763  m_baManager->NotifyOriginatorAgreementReset(recipient, tid);
764  }
765 }
766 
767 void
769 {
770  NS_LOG_FUNCTION(this << addBaResponseTimeout);
771  m_addBaResponseTimeout = addBaResponseTimeout;
772 }
773 
774 Time
776 {
777  return m_addBaResponseTimeout;
778 }
779 
780 void
782 {
783  NS_LOG_FUNCTION(this << failedAddBaTimeout);
784  m_failedAddBaTimeout = failedAddBaTimeout;
785 }
786 
787 Time
789 {
790  return m_failedAddBaTimeout;
791 }
792 
793 bool
795 {
796  return true;
797 }
798 
799 AcIndex
801 {
802  return m_ac;
803 }
804 
805 } // namespace ns3
#define min(a, b)
Definition: 80211b.c:41
void NotifyDiscardedMpdu(Ptr< const WifiMpdu > mpdu)
Callback template class.
Definition: callback.h:438
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
auto Bind(BoundArgs &&... bargs)
Bind a variable number of arguments.
Definition: callback.h:557
void DisableEdcaFor(Ptr< Txop > qosTxop, Time duration)
Headers for BlockAckRequest.
Definition: ctrl-headers.h:52
an EUI-48 address
Definition: mac48-address.h:46
bool IsBroadcast() const
Implement the header for management frames of type Add Block Ack response.
StatusCode GetStatusCode() const
Return the status code.
uint8_t GetTid() const
Return the Traffic ID (TID).
Implement the header for management frames of type Delete Block Ack.
uint8_t GetTid() const
Return the Traffic ID (TID).
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:74
QosTxop(AcIndex ac=AC_UNDEF)
Constructor.
Definition: qos-txop.cc:106
std::unique_ptr< LinkEntity > CreateLinkEntity() const override
Create a LinkEntity object.
Definition: qos-txop.cc:167
~QosTxop() override
Definition: qos-txop.cc:149
uint8_t m_blockAckThreshold
the block ack threshold (use BA mechanism if number of packets in queue reaches this value.
Definition: qos-txop.h:469
Ptr< BlockAckManager > GetBaManager()
Get the Block Ack Manager associated with this QosTxop.
Definition: qos-txop.cc:286
Time m_failedAddBaTimeout
timeout after failed BA agreement
Definition: qos-txop.h:476
Ptr< WifiMpdu > PeekNextMpdu(uint8_t linkId, uint8_t tid=8, Mac48Address recipient=Mac48Address::GetBroadcast(), Ptr< const WifiMpdu > mpdu=nullptr)
Peek the next frame to transmit on the given link to the given receiver and of the given TID from the...
Definition: qos-txop.cc:378
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i....
Definition: qos-txop.cc:350
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.
Definition: qos-txop.cc:198
bool UseExplicitBarAfterMissedBlockAck() const
Return true if an explicit BlockAckRequest is sent after a missed BlockAck.
Definition: qos-txop.cc:327
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...
Definition: qos-txop.cc:248
Time GetAddBaResponseTimeout() const
Get the timeout for ADDBA response.
Definition: qos-txop.cc:775
AcIndex GetAccessCategory() const
Get the access category of this object.
Definition: qos-txop.cc:800
void AddBaResponseTimeout(Mac48Address recipient, uint8_t tid)
Callback when ADDBA response is not received after timeout.
Definition: qos-txop.cc:740
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:292
void DoDispose() override
Destructor implementation.
Definition: qos-txop.cc:155
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.
Definition: qos-txop.cc:205
bool MuEdcaTimerRunning(uint8_t linkId) const
Return true if the MU EDCA Timer is running for the given link, false otherwise.
Definition: qos-txop.cc:239
void StartMuEdcaTimerNow(uint8_t linkId)
Start the MU EDCA Timer for the given link.
Definition: qos-txop.cc:226
uint8_t GetBlockAckThreshold() const
Return the current threshold for block ack mechanism.
Definition: qos-txop.cc:727
void NotifyChannelReleased(uint8_t linkId) override
Called by the FrameExchangeManager to notify the completion of the transmissions.
Definition: qos-txop.cc:599
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
Definition: qos-txop.cc:344
uint16_t GetBlockAckInactivityTimeout() const
Get the BlockAck inactivity timeout.
Definition: qos-txop.cc:734
TxopTracedCallback m_txopTrace
TXOP trace callback.
Definition: qos-txop.h:487
virtual Time GetRemainingTxop(uint8_t linkId) const
Return the remaining duration in the current TXOP on the given link.
Definition: qos-txop.cc:636
AcIndex m_ac
the access category
Definition: qos-txop.h:467
void SetDroppedMpduCallback(DroppedMpdu callback) override
Definition: qos-txop.cc:190
bool m_useExplicitBarAfterMissedBlockAck
flag whether explicit BlockAckRequest should be sent upon missed BlockAck Response
Definition: qos-txop.h:477
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.
Definition: qos-txop.cc:212
void NotifyOriginatorAgreementNoReply(const Mac48Address &recipient, uint8_t tid)
Take action upon notification of ADDBA_REQUEST frame being discarded (likely due to exceeded max retr...
Definition: qos-txop.cc:691
virtual std::optional< Time > GetTxopStartTime(uint8_t linkId) const
Definition: qos-txop.cc:591
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...
Definition: qos-txop.cc:179
void ResetBa(Mac48Address recipient, uint8_t tid)
Reset BA agreement after BA negotiation failed.
Definition: qos-txop.cc:753
Time GetFailedAddBaTimeout() const
Get the timeout for failed BA agreement.
Definition: qos-txop.cc:788
void GotAddBaResponse(const MgtAddBaResponseHeader &respHdr, Mac48Address recipient)
Event handler when an ADDBA response is received.
Definition: qos-txop.cc:652
static TypeId GetTypeId()
Get the type ID.
Definition: qos-txop.cc:59
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...
Definition: qos-txop.cc:566
void SetFailedAddBaTimeout(Time failedAddBaTimeout)
Set the timeout for failed BA agreement.
Definition: qos-txop.cc:781
uint16_t m_blockAckInactivityTimeout
the BlockAck inactivity timeout value (in TUs, i.e.
Definition: qos-txop.h:473
QosLinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
Definition: qos-txop.cc:173
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...
Definition: qos-txop.cc:495
void SetBlockAckThreshold(uint8_t threshold)
Set threshold for block ack mechanism.
Definition: qos-txop.cc:712
bool IsQosOldPacket(Ptr< const WifiMpdu > mpdu)
Check if the given MPDU is to be considered old according to the current starting sequence number of ...
Definition: qos-txop.cc:356
void GotDelBaFrame(const MgtDelBaHeader *delBaHdr, Mac48Address recipient)
Event handler when a DELBA frame is received.
Definition: qos-txop.cc:683
void SetBlockAckInactivityTimeout(uint16_t timeout)
Set the BlockAck inactivity timeout.
Definition: qos-txop.cc:720
uint8_t m_nMaxInflights
the maximum number of links on which an MPDU can be in-flight at the same time
Definition: qos-txop.h:479
void CompleteMpduTx(Ptr< WifiMpdu > mpdu)
Stores an MPDU (part of an A-MPDU) in block ack agreement (i.e.
Definition: qos-txop.cc:698
void SetAddBaResponseTimeout(Time addBaResponseTimeout)
Set the timeout to wait for ADDBA response.
Definition: qos-txop.cc:768
std::pair< CtrlBAckRequestHeader, WifiMacHeader > PrepareBlockAckRequest(Mac48Address recipient, uint8_t tid) const
Definition: qos-txop.cc:304
bool HasFramesToTransmit(uint8_t linkId) override
Check if the Txop has frames to transmit over the given link.
Definition: qos-txop.cc:333
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:298
bool IsQosTxop() const override
Check for QoS TXOP.
Definition: qos-txop.cc:794
Time m_addBaResponseTimeout
timeout for ADDBA response
Definition: qos-txop.h:475
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...
Definition: qos-txop.cc:580
void SetMuEdcaTimer(Time timer, uint8_t linkId)
Set the MU EDCA Timer for the given link.
Definition: qos-txop.cc:219
Ptr< BlockAckManager > m_baManager
the block ack manager
Definition: qos-txop.h:468
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:605
bool IsSuccess() const
Return whether the status code is success.
Definition: status-code.cc:42
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
static Time Min()
Minimum representable Time Not to be confused with Min(Time,Time).
Definition: nstime.h:287
@ MS
millisecond
Definition: nstime.h:117
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
Definition: nstime.h:342
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:74
Ptr< WifiMac > m_mac
the wifi MAC
Definition: txop.h:555
Ptr< WifiMacQueue > m_queue
the wifi MAC queue
Definition: txop.h:553
void StartAccessAfterEvent(uint8_t linkId, bool hadFramesToTransmit, bool checkMediumBusy)
Request channel access on the given link after the occurrence of an event that possibly requires to g...
Definition: txop.cc:572
void DoDispose() override
Destructor implementation.
Definition: txop.cc:153
uint32_t GetMinCw() const
Return the minimum contention window size.
Definition: txop.cc:418
@ NOT_REQUESTED
Definition: txop.h:103
LinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
Definition: txop.cc:170
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
Definition: txop.h:552
const std::map< uint8_t, std::unique_ptr< LinkEntity > > & GetLinks() const
Definition: txop.cc:179
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
Definition: txop.cc:220
virtual void GenerateBackoff(uint8_t linkId)
Generate a new backoff for the given link now.
Definition: txop.cc:646
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
Definition: txop.h:554
static constexpr bool CHECK_MEDIUM_BUSY
generation of backoff (also) depends on the busy/idle state of the medium
Definition: txop.h:419
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...
Definition: txop.cc:617
void RequestAccess(uint8_t linkId)
Request access to the ChannelAccessManager associated with the given link.
Definition: txop.cc:636
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
Definition: txop.cc:466
uint32_t GetMaxCw() const
Return the maximum contention window size.
Definition: txop.cc:442
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
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.
uint16_t GetSequenceNumber() const
Return the sequence number of the header.
void SetNoMoreFragments()
Un-set the More Fragment bit in the Frame Control Field.
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
void SetDsNotFrom()
Un-set the From DS bit in the Frame Control field.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
virtual void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
bool IsQosData() const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
void SetDsNotTo()
Un-set the To DS bit in the Frame Control field.
void SetNoRetry()
Un-set the Retry bit in the Frame Control field.
Ptr< FrameExchangeManager > GetFrameExchangeManager(uint8_t linkId=SINGLE_LINK_OP_ID) const
Get the Frame Exchange Manager associated with the given link.
Definition: wifi-mac.cc:864
std::optional< Mac48Address > GetMldAddress(const Mac48Address &remoteAddr) const
Definition: wifi-mac.cc:1632
Ptr< WifiMacQueueScheduler > GetMacQueueScheduler() const
Get the wifi MAC queue scheduler.
Definition: wifi-mac.cc:576
bool GetHtSupported() const
Return whether the device supports HT.
Definition: wifi-mac.cc:1761
Mac48Address GetLocalAddress(const Mac48Address &remoteAddr) const
Get the local MAC address used to communicate with a remote STA.
Definition: wifi-mac.cc:1645
OriginatorAgreementOptConstRef GetBaAgreementEstablishedAsOriginator(Mac48Address recipient, uint8_t tid) const
Definition: wifi-mac.cc:1679
virtual bool CanForwardPacketsTo(Mac48Address to) const =0
Return true if packets can be forwarded to the given destination, false otherwise.
Ptr< ChannelAccessManager > GetChannelAccessManager(uint8_t linkId=SINGLE_LINK_OP_ID) const
Get the Channel Access Manager associated with the given link.
Definition: wifi-mac.cc:870
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,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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.
Definition: object.h:579
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
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.
Definition: qos-utils.cc:134
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:182
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:73
@ WIFI_MAC_DROP_QOS_OLD_PACKET
Definition: wifi-mac.h:81
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
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...
Definition: callback.h:704
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
std::tuple< WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional< uint8_t > > WifiContainerQueueId
Tuple (queue type, receiver address 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.
Definition: time.cc:533
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:86
@ WIFI_MAC_CTL_BACKREQ
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
Definition: wifi-utils.cc:119
ns3::Time timeout
std::ofstream queueSize