A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
eht-frame-exchange-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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-emlsr-manager.h"
12#include "eht-phy.h"
13#include "emlsr-manager.h"
14
15#include "ns3/abort.h"
16#include "ns3/ap-wifi-mac.h"
17#include "ns3/log.h"
18#include "ns3/mgt-action-headers.h"
19#include "ns3/spectrum-signal-parameters.h"
20#include "ns3/sta-wifi-mac.h"
21#include "ns3/wifi-mac-queue.h"
22#include "ns3/wifi-net-device.h"
23#include "ns3/wifi-spectrum-phy-interface.h"
24
25#include <algorithm>
26
27#undef NS_LOG_APPEND_CONTEXT
28#define NS_LOG_APPEND_CONTEXT WIFI_FEM_NS_LOG_APPEND_CONTEXT
29
30namespace ns3
31{
32
33/**
34 * Additional time (exceeding 20 us) to wait for a PHY-RXSTART.indication when the PHY is
35 * decoding a PHY header.
36 *
37 * Values for aRxPHYStartDelay:
38 * - OFDM : 20 us (for 20 MHz) [Table 17-21 of 802.11-2020]
39 * - ERP-OFDM : 20 us [Table 18-5 of 802.11-2020]
40 * - HT : 28 us (HT-mixed), 24 us (HT-greenfield) [Table 19-25 of 802.11-2020]
41 * - VHT : 36 + 4 * max N_VHT-LTF + 4 = 72 us [Table 21-28 of 802.11-2020]
42 * - HE : 32 us (for HE SU and HE TB PPDUs)
43 * 32 + 4 * N_HE-SIG-B us (for HE MU PPDUs) [Table 27-54 of 802.11ax-2021]
44 * - EHT : 32 us (for EHT TB PPDUs)
45 * 32 + 4 * N_EHT-SIG us (for EHT MU PPDUs) [Table 36-70 of 802.11be D3.2]
46 */
47static constexpr uint8_t WAIT_FOR_RXSTART_DELAY_USEC = 52;
48
49NS_LOG_COMPONENT_DEFINE("EhtFrameExchangeManager");
50
52
55{
56 static TypeId tid =
57 TypeId("ns3::EhtFrameExchangeManager")
59 .AddConstructor<EhtFrameExchangeManager>()
60 .SetGroupName("Wifi")
61 .AddAttribute("EarlyTxopEndDetect",
62 "Whether the Duration/ID value of the frame being transmitted "
63 "or received can be used to early detect an ongoing TXOP end.",
64 BooleanValue(true),
67 return tid;
68}
69
74
79
80void
87
88void
90{
91 NS_LOG_FUNCTION(this << txVector << psduDuration.As(Time::MS));
92
93 HeFrameExchangeManager::RxStartIndication(txVector, psduDuration);
95}
96
97void
99{
100 if (auto protectionManager = GetProtectionManager())
101 {
102 protectionManager->SetLinkId(linkId);
103 }
104 if (auto ackManager = GetAckManager())
105 {
106 ackManager->SetLinkId(linkId);
107 }
108 m_msduAggregator->SetLinkId(linkId);
109 m_mpduAggregator->SetLinkId(linkId);
111}
112
115{
116 NS_LOG_FUNCTION(this << *mpdu);
117
118 // alias needs only be created for non-broadcast QoS data frames exchanged between two MLDs
119 if (auto staMac = DynamicCast<StaWifiMac>(m_mac);
120 !mpdu->GetHeader().IsQosData() ||
121 (staMac ? (staMac->GetAssocType() == WifiAssocType::LEGACY) : (m_mac->GetNLinks() == 1)) ||
122 mpdu->GetHeader().GetAddr1().IsGroup() ||
123 !GetWifiRemoteStationManager()->GetMldAddress(mpdu->GetHeader().GetAddr1()))
124 {
126 }
127
128 mpdu = mpdu->CreateAlias(m_linkId);
129 auto& hdr = mpdu->GetHeader();
130 hdr.SetAddr2(GetAddress());
131 auto address = GetWifiRemoteStationManager()->GetAffiliatedStaAddress(hdr.GetAddr1());
132 NS_ASSERT(address);
133 hdr.SetAddr1(*address);
134 /*
135 * Set Address3 according to Table 9-30 of 802.11-2020 and Section 35.3.3 of
136 * 802.11be D2.0 ["the value of the Address 3 field and the Address 4 field (if present)
137 * in the MAC header of a data frame shall be set based on Table 9-30 (Address field
138 * contents) and the settings of the To DS and From DS bits, where the BSSID is the
139 * MAC address of the AP affiliated with the AP MLD corresponding to that link"].
140 */
141 if (hdr.IsQosAmsdu())
142 {
143 if (hdr.IsToDs() && !hdr.IsFromDs())
144 {
145 // from STA to AP: BSSID is in Address1
146 hdr.SetAddr3(hdr.GetAddr1());
147 }
148 else if (!hdr.IsToDs() && hdr.IsFromDs())
149 {
150 // from AP to STA: BSSID is in Address2
151 hdr.SetAddr3(hdr.GetAddr2());
152 }
153 }
154
155 return mpdu;
156}
157
158void
160{
161 // Override FrameExchangeManager::PrepareFrameToSend to create an MPDU alias in case of
162 // frame exchange between two MLDs.
164}
165
166bool
168{
169 if (!m_staMac || !m_staMac->IsEmlsrLink(m_linkId))
170 {
171 return false;
172 }
173 return m_staMac->GetMacQueueScheduler()->GetAllQueuesBlockedOnLink(
174 m_linkId,
177}
178
179bool
181{
182 auto recipientMld = m_mac->GetMldAddress(recipient);
183
184 if (!recipientMld.has_value())
185 {
186 return HeFrameExchangeManager::CanTransmitBarTo(recipient, tid);
187 }
188
189 // we don't check if the TID is mapped on this link if this is an adhoc STA
190 if (m_adhocMac)
191 {
192 return HeFrameExchangeManager::CanTransmitBarTo(recipient, tid);
193 }
194
195 // Sec. 35.3.7.2.1 of 802.11be D7.0
196 // If a link is enabled for a non-AP MLD, then:
197 // - Individually addressed Management frames, QoS Null frames, and Control frames may be sent
198 // on any enabled links between the corresponding non-AP MLD and AP MLD both in DL and UL,
199 // except that a BlockAckReq frame requesting status for TID(s) that are not mapped to a link
200 // shall not be transmitted on the link by the corresponding non-AP STA affiliated with the
201 // non-AP MLD and by the corresponding AP affiliated with the AP MLD.
202 return m_mac->TidMappedOnLink(*recipientMld, WifiDirection::DOWNLINK, tid, m_linkId) &&
203 m_mac->TidMappedOnLink(*recipientMld, WifiDirection::UPLINK, tid, m_linkId);
204}
205
206bool
208{
209 NS_LOG_FUNCTION(this);
210
212 auto txopStartTime = m_edca->GetTxopStartTime(m_linkId);
213 NS_ASSERT_MSG(txopStartTime.has_value(), "A TXOP must be ongoing");
214 auto initialFrame = (txopStartTime.value() == Simulator::Now());
215
216 if (m_apMac)
217 {
219 }
220
221 if (initialFrame && m_staMac && m_staMac->IsEmlsrLink(m_linkId) &&
223 {
224 return false;
225 }
226
228
229 if (initialFrame && started)
230 {
231 if (m_staMac && m_staMac->IsEmlsrLink(m_linkId))
232 {
233 // notify the EMLSR Manager of the UL TXOP start on an EMLSR link
234 NS_ASSERT(m_staMac->GetEmlsrManager());
235 m_staMac->GetEmlsrManager()->NotifyUlTxopStart(m_linkId);
236 }
237
238 // we are starting a new TXOP, hence consider the previous ongoing TXOP as terminated
239 m_ongoingTxopEnd.Cancel();
240 }
241
242 return started;
243}
244
245void
247{
248 NS_LOG_FUNCTION(this);
249
250 for (linkId_t linkId = 0; linkId < m_apMac->GetNLinks(); linkId++)
251 {
252 if (linkId == m_linkId)
253 {
254 continue;
255 }
256
257 // EMLSR clients involved in a DL or UL TXOP on another link
258 std::set<Mac48Address> emlsrClients;
259 auto ehtFem = StaticCast<EhtFrameExchangeManager>(m_mac->GetFrameExchangeManager(linkId));
260
261 // check if an EMLSR client is the holder of an UL TXOP on the other link
262 if (ehtFem->m_ongoingTxopEnd.IsPending() && ehtFem->m_txopHolder &&
263 m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(
264 ehtFem->m_txopHolder.value()))
265 {
266 NS_LOG_DEBUG("Involved in UL TXOP: " << ehtFem->m_txopHolder.value());
267 emlsrClients.insert(ehtFem->m_txopHolder.value());
268 }
269
270 // check if EMLSR clients are involved in a DL TXOP on another link
271 for (const auto& address : ehtFem->m_protectedStas)
272 {
273 if (m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(address))
274 {
275 NS_LOG_DEBUG("Involved in DL TXOP: " << address);
276 emlsrClients.insert(address);
277 }
278 }
279
280 for (const auto& address : emlsrClients)
281 {
282 auto mldAddress = m_mac->GetWifiRemoteStationManager(linkId)->GetMldAddress(address);
283 NS_ASSERT_MSG(mldAddress, "MLD address not found for " << address);
284
285 if (!GetWifiRemoteStationManager()->GetEmlsrEnabled(*mldAddress))
286 {
287 // EMLSR client did not enable EMLSR mode on this link, we can transmit to it
288 continue;
289 }
290
291 // check that this link is blocked as expected
292 const auto queueId = MakeWifiUnicastQueueId(WIFI_QOSDATA_QUEUE, *mldAddress, 0);
293 auto mask = m_apMac->GetMacQueueScheduler()->GetQueueLinkMask(AC_BE, queueId, m_linkId);
294 NS_ASSERT_MSG(mask, "No mask for client " << *mldAddress << " on link " << +m_linkId);
295 if (!mask->test(
296 static_cast<std::size_t>(WifiQueueBlockedReason::USING_OTHER_EMLSR_LINK)))
297 {
298 NS_ASSERT_MSG(false,
299 "Transmissions to " << *mldAddress << " on link " << +m_linkId
300 << " are not blocked");
301 // in case asserts are disabled, block transmissions on the other links because
302 // this is what we need
304 *mldAddress,
305 {m_linkId});
306 }
307 }
308 }
309}
310
311bool
313{
314 NS_LOG_FUNCTION(this);
315
316 // Cannot start a transmission on a link blocked because another EMLSR link is being used
318 {
319 NS_LOG_DEBUG("StartTransmission called while another EMLSR link is being used");
320 return false;
321 }
322
323 auto emlsrManager = m_staMac->GetEmlsrManager();
324
325 if (auto elapsed = emlsrManager->GetElapsedMediumSyncDelayTimer(m_linkId);
326 elapsed && emlsrManager->MediumSyncDelayNTxopsExceeded(m_linkId))
327 {
328 NS_LOG_DEBUG("No new TXOP attempts allowed while MediumSyncDelay is running");
329 // request channel access if needed when the MediumSyncDelay timer expires; in the
330 // meantime no queued packet can be transmitted
332 emlsrManager->GetMediumSyncDuration() - *elapsed,
334 m_edca,
335 m_linkId,
336 Txop::DIDNT_HAVE_FRAMES_TO_TRANSMIT, // queued frames cannot be transmitted until
337 // MSD expires
338 Txop::DONT_CHECK_MEDIUM_BUSY); // generate backoff regardless of medium busy
339 return false;
340 }
341
342 if (!m_phy)
343 {
344 NS_LOG_DEBUG("No PHY is currently operating on EMLSR link " << +m_linkId);
345 return false;
346 }
347
348 // let EMLSR manager decide whether to prevent or allow this UL TXOP
349 if (const auto [startTxop, delay] =
350 emlsrManager->GetDelayUntilAccessRequest(m_linkId, m_edca->GetAccessCategory());
351 !startTxop)
352
353 {
354 if (delay.IsStrictlyPositive())
355 {
358 m_edca,
359 m_linkId,
360 Txop::DIDNT_HAVE_FRAMES_TO_TRANSMIT, // queued frames cannot be
361 // transmitted until RX ends
362 Txop::CHECK_MEDIUM_BUSY); // generate backoff if medium busy
363 }
364 return false;
365 }
366
367 return true;
368}
369
370void
372{
373 NS_LOG_FUNCTION(this);
374
375 if (m_staMac && m_staMac->GetEmlsrManager())
376 {
377 m_staMac->GetEmlsrManager()->NotifyProtectionCompleted(m_linkId);
378 }
379
381}
382
383void
385{
386 NS_LOG_FUNCTION(this << psdu << txVector);
387
388 // EHT-SIG, the equivalent of HE-SIG-B, is present in EHT SU transmissions, too
389 if (txVector.GetPreambleType() == WIFI_PREAMBLE_EHT_MU)
390 {
391 auto phy = std::static_pointer_cast<EhtPhy>(m_phy->GetPhyEntity(WIFI_MOD_CLASS_EHT));
392 auto sigBMode = phy->GetSigBMode(txVector);
393 txVector.SetSigBMode(sigBMode);
394 }
395
396 auto txDuration = WifiPhy::CalculateTxDuration(psdu, txVector, m_phy->GetPhyBand());
397
398 if (m_apMac && psdu->GetHeader(0).IsTrigger())
399 {
400 for (const auto& client : m_sentRtsTo)
401 {
402 if (!GetWifiRemoteStationManager()->GetEmlsrEnabled(client))
403 {
404 continue;
405 }
406 auto clientMld = GetWifiRemoteStationManager()->GetMldAddress(client);
407 NS_ASSERT(clientMld);
408
409 // block transmissions on the other EMLSR links of the EMLSR clients
410 for (uint8_t linkId = 0; linkId < m_apMac->GetNLinks(); ++linkId)
411 {
412 if (linkId != m_linkId &&
413 m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(*clientMld))
414 {
416 *clientMld,
417 {linkId});
418 }
419 }
420 }
421 }
422
423 if (m_staMac && m_staMac->IsEmlsrLink(m_linkId) && psdu->GetAddr1() == m_bssid &&
424 psdu->GetHeader(0).IsRts())
425 {
426 NS_ASSERT(m_staMac->GetEmlsrManager());
427 m_staMac->GetEmlsrManager()->NotifyRtsSent(m_linkId, psdu, txVector);
428 }
429
431 UpdateTxopEndOnTxStart(txDuration, psdu->GetDuration());
432
433 if (m_apMac && m_apMac->GetApEmlsrManager())
434 {
435 auto delay = m_apMac->GetApEmlsrManager()->GetDelayOnTxPsduNotForEmlsr(psdu,
436 txVector,
437 m_phy->GetPhyBand());
438
439 // check if the EMLSR clients shall switch back to listening operation
440 for (auto clientIt = m_protectedStas.begin(); clientIt != m_protectedStas.end();)
441 {
442 auto aid = GetWifiRemoteStationManager()->GetAssociationId(*clientIt);
443
444 if (GetWifiRemoteStationManager()->GetEmlsrEnabled(*clientIt) &&
445 GetEmlsrSwitchToListening(psdu, aid, *clientIt))
446 {
447 EmlsrSwitchToListening(*clientIt, delay);
448 // this client is no longer involved in the current TXOP
449 clientIt = m_protectedStas.erase(clientIt);
450 }
451 else
452 {
453 clientIt++;
454 }
455 }
456 }
457 else if (m_staMac && m_staMac->IsEmlsrLink(m_linkId) &&
458 m_staMac->GetEmlsrManager()->GetInDeviceInterference())
459 {
460 NS_ASSERT(m_staMac->GetEmlsrManager());
461 m_staMac->GetEmlsrManager()->NotifyInDeviceInterferenceStart(m_linkId, txDuration);
462 GenerateInDeviceInterferenceForAll(txDuration, txVector);
463 }
464}
465
466void
468{
469 NS_LOG_FUNCTION(this << psduMap << txVector);
470
471 auto txDuration = WifiPhy::CalculateTxDuration(psduMap, txVector, m_phy->GetPhyBand());
472
474 UpdateTxopEndOnTxStart(txDuration, psduMap.begin()->second->GetDuration());
475
476 if (m_apMac)
477 {
478 // check if this is a BSRP TF used as ICF for some EMLSR client
479 if (IsTrigger(psduMap))
480 {
481 CtrlTriggerHeader trigger;
482 psduMap.cbegin()->second->GetPayload(0)->PeekHeader(trigger);
483
484 if (trigger.IsBsrp())
485 {
486 auto recipients = GetTfRecipients(trigger);
487 for (const auto& client : recipients)
488 {
489 if (!GetWifiRemoteStationManager()->GetEmlsrEnabled(client))
490 {
491 continue;
492 }
493 auto clientMld = GetWifiRemoteStationManager()->GetMldAddress(client);
494 NS_ASSERT(clientMld);
495
496 // block transmissions on the other EMLSR links of the EMLSR clients
497 for (uint8_t linkId = 0; linkId < m_apMac->GetNLinks(); ++linkId)
498 {
499 if (linkId != m_linkId &&
500 m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(*clientMld))
501 {
502 m_mac->BlockUnicastTxOnLinks(
504 *clientMld,
505 {linkId});
506 }
507 }
508 }
509 }
510 }
511
512 // check if the EMLSR clients shall switch back to listening operation at the end of this
513 // PPDU
514 for (auto clientIt = m_protectedStas.begin(); clientIt != m_protectedStas.end();)
515 {
516 auto aid = GetWifiRemoteStationManager()->GetAssociationId(*clientIt);
517 const auto psduMapIt = psduMap.find(aid);
518 const auto aidNotFoundAndNotTf = (psduMapIt == psduMap.cend()) && !IsTrigger(psduMap);
519 // the PSDU to process: the one addressed to the given AID (if any) or the unique one
520 const auto psdu = (psduMapIt != psduMap.cend() ? psduMapIt : psduMap.begin())->second;
521
522 if (GetWifiRemoteStationManager()->GetEmlsrEnabled(*clientIt) &&
523 (aidNotFoundAndNotTf || GetEmlsrSwitchToListening(psdu, aid, *clientIt)))
524 {
525 EmlsrSwitchToListening(*clientIt, txDuration);
526 // this client is no longer involved in the current TXOP
527 clientIt = m_protectedStas.erase(clientIt);
528 }
529 else
530 {
531 clientIt++;
532 }
533 }
534 }
535 else if (m_staMac && m_staMac->IsEmlsrLink(m_linkId) &&
536 m_staMac->GetEmlsrManager()->GetInDeviceInterference())
537 {
538 NS_ASSERT(m_staMac->GetEmlsrManager());
539 m_staMac->GetEmlsrManager()->NotifyInDeviceInterferenceStart(m_linkId, txDuration);
540 GenerateInDeviceInterferenceForAll(txDuration, txVector);
541 }
542}
543
544void
546 const WifiTxVector& txVector)
547{
548 NS_LOG_FUNCTION(this << txDuration.As(Time::MS) << txVector);
549
551 NS_ASSERT(m_staMac->GetEmlsrManager());
552
553 for (const auto& phy : m_staMac->GetDevice()->GetPhys())
554 {
555 // generate in-device interference for a PHY provided that:
556 // - the PHY is not the one the client is using to transmit
557 // - either the PHY is not operating on any link or it is operating on an EMLSR link
558 // Interference is generated for the duration of this transmission
559 if (auto id = m_staMac->GetLinkForPhy(phy);
560 phy != m_phy && (!id || m_staMac->IsEmlsrLink(*id)))
561 {
562 const auto txPower = phy->GetPower(txVector.GetTxPowerLevel()) + phy->GetTxGain();
563 GenerateInDeviceInterference(phy, txDuration, DbmToW(txPower));
564 }
565 }
566}
567
568void
570 Time duration,
571 Watt_u txPower)
572{
573 NS_LOG_FUNCTION(this << phy << duration.As(Time::US) << txPower);
574
575 auto rxPhy = DynamicCast<SpectrumWifiPhy>(phy);
576
577 if (!rxPhy)
578 {
579 NS_LOG_DEBUG("No spectrum PHY");
580 return;
581 }
582
584 NS_ASSERT(txPhy);
585
586 for (const auto& [range, interface] : rxPhy->GetSpectrumPhyInterfaces())
587 {
588 if (!interface->GetRxSpectrumModel())
589 {
590 // we may have created a PHY interface but never set a frequency channel comprised
591 // in the frequency range associated with that PHY interface, thus the RX spectrum
592 // model may have not been created
593 continue;
594 }
595
596 auto psd = Create<SpectrumValue>(interface->GetRxSpectrumModel());
597 *psd = txPower;
598
599 auto spectrumSignalParams = Create<SpectrumSignalParameters>();
600 spectrumSignalParams->duration = duration;
601 spectrumSignalParams->txPhy = txPhy->GetCurrentInterface();
602 spectrumSignalParams->txAntenna = txPhy->GetAntenna();
603 spectrumSignalParams->psd = psd;
604
605 rxPhy->StartRx(spectrumSignalParams, interface);
606 }
607}
608
609void
611{
612 NS_LOG_FUNCTION(this);
614 {
615 // the CTS may have been missed because another EMLSR link is being used; do not reset NAV
616 return;
617 }
619}
620
621void
623{
624 NS_LOG_FUNCTION(this);
626 {
627 // the CTS may have been missed because another EMLSR link is being used; do not reset NAV
628 return;
629 }
631}
632
633bool
635{
636 NS_LOG_FUNCTION(this << address << checkThisLink);
637
638 auto mldAddress = GetWifiRemoteStationManager()->GetMldAddress(address);
639 NS_ASSERT_MSG(mldAddress, "MLD address not found for " << address);
640 NS_ASSERT_MSG(m_apMac, "This function shall only be called by AP MLDs");
641 std::set<uint8_t> linkIds{m_linkId};
642
643 /**
644 * Do nothing if the EMLSR client is involved in a DL or UL TXOP on another EMLSR link. This
645 * may happen, e.g., when the AP MLD sent an MU-RTS to multiple stations on this link, some of
646 * which responded, but this EMLSR client did not, e.g., because it concurrently started an UL
647 * TXOP on another link. The AP MLD then started a (long) DL MU transmission on this link,
648 * during which the EMLSR client completed the UL TXOP and started being involved in another
649 * DL or UL TXOP (note that DL TXOP is possible because the AP MLD considered the EMLSR client
650 * unprotected as soon as it detected the start of the previous UL TXOP). A Block Ack timeout
651 * for the EMLSR client occurs at the end of the DL MU transmission (which brings us here) and
652 * it may occur while the EMLSR client is still involved in a DL or UL TXOP.
653 *
654 * ┌─────────────┐ ┌───────────────┐
655 * │ MU-RTS to │ │ Data to │ BA timeout for us
656 * │us and others│ │ us and others │ |
657 * ────────┴─────────────┴┬────────┬┴───────────────┴┬───────┬──────────────
658 * [this link] │CTS from│ │BA from│
659 * │ others │ │ others│
660 * └────────┘ └───────┘
661 * ┌───────┐
662 * ┌───┐ ┌──┐ │ MU-RTS│ ┌──────┐
663 * [other link] │CTS│ │BA│ │ to us │ │ Data │
664 * ─────────┬────────┬┴───┴┬────┬┴──┴──────┴───────┴┬───┬┴──────┴┬──┬───────
665 * │ RTS │ │Data│ │CTS│ │BA│
666 * │from us │ └────┘ └───┘ └──┘
667 * └────────┘
668 */
669
670 for (uint8_t linkId = 0; linkId < m_apMac->GetNLinks(); ++linkId)
671 {
672 if (!m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(*mldAddress))
673 {
674 continue; // not an EMLSR link
675 }
676
677 auto ehtFem = StaticCast<EhtFrameExchangeManager>(m_mac->GetFrameExchangeManager(linkId));
678
679 if (ehtFem->m_ongoingTxopEnd.IsPending() && ehtFem->m_txopHolder &&
680 m_mac->GetWifiRemoteStationManager(linkId)->GetMldAddress(*ehtFem->m_txopHolder) ==
681 mldAddress)
682 {
683 NS_LOG_DEBUG("EMLSR client " << *mldAddress << " is the holder of an UL TXOP on link "
684 << +linkId << ", do not unblock links");
685 return false;
686 }
687
688 if (linkId == m_linkId && !checkThisLink)
689 {
690 continue;
691 }
692
693 linkIds.insert(linkId);
694
695 if (auto linkAddr =
696 m_apMac->GetWifiRemoteStationManager(linkId)->GetAffiliatedStaAddress(*mldAddress);
697 linkAddr &&
698 (ehtFem->m_sentRtsTo.contains(*linkAddr) || ehtFem->m_sentFrameTo.contains(*linkAddr) ||
699 ehtFem->m_protectedStas.contains(*linkAddr)))
700 {
701 NS_LOG_DEBUG("EMLSR client " << address
702 << " has been sent an ICF, do not unblock links");
703 return false;
704 }
705 }
706
707 // unblock DL transmissions with reason USING_OTHER_EMLSR_LINK
709 *mldAddress,
710 linkIds);
711 return true;
712}
713
714void
716{
717 NS_LOG_FUNCTION(this << address << delay.As(Time::US));
718
719 auto mldAddress = GetWifiRemoteStationManager()->GetMldAddress(address);
720 NS_ASSERT_MSG(mldAddress, "MLD address not found for " << address);
721 NS_ASSERT_MSG(m_apMac, "This function shall only be called by AP MLDs");
722
723 auto blockLinks = [=, this](bool checkThisLink) {
724 if (!UnblockEmlsrLinksIfAllowed(address, checkThisLink))
725 {
726 NS_LOG_DEBUG("Could not unblock transmissions to " << address);
727 return;
728 }
729
730 // this EMLSR client switches back to listening operation
731 std::set<uint8_t> linkIds;
732 for (uint8_t linkId = 0; linkId < m_mac->GetNLinks(); linkId++)
733 {
734 if (m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(*mldAddress))
735 {
736 linkIds.insert(linkId);
737 }
738 }
739
740 // block DL transmissions on this link until transition delay elapses
742 *mldAddress,
743 linkIds);
744
745 auto unblockLinks = [=, this]() {
747 *mldAddress,
748 linkIds);
749 };
750
751 // unblock all EMLSR links when the transition delay elapses
752 auto emlCapabilities = GetWifiRemoteStationManager()->GetStationEmlCapabilities(address);
753 NS_ASSERT(emlCapabilities);
755 emlCapabilities->get().emlsrTransitionDelay);
756
757 endDelay.IsZero() ? unblockLinks()
758 : static_cast<void>(m_transDelayTimer[*mldAddress] =
759 Simulator::Schedule(endDelay, unblockLinks));
760 };
761
762 // it makes sense to check if the EMLSR client is involved in a DL TXOP on this link only if
763 // the transition delay start is scheduled to start after some delay, because the AP MLD may
764 // start another DL TXOP in the meantime. An example is when the AP MLD terminates a TXOP on
765 // this link due to the remaining TXOP time being not enough to send another frame (not even a
766 // CF-End), delays the start of the transition delay to align with the EMLSR client (which is
767 // waiting for a SIFS + slot + PHY RXSTART delay after the last frame to switch to listening
768 // operations), gains channel access on this link again before starting the transition delay
769 // timer and sends an ICF.
770 delay.IsZero() ? blockLinks(false)
771 : static_cast<void>(Simulator::Schedule(delay, [=]() { blockLinks(true); }));
772}
773
774void
776{
777 NS_LOG_FUNCTION(this << phy << linkId << delay.As(Time::US));
778
779 // TODO Shall we assert that there is no ongoing frame exchange sequence? Or is it possible
780 // that there is an ongoing frame exchange sequence (in such a case, we need to force a
781 // timeout, just like it is done in case of a normal channel switch
782
783 NS_ABORT_MSG_IF(!m_staMac, "This method can only be called on a STA");
784
785 // if we receive the notification from a PHY that is not connected to us, it means that
786 // we have been already connected to another PHY operating on this link, hence we do not
787 // have to reset the connected PHY. Similarly, we do not have to reset the connected PHY if
788 // the link does not change (this occurs when changing the channel width of aux PHYs upon
789 // enabling the EMLSR mode).
790 if (phy == m_phy && linkId != m_linkId)
791 {
792 ResetPhy();
793 }
794 m_staMac->NotifySwitchingEmlsrLink(phy, linkId, delay);
795}
796
797void
799{
800 NS_LOG_FUNCTION(this << dest << frame);
801
802 WifiMacHeader hdr;
804 hdr.SetAddr1(dest);
805 hdr.SetAddr2(m_self);
806 hdr.SetAddr3(m_bssid);
807 hdr.SetDsNotTo();
808 hdr.SetDsNotFrom();
809
810 const auto sequence = m_txMiddle->GetNextSequenceNumberFor(&hdr);
811 hdr.SetSequenceNumber(sequence);
812
813 WifiActionHeader actionHdr;
817
818 m_mac->EnqueueMgt(hdr, {frame, actionHdr}, m_linkId);
819}
820
821std::optional<dBm_u>
823{
824 auto optRssi = HeFrameExchangeManager::GetMostRecentRssi(address);
825
826 if (optRssi)
827 {
828 return optRssi;
829 }
830
831 auto mldAddress = GetWifiRemoteStationManager()->GetMldAddress(address);
832
833 if (!mldAddress)
834 {
835 // not an MLD, nothing else can be done
836 return std::nullopt;
837 }
838
839 for (uint8_t linkId = 0; linkId < m_mac->GetNLinks(); linkId++)
840 {
841 std::optional<Mac48Address> linkAddress;
842 if (linkId != m_linkId &&
843 (linkAddress = m_mac->GetWifiRemoteStationManager(linkId)->GetAffiliatedStaAddress(
844 *mldAddress)) &&
845 (optRssi = m_mac->GetWifiRemoteStationManager(linkId)->GetMostRecentRssi(*linkAddress)))
846 {
847 return optRssi;
848 }
849 }
850
851 return std::nullopt;
852}
853
854void
856 WifiTxVector& txVector) const
857{
858 NS_LOG_FUNCTION(this << trigger << txVector);
859
860 if (!trigger.IsMuRts() && !trigger.IsBsrp())
861 {
862 NS_LOG_INFO("Not an ICF");
863 return;
864 }
865
866 const auto recipients = GetTfRecipients(trigger);
867 uint8_t maxPaddingDelay = 0;
868 bool isUnprotectedEmlsrDst = false;
869
870 for (const auto& address : recipients)
871 {
872 if (!GetWifiRemoteStationManager()->GetEmlsrEnabled(address) ||
873 m_protectedStas.contains(address))
874 {
875 continue; // not an EMLSR client or EMLSR client already protected
876 }
877
878 isUnprotectedEmlsrDst = true;
879 auto emlCapabilities = GetWifiRemoteStationManager()->GetStationEmlCapabilities(address);
880 NS_ASSERT(emlCapabilities);
881 maxPaddingDelay = std::max(maxPaddingDelay, emlCapabilities->get().emlsrPaddingDelay);
882 }
883
884 if (isUnprotectedEmlsrDst)
885 {
886 // The initial Control frame of frame exchanges shall be sent in the non-HT PPDU or
887 // non-HT duplicate PPDU format using a rate of 6 Mb/s, 12 Mb/s, or 24 Mb/s.
888 // (Sec. 35.3.17 of 802.11be D3.0)
889 GetWifiRemoteStationManager()->AdjustTxVectorForIcf(txVector);
890 }
891
892 // add padding (if needed)
893 if (maxPaddingDelay > 0)
894 {
895 // see formula (35-1) in Sec. 35.5.2.2.3 of 802.11be D3.0
896 auto rate = txVector.GetMode().GetDataRate(txVector);
897 std::size_t nDbps = rate / 1e6 * 4; // see Table 17-4 of 802.11-2020
898 trigger.SetPaddingSize((1 << (maxPaddingDelay + 2)) * nDbps / 8);
899 }
900}
901
902void
904{
905 NS_LOG_FUNCTION(this << sender);
906
907 // an EMLSR client responding to a BSRP TF must be considered protected
908 if (GetWifiRemoteStationManager()->GetEmlsrEnabled(sender))
909 {
910 m_protectedStas.insert(sender);
911 }
912
914}
915
916bool
918{
920 if (m_staMac->IsEmlsrLink(m_linkId))
921 {
922 auto mainPhy = m_staMac->GetDevice()->GetPhy(m_staMac->GetEmlsrManager()->GetMainPhyId());
923
924 // while an ICF is being received on this link, an aux PHY that is not TX capable may get
925 // a TXOP on another link, release the channel and request the main PHY to switch channel.
926 // It may be decided to have the main PHY start a TXOP on the other link a PIFS after the
927 // channel switch (e.g., MAC header information is not used and AllowUlTxopInRx is true).
928 // Thus, when the ICF is received on this link, it is not dropped but, when the CTS must
929 // be transmitted, the main PHY has already started transmitting on the other link. In
930 // such a case, do not respond to the ICF.
931 if (mainPhy->IsStateSwitching() || m_mac->GetLinkForPhy(mainPhy) != m_linkId)
932 {
933 NS_LOG_DEBUG("Main PHY is switching or operating on another link, abort ICF response");
934 return true;
935 }
936 }
937 return false;
938}
939
940void
942 const CtrlTriggerHeader& trigger,
943 double muRtsSnr)
944{
945 NS_LOG_FUNCTION(this << muRtsHdr << trigger << muRtsSnr);
946
948 {
949 return;
950 }
951 HeFrameExchangeManager::SendCtsAfterMuRts(muRtsHdr, trigger, muRtsSnr);
952}
953
954void
956 const WifiMacHeader& hdr)
957{
958 NS_LOG_FUNCTION(this << trigger << hdr);
959
960 if (trigger.IsBsrp() && EmlsrClientCannotRespondToIcf())
961 {
962 return;
963 }
965}
966
967void
969{
970 NS_LOG_FUNCTION(this);
971
972 for (const auto& address : clients)
973 {
974 if (GetWifiRemoteStationManager()->GetEmlsrEnabled(address))
975 {
976 // EMLSR client switched to listening operations if it was protected, otherwise
977 // simply unblock transmissions
978 m_protectedStas.contains(address) ? EmlsrSwitchToListening(address, Time{0})
979 : (void)(UnblockEmlsrLinksIfAllowed(address, false));
980 m_protectedStas.erase(address);
981 }
982 }
983}
984
985void
992
993bool
995{
996 NS_LOG_FUNCTION(this);
997
998 if (m_apMac)
999 {
1000 if (const auto apEmlsrManager = m_apMac->GetApEmlsrManager();
1001 apEmlsrManager && IsCrossLinkCollision(m_sentRtsTo))
1002 {
1003 return apEmlsrManager->UpdateCwAfterFailedIcf();
1004 }
1005 }
1006
1008}
1009
1010bool
1012{
1013 NS_LOG_FUNCTION(this);
1014
1015 if (m_apMac)
1016 {
1017 if (const auto apEmlsrManager = m_apMac->GetApEmlsrManager();
1018 apEmlsrManager && IsCrossLinkCollision(m_sentRtsTo))
1019 {
1020 return apEmlsrManager->ReportFailedIcf();
1021 }
1022 }
1023
1025}
1026
1027void
1028EhtFrameExchangeManager::TbPpduTimeout(WifiPsduMap* psduMap, std::size_t nSolicitedStations)
1029{
1030 NS_LOG_FUNCTION(this << psduMap << nSolicitedStations);
1031
1032 const auto& staMissedTbPpduFrom = m_txTimer.GetStasExpectedToRespond();
1033 const auto crossLinkCollision = IsCrossLinkCollision(staMissedTbPpduFrom);
1034
1035 if (staMissedTbPpduFrom.size() != nSolicitedStations)
1036 {
1037 // some STAs replied, hence the transmission succeeded. EMLSR clients that did not
1038 // respond are switching back to listening operations
1039 SwitchToListeningOrUnblockLinks(staMissedTbPpduFrom);
1040 }
1041
1042 const auto apEmlsrManager = m_apMac->GetApEmlsrManager();
1043 const auto updateFailedCw =
1044 crossLinkCollision && apEmlsrManager ? apEmlsrManager->UpdateCwAfterFailedIcf() : true;
1045 DoTbPpduTimeout(psduMap, nSolicitedStations, updateFailedCw);
1046}
1047
1048void
1050 std::size_t nSolicitedStations)
1051{
1052 NS_LOG_FUNCTION(this << psduMap << nSolicitedStations);
1053
1054 const auto& staMissedTbPpduFrom = m_txTimer.GetStasExpectedToRespond();
1055
1056 if (staMissedTbPpduFrom.size() != nSolicitedStations)
1057 {
1058 // some STAs replied, hence the transmission succeeded. EMLSR clients that did not
1059 // respond are switching back to listening operations
1060 SwitchToListeningOrUnblockLinks(staMissedTbPpduFrom);
1061 }
1062
1063 HeFrameExchangeManager::BlockAcksInTbPpduTimeout(psduMap, nSolicitedStations);
1064}
1065
1066bool
1068 const std::set<Mac48Address>& staMissedResponseFrom) const
1069{
1070 NS_LOG_FUNCTION(this << staMissedResponseFrom.size());
1071
1072 // check if all the clients that did not respond to the ICF are EMLSR clients that have sent
1073 // (or are sending) a frame to the AP on another link
1074 auto crossLinkCollision = true;
1075
1076 // we blocked transmissions on the other EMLSR links for the EMLSR clients we sent the ICF to.
1077 // For clients that did not respond, we can unblock transmissions if there is no ongoing
1078 // UL TXOP held by that client
1079 for (const auto& address : staMissedResponseFrom)
1080 {
1081 if (!GetWifiRemoteStationManager()->GetEmlsrEnabled(address))
1082 {
1083 crossLinkCollision = false;
1084 continue;
1085 }
1086
1087 auto mldAddress = GetWifiRemoteStationManager()->GetMldAddress(address);
1088 NS_ASSERT(mldAddress);
1089
1090 std::set<uint8_t> linkIds; // all EMLSR links of EMLSR client
1091 for (uint8_t linkId = 0; linkId < m_apMac->GetNLinks(); linkId++)
1092 {
1093 if (m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(*mldAddress) &&
1094 linkId != m_linkId)
1095 {
1096 linkIds.insert(linkId);
1097 }
1098 }
1099
1100 if (std::any_of(linkIds.cbegin(),
1101 linkIds.cend(),
1102 /* lambda returning true if an UL TXOP is ongoing on the given link ID */
1103 [=, this](uint8_t id) {
1104 auto ehtFem = StaticCast<EhtFrameExchangeManager>(
1105 m_mac->GetFrameExchangeManager(id));
1106 return ehtFem->m_ongoingTxopEnd.IsPending() && ehtFem->m_txopHolder &&
1107 m_mac->GetMldAddress(ehtFem->m_txopHolder.value()) == mldAddress;
1108 }))
1109 {
1110 // an UL TXOP is ongoing on one EMLSR link, do not unblock links
1111 continue;
1112 }
1113
1114 // no UL TXOP is ongoing on any EMLSR link; if the EMLSR client is not transmitting a
1115 // frame to the AP on any EMLSR link, then the lack of response to the MU-RTS was not
1116 // caused by a simultaneous UL transmission
1117 if (std::none_of(linkIds.cbegin(),
1118 linkIds.cend(),
1119 /* lambda returning true if an MPDU from the EMLSR client is being received
1120 on the given link ID */
1121 [=, this](uint8_t id) {
1122 auto macHdr = m_mac->GetFrameExchangeManager(id)->GetReceivedMacHdr();
1123 if (!macHdr.has_value())
1124 {
1125 return false;
1126 }
1127 auto addr2 = macHdr->get().GetAddr2();
1128 return m_mac->GetMldAddress(addr2) == mldAddress;
1129 }))
1130 {
1131 crossLinkCollision = false;
1132 }
1133 }
1134
1135 return crossLinkCollision;
1136}
1137
1138void
1140 const WifiTxVector& rtsTxVector,
1141 double rtsSnr)
1142{
1143 NS_LOG_FUNCTION(this << rtsHdr << rtsTxVector << rtsSnr);
1144
1145 auto addr2 = rtsHdr.GetAddr2();
1146
1147 if (m_apMac && GetWifiRemoteStationManager()->GetEmlsrEnabled(addr2))
1148 {
1149 // we are going to send a CTS to an EMLSR client, transmissions to such EMLSR client
1150 // must be blocked on the other EMLSR links
1151
1152 auto mldAddress = GetWifiRemoteStationManager()->GetMldAddress(addr2);
1153 NS_ASSERT_MSG(mldAddress, "MLD address not found for " << addr2);
1154
1155 for (uint8_t linkId = 0; linkId < m_apMac->GetNLinks(); ++linkId)
1156 {
1157 if (linkId != m_linkId &&
1158 m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(*mldAddress))
1159 {
1160 // check that other links are blocked as expected
1161 const auto queueId = MakeWifiUnicastQueueId(WIFI_QOSDATA_QUEUE, *mldAddress, 0);
1162 auto mask =
1163 m_apMac->GetMacQueueScheduler()->GetQueueLinkMask(AC_BE, queueId, linkId);
1164 NS_ASSERT_MSG(mask, "No mask for client " << *mldAddress << " on link " << +linkId);
1165 if (!mask->test(
1166 static_cast<std::size_t>(WifiQueueBlockedReason::USING_OTHER_EMLSR_LINK)))
1167 {
1168 NS_ASSERT_MSG(false,
1169 "Transmissions to " << *mldAddress << " on link " << +linkId
1170 << " are not blocked");
1171 // in case asserts are disabled, block transmissions on the other links because
1172 // this is what we need
1174 *mldAddress,
1175 {linkId});
1176 }
1177 }
1178 }
1179 }
1180
1181 HeFrameExchangeManager::SendCtsAfterRts(rtsHdr, rtsTxVector, rtsSnr);
1182}
1183
1184bool
1186 uint16_t aid,
1187 const Mac48Address& address) const
1188{
1189 NS_LOG_FUNCTION(this << psdu << aid << address);
1190
1191 // Sec. 35.3.17 of 802.11be D3.0:
1192 // The non-AP MLD shall be switched back to the listening operation on the EMLSR links after
1193 // the EMLSR transition delay time if [...] the non-AP STA affiliated with the non-AP MLD
1194 // does not detect [...] any of the following frames:
1195 // - an individually addressed frame with the RA equal to the MAC address of the non-AP STA
1196 // affiliated with the non-AP MLD
1197 if (psdu->GetAddr1() == address)
1198 {
1199 return false;
1200 }
1201
1202 // - a Trigger frame that has one of the User Info fields addressed to the non-AP STA
1203 // affiliated with the non-AP MLD
1204 for (const auto& mpdu : *PeekPointer(psdu))
1205 {
1206 if (mpdu->GetHeader().IsTrigger())
1207 {
1208 CtrlTriggerHeader trigger;
1209 mpdu->GetPacket()->PeekHeader(trigger);
1210 if (trigger.FindUserInfoWithAid(aid) != trigger.end())
1211 {
1212 return false;
1213 }
1214 }
1215 }
1216
1217 // - a CTS-to-self frame with the RA equal to the MAC address of the AP affiliated with
1218 // the AP MLD
1219 if (psdu->GetHeader(0).IsCts())
1220 {
1221 if (m_apMac && psdu->GetAddr1() == m_self)
1222 {
1223 return false;
1224 }
1225 if (m_staMac && psdu->GetAddr1() == m_bssid)
1226 {
1227 return false;
1228 }
1229 }
1230
1231 // - a Multi-STA BlockAck frame that has one of the Per AID TID Info fields addressed to
1232 // the non-AP STA affiliated with the non-AP MLD
1233 if (psdu->GetHeader(0).IsBlockAck())
1234 {
1235 CtrlBAckResponseHeader blockAck;
1236 psdu->GetPayload(0)->PeekHeader(blockAck);
1237 if (blockAck.IsMultiSta() && !blockAck.FindPerAidTidInfoWithAid(aid).empty())
1238 {
1239 return false;
1240 }
1241 }
1242
1243 // - a NDP Announcement frame that has one of the STA Info fields addressed to the non-AP
1244 // STA affiliated with the non-AP MLD and a sounding NDP
1245 // TODO NDP Announcement frame not supported yet
1246
1247 return true;
1248}
1249
1250void
1252{
1253 NS_LOG_FUNCTION(this);
1254
1255 if (m_staMac && m_staMac->IsEmlsrLink(m_linkId) &&
1256 m_staMac->GetEmlsrManager()->GetElapsedMediumSyncDelayTimer(m_linkId))
1257 {
1258 NS_LOG_DEBUG("Reset the counter of TXOP attempts allowed while "
1259 "MediumSyncDelay is running");
1260 m_staMac->GetEmlsrManager()->ResetMediumSyncDelayNTxops(m_linkId);
1261 }
1262
1264}
1265
1266void
1268{
1269 NS_LOG_FUNCTION(this << forceCurrentCw);
1270
1271 if (m_staMac && m_staMac->IsEmlsrLink(m_linkId) &&
1272 m_staMac->GetEmlsrManager()->GetElapsedMediumSyncDelayTimer(m_linkId))
1273 {
1274 NS_LOG_DEBUG("Decrement the remaining number of TXOP attempts allowed while "
1275 "MediumSyncDelay is running");
1276 m_staMac->GetEmlsrManager()->DecrementMediumSyncDelayNTxops(m_linkId);
1277 }
1278
1280}
1281
1282void
1284{
1285 NS_LOG_FUNCTION(this);
1286
1287 if (m_apMac)
1288 {
1289 // the channel has been released; if the TXNAV is still set, it means that there is not
1290 // enough time left to send a CF-End. In this case, EMLSR clients wait for a slot plus the
1291 // PHY RX start delay before switching back to listening operation (in this case, this
1292 // function is called a SIFS after the last frame in the TXOP)
1293 Time delay{0};
1294 if (const auto remTxNav = m_txNav - Simulator::Now(); remTxNav.IsStrictlyPositive())
1295 {
1296 delay = Min(m_phy->GetSlot() + EMLSR_RX_PHY_START_DELAY, remTxNav);
1297 }
1298
1299 for (const auto& address : m_protectedStas)
1300 {
1301 if (GetWifiRemoteStationManager()->GetEmlsrEnabled(address))
1302 {
1303 EmlsrSwitchToListening(address, delay);
1304 }
1305 }
1306 }
1307 else if (m_staMac && m_staMac->IsEmlsrLink(m_linkId))
1308 {
1309 // Notify the UL TXOP end to the EMLSR Manager
1311
1312 NS_ASSERT(m_staMac->GetEmlsrManager());
1313 m_staMac->GetEmlsrManager()->NotifyTxopEnd(m_linkId, m_edca);
1314 }
1315
1317}
1318
1319void
1321{
1322 NS_LOG_FUNCTION(this << psdu << txVector);
1323
1324 // In addition, the timer resets to zero when any of the following events occur:
1325 // — The STA receives an MPDU
1326 // (Sec. 35.3.16.8.1 of 802.11be D3.1)
1327 if (m_staMac && m_staMac->IsEmlsrLink(m_linkId) &&
1328 m_staMac->GetEmlsrManager()->GetElapsedMediumSyncDelayTimer(m_linkId))
1329 {
1330 m_staMac->GetEmlsrManager()->CancelMediumSyncDelayTimer(m_linkId);
1331 }
1332
1333 if (m_apMac)
1334 {
1335 // we iterate over protected STAs to consider only the case when the AP is the TXOP holder.
1336 // The AP received a PSDU from a non-AP STA; given that the AP is the TXOP holder, this
1337 // PSDU has been likely solicited by the AP. In most of the cases, we identify which EMLSR
1338 // clients are no longer involved in the TXOP when the AP transmits the frame soliciting
1339 // response(s) from client(s). This is not the case, for example, for the acknowledgment
1340 // in SU format of a DL MU PPDU, where all the EMLSR clients (but one) switch to listening
1341 // operation after the immediate response (if any) by one of the EMLSR clients.
1342 for (auto clientIt = m_protectedStas.begin(); clientIt != m_protectedStas.end();)
1343 {
1344 // TB PPDUs are received by the AP at distinct times, so it is difficult to take a
1345 // decision based on one of them. However, clients transmitting TB PPDUs are identified
1346 // by the soliciting Trigger Frame, thus we have already identified (when sending the
1347 // Trigger Frame) which EMLSR clients have switched to listening operation.
1348 // If the PSDU is not carried in a TB PPDU, we can determine whether this EMLSR client
1349 // is switching to listening operation by checking whether the AP is expecting a
1350 // response from it.
1351 if (GetWifiRemoteStationManager()->GetEmlsrEnabled(*clientIt) && !txVector.IsUlMu() &&
1352 !m_txTimer.GetStasExpectedToRespond().contains(*clientIt))
1353 {
1354 EmlsrSwitchToListening(*clientIt, Seconds(0));
1355 // this client is no longer involved in the current TXOP
1356 clientIt = m_protectedStas.erase(clientIt);
1357 }
1358 else
1359 {
1360 clientIt++;
1361 }
1362 }
1363 }
1364
1366}
1367
1368void
1370{
1371 NS_LOG_FUNCTION(this << psdu << txVector);
1372
1374
1375 if (m_apMac && m_apMac->GetApEmlsrManager())
1376 {
1377 m_apMac->GetApEmlsrManager()->NotifyPsduRxOk(m_linkId, psdu);
1378 }
1379
1380 if (m_apMac && m_txopHolder == psdu->GetAddr2() &&
1381 GetWifiRemoteStationManager()->GetEmlsrEnabled(*m_txopHolder))
1382 {
1383 const auto unrespondedRts = (psdu->GetHeader(0).IsRts() && !m_sendCtsEvent.IsPending());
1384
1385 if (!m_ongoingTxopEnd.IsPending() && !unrespondedRts)
1386 {
1387 // an EMLSR client has started an UL TXOP. Start the ongoingTxopEnd timer so that
1388 // the next call to UpdateTxopEndOnRxEnd does its job
1391 }
1392
1393 UpdateTxopEndOnRxEnd(psdu->GetDuration());
1394 }
1395
1396 if (m_staMac && m_ongoingTxopEnd.IsPending())
1397 {
1398 if (GetEmlsrSwitchToListening(psdu, m_staMac->GetAssociationId(), m_self))
1399 {
1400 // we are no longer involved in the TXOP and switching to listening mode
1401 m_ongoingTxopEnd.Cancel();
1402 m_staMac->GetEmlsrManager()->NotifyTxopEnd(m_linkId);
1403 }
1404 else
1405 {
1406 UpdateTxopEndOnRxEnd(psdu->GetDuration());
1407 }
1408 }
1409
1410 if (m_staMac && m_dlTxopStart)
1411 {
1412 // we just got involved in a DL TXOP. Check if we are still involved in the TXOP in a
1413 // SIFS (we are expected to reply in a SIFS)
1414 m_ongoingTxopEnd.Cancel();
1415 NS_LOG_DEBUG("Expected TXOP end=" << (Simulator::Now() + m_phy->GetSifs()).As(Time::S));
1418 this,
1419 psdu->GetAddr2());
1420 // notify the EMLSR manager
1421 m_staMac->GetEmlsrManager()->NotifyDlTxopStart(m_linkId);
1422 m_dlTxopStart = false;
1423 }
1424}
1425
1426bool
1428 const WifiTxVector& txVector)
1429{
1430 NS_LOG_FUNCTION(this);
1431
1432 auto sender = hdr.GetAddr2();
1433
1434 if (m_ongoingTxopEnd.IsPending())
1435 {
1436 // after each frame exchange of a multi-frame TXOP, the TXOP end event stays pending
1437 // for a short window in which we wait to see whether the TXOP holder continues its
1438 // TXOP. If, in that window, another station transmits a frame that makes it the new
1439 // TXOP holder, the pending event refers to a TXOP that has been terminated: deliver
1440 // that event now and process the start of the new TXOP
1441 if (const auto holder = FindTxopHolder(hdr, txVector);
1442 holder == sender && m_txopHolder != sender)
1443 {
1444 NS_LOG_DEBUG("The TXOP tracked by the pending TXOP end event has terminated");
1445 m_ongoingTxopEnd.PeekEventImpl()->Invoke();
1446 m_ongoingTxopEnd.Cancel();
1447 }
1448 else
1449 {
1450 NS_LOG_DEBUG("A TXOP is already ongoing");
1451 return false;
1452 }
1453 }
1454
1455 if (auto holder = FindTxopHolder(hdr, txVector); holder != sender)
1456 {
1457 NS_LOG_DEBUG("Sender (" << sender << ") differs from the TXOP holder ("
1458 << (holder ? Address(*holder) : Address()) << ")");
1459 return false;
1460 }
1461
1462 if (!GetWifiRemoteStationManager()->GetEmlsrEnabled(sender))
1463 {
1464 NS_LOG_DEBUG("Sender (" << sender << ") is not an EMLSR client");
1465 return false;
1466 }
1467
1468 NS_LOG_DEBUG("EMLSR client " << sender << " is starting a TXOP");
1469
1470 // Block transmissions for this EMLSR client on other links
1471 auto mldAddress = GetWifiRemoteStationManager()->GetMldAddress(sender);
1472 NS_ASSERT(mldAddress);
1473
1474 for (uint8_t linkId = 0; linkId < m_apMac->GetNLinks(); ++linkId)
1475 {
1476 if (linkId != m_linkId &&
1477 m_mac->GetWifiRemoteStationManager(linkId)->GetEmlsrEnabled(*mldAddress))
1478 {
1480 *mldAddress,
1481 {linkId});
1482
1483 // the AP MLD may have sent an ICF to the EMLSR client on this link while the EMLSR
1484 // client was starting a TXOP on another link. To be safe, besides blocking
1485 // transmissions, remove the EMLSR client from the protected stations on this link
1486 auto linkAddr =
1487 m_mac->GetWifiRemoteStationManager(linkId)->GetAffiliatedStaAddress(*mldAddress);
1488 NS_ASSERT(linkAddr.has_value());
1489 auto ehtFem =
1490 StaticCast<EhtFrameExchangeManager>(m_mac->GetFrameExchangeManager(linkId));
1491 NS_LOG_DEBUG("Remove " << *linkAddr << " from protected STAs");
1492 ehtFem->m_protectedStas.erase(*linkAddr);
1493 ehtFem->m_sentRtsTo.erase(*linkAddr);
1494 ehtFem->m_sentFrameTo.erase(*linkAddr);
1495 }
1496 }
1497
1498 // Make sure that transmissions for this EMLSR client are not blocked on this link
1499 // (the AP MLD may have sent an ICF on another link right before receiving this MPDU,
1500 // thus transmissions on this link may have been blocked)
1502 *mldAddress,
1503 {m_linkId});
1504
1505 // Stop the transition delay timer for this EMLSR client, if any is running
1506 if (auto it = m_transDelayTimer.find(*mldAddress);
1507 it != m_transDelayTimer.end() && it->second.IsPending())
1508 {
1509 it->second.PeekEventImpl()->Invoke();
1510 it->second.Cancel();
1511 }
1512
1513 return true;
1514}
1515
1516EventId&
1521
1522void
1524{
1525 NS_LOG_FUNCTION(this << psdu);
1526
1527 if (m_apMac && m_apMac->GetApEmlsrManager())
1528 {
1529 m_apMac->GetApEmlsrManager()->NotifyPsduRxError(m_linkId, psdu);
1530 }
1531}
1532
1533void
1535 RxSignalInfo rxSignalInfo,
1536 const WifiTxVector& txVector,
1537 bool inAmpdu)
1538{
1539 NS_LOG_FUNCTION(this << *mpdu << rxSignalInfo << txVector << inAmpdu);
1540
1541 // The received MPDU is either broadcast or addressed to this station
1542 NS_ASSERT(mpdu->GetHeader().GetAddr1().IsGroup() || mpdu->GetHeader().GetAddr1() == m_self);
1543
1544 const auto& hdr = mpdu->GetHeader();
1545 auto sender = hdr.GetAddr2();
1546
1547 if (hdr.IsTrigger())
1548 {
1549 if (!m_staMac)
1550 {
1551 return; // Trigger Frames are only processed by STAs
1552 }
1553
1554 CtrlTriggerHeader trigger;
1555 mpdu->GetPacket()->PeekHeader(trigger);
1556
1557 if (hdr.GetAddr1() != m_self &&
1558 (!hdr.GetAddr1().IsBroadcast() || !m_staMac->IsAssociated() ||
1559 sender != m_bssid // not sent by the AP this STA is associated with
1560 || trigger.FindUserInfoWithAid(m_staMac->GetAssociationId()) == trigger.end()))
1561 {
1562 return; // not addressed to us
1563 }
1564
1565 if ((trigger.IsMuRts() || trigger.IsBsrp()) && !m_ongoingTxopEnd.IsPending() &&
1566 m_staMac->IsEmlsrLink(m_linkId))
1567 {
1568 // this is an initial Control frame
1569 if (DropReceivedIcf(mpdu))
1570 {
1571 return;
1572 }
1573
1574 m_dlTxopStart = true;
1575 }
1576 }
1577 else if (m_staMac && m_staMac->IsEmlsrLink(m_linkId) && !m_ongoingTxopEnd.IsPending() &&
1578 m_phy->GetPhyId() == m_staMac->GetEmlsrManager()->GetMainPhyId() &&
1579 (hdr.IsRts() || hdr.IsBlockAckReq() || hdr.IsData()) && hdr.GetAddr1() == m_self)
1580 {
1581 // a frame that is starting a DL TXOP has been received by the main PHY, check if the frame
1582 // shall be dropped
1583 if (DropReceivedIcf(mpdu))
1584 {
1585 return;
1586 }
1587
1588 m_dlTxopStart = true;
1589
1590 if (inAmpdu)
1591 {
1592 // start blocking transmission on other links (which is normally done later on by
1593 // PostProcessFrame()) to avoid starting an UL TXOP before end of A-MPDU
1594 for (auto id : m_staMac->GetLinkIds())
1595 {
1596 if (id != m_linkId && m_staMac->IsEmlsrLink(id))
1597 {
1599 }
1600 }
1601 }
1602 }
1603
1605 {
1606 NS_LOG_DEBUG("Drop received MPDU: " << *mpdu);
1607 return;
1608 }
1609
1610 HeFrameExchangeManager::ReceiveMpdu(mpdu, rxSignalInfo, txVector, inAmpdu);
1611
1612 if (m_apMac && GetWifiRemoteStationManager()->GetEmlsrEnabled(sender))
1613 {
1614 if (hdr.IsRts() && !m_sendCtsEvent.IsPending())
1615 {
1616 // received RTS but did not send CTS (e.g., NAV busy), start transition delay
1617 EmlsrSwitchToListening(sender, Time{0});
1618 return;
1619 }
1620
1621 // if the AP MLD received an MPDU from an EMLSR client that is starting an UL TXOP,
1622 // block transmissions to the EMLSR client on other links
1623 CheckEmlsrClientStartingTxop(hdr, txVector);
1624 }
1625}
1626
1627bool
1629{
1630 NS_LOG_FUNCTION(this << *mpdu);
1631
1632 // this function only checks frames that shall be dropped by an EMLSR client
1633 if (!m_staMac || !m_staMac->IsEmlsrLink(m_linkId))
1634 {
1635 return false;
1636 }
1637
1638 // discard any frame received after scheduling a CTS response. It has been observed that
1639 // an ICF may be received by both the main PHY and an aux PHY (leading to scheduling a
1640 // CTS response twice) if:
1641 // - the main PHY switches to an aux PHY link and completes the switch during the preamble
1642 // detection period for a PPDU (that is not an ICF), hence main PHY connection is postponed
1643 // - right afterwards, an ICF is transmitted on the aux PHY link (collision with the other
1644 // PPDU)
1645 // - the main PHY starts receiving the ICF, and so does the aux PHY because the ICF signal
1646 // is stronger
1647 // - at the end of the ICF reception, the aux PHY notifies the ICF to the FEM, which schedules
1648 // a CTS and connects the main PHY to the link; then, the main PHY notifies the ICF to the
1649 // FEM again
1650 if (m_sendCtsEvent.IsPending())
1651 {
1652 NS_LOG_DEBUG("Dropping " << *mpdu << " received when CTS is scheduled for TX on link "
1653 << +m_linkId);
1654 return true;
1655 }
1656
1657 const auto& hdr = mpdu->GetHeader();
1658
1659 // We impose that an aux PHY is only able to receive an ICF, a CF-End, a CTS or a management
1660 // frame (we are interested in receiving mainly Beacon frames). Note that other frames are
1661 // still post-processed, e.g., used to set the NAV and the TXOP holder.
1662 // The motivation is that, e.g., an AP MLD may send an ICF to EMLSR clients A and B;
1663 // A responds while B does not; the AP MLD sends a DL MU PPDU to both clients followed
1664 // by an MU-BAR to solicit a BlockAck from both clients. If an aux PHY of client B is
1665 // operating on this link, the MU-BAR will be received and a TB PPDU response sent
1666 // through the aux PHY.
1667 if (hdr.IsMgt() || hdr.IsCts() || hdr.IsCfEnd() || (hdr.IsData() && hdr.GetAddr1().IsGroup()))
1668 {
1669 return false;
1670 }
1671
1672 // other frames cannot be received by an aux PHY
1673 if (m_mac->GetLinkForPhy(m_staMac->GetEmlsrManager()->GetMainPhyId()) != m_linkId)
1674 {
1675 NS_LOG_DEBUG("Dropping " << *mpdu << " received by an aux PHY on link " << +m_linkId);
1676 return true;
1677 }
1678
1679 // other frames cannot be received by the main PHY when not involved in any TXOP
1680 if (!m_ongoingTxopEnd.IsPending() &&
1681 std::none_of(wifiAcList.cbegin(), wifiAcList.cend(), [=, this](const auto& aciAcPair) {
1682 return m_mac->GetQosTxop(aciAcPair.first)->GetTxopStartTime(m_linkId).has_value();
1683 }))
1684 {
1685 NS_LOG_DEBUG("Dropping " << *mpdu << " received by main PHY on link " << +m_linkId
1686 << " while no TXOP is ongoing");
1687 return true;
1688 }
1689
1690 // other frames can be received by the main PHY when involved in a TXOP
1691 return false;
1692}
1693
1694bool
1696{
1697 NS_LOG_FUNCTION(this << *icf);
1698
1699 auto emlsrManager = m_staMac->GetEmlsrManager();
1700 NS_ASSERT(emlsrManager);
1701 auto addr2 = icf->GetHeader().GetAddr2();
1702
1703 if (UsingOtherEmlsrLink())
1704 {
1705 // we received an ICF on a link that is blocked because another EMLSR link is
1706 // being used. Check if there is an ongoing DL TXOP on the other EMLSR link
1707 const auto sender = GetWifiRemoteStationManager()->GetMldAddress(addr2).value_or(addr2);
1708 NS_ASSERT_MSG(addr2 != m_bssid || sender != m_bssid,
1709 "If the ICF is not sent by an adhoc peer, it must be sent by an (AP) MLD");
1710
1711 if (auto it = std::find_if(
1712 m_staMac->GetLinkIds().cbegin(),
1713 m_staMac->GetLinkIds().cend(),
1714 /* lambda to find an EMLSR link on which there is an ongoing DL TXOP */
1715 [=, this](uint8_t linkId) {
1716 auto ehtFem =
1717 StaticCast<EhtFrameExchangeManager>(m_mac->GetFrameExchangeManager(linkId));
1718 return linkId != m_linkId && m_staMac->IsEmlsrLink(linkId) &&
1719 ehtFem->m_ongoingTxopEnd.IsPending() && ehtFem->m_txopHolder &&
1720 m_mac->GetWifiRemoteStationManager(linkId)
1721 ->GetMldAddress(*ehtFem->m_txopHolder)
1722 .value_or(*ehtFem->m_txopHolder) == sender;
1723 });
1724 it != m_staMac->GetLinkIds().cend())
1725 {
1726 // A device is not expected to send ICFs on two links. If an ICF has been received on
1727 // this link, it means that the DL TXOP on the other link terminated (e.g., the device
1728 // did not receive our response)
1729 StaticCast<EhtFrameExchangeManager>(m_mac->GetFrameExchangeManager(*it))
1730 ->m_ongoingTxopEnd.Cancel();
1731 // we are going to start a TXOP on this link; unblock transmissions on this link, the
1732 // other links will be blocked subsequently
1734 }
1735 else
1736 {
1737 // We get here if either there is an ongoing DL TXOP on another EMLSR link but the
1738 // TXOP holder is not the sender of the ICF (this may happen when the EMLSR client
1739 // receives ICFs from the AP and a peer adhoc STA) or there is an ongoing UL TXOP on
1740 // the other EMLSR link (which likely happens when a transmission on the other EMLSR
1741 // link started before the reception of the ICF ended). In both cases, we drop this ICF
1742 // and let the TXOP on the other EMLSR link continue.
1743 NS_LOG_DEBUG("Drop ICF because another EMLSR link is being used");
1745 return true;
1746 }
1747 }
1748 /**
1749 * It might happen that, while the aux PHY is receiving an ICF, the main PHY is
1750 * completing a TXOP on another link or is returning to the primary link after a TXOP
1751 * is completed on another link. In order to respond to the ICF, it is necessary that
1752 * the main PHY has enough time to switch and be ready to operate on this link by the
1753 * end of the ICF padding.
1754 *
1755 * TXOP end
1756 * │
1757 * ┌───┐ another
1758 * AP MLD │ACK│ link
1759 * ───────────┬─────────┬┴───┴───────────────────────────────────────
1760 * EMLSR │ QoS │ │ main PHY
1761 * client │ Data │ │
1762 * └─────────┘ │
1763 * ┌─────┬───┐ this
1764 * AP MLD │ ICF │pad│ link
1765 * ────────────────────┴─────┴───┴───────────────────────────────────
1766 * aux PHY
1767 */
1768 else if (auto mainPhy = m_staMac->GetDevice()->GetPhy(emlsrManager->GetMainPhyId());
1769 mainPhy != m_phy)
1770 {
1771 auto reason = emlsrManager->CheckMainPhyTakesOverDlTxop(m_linkId);
1772
1773 if (reason.has_value())
1774 {
1776 "Drop ICF due to not enough time for the main PHY to switch link; reason = "
1777 << *reason);
1778 m_icfDropCallback({*reason, m_linkId, addr2});
1779 return true;
1780 }
1781 }
1782 return false;
1783}
1784
1785void
1786EhtFrameExchangeManager::TxopEnd(const std::optional<Mac48Address>& txopHolder)
1787{
1788 NS_LOG_FUNCTION(this << txopHolder.has_value());
1789
1790 if (m_phy && m_phy->GetInfoIfRxingPhyHeader())
1791 {
1792 // we may get here because the PHY has not issued the PHY-RXSTART.indication before
1793 // the expiration of the timer started to detect new received frames, but the PHY is
1794 // currently decoding the PHY header of a PPDU, so let's wait some more time to check
1795 // if we receive a PHY-RXSTART.indication when the PHY is done decoding the PHY header
1796 NS_LOG_DEBUG("PHY is decoding the PHY header of PPDU, postpone TXOP end");
1799 this,
1800 txopHolder);
1801 return;
1802 }
1803
1804 if (m_staMac && m_staMac->IsEmlsrLink(m_linkId))
1805 {
1806 m_staMac->GetEmlsrManager()->NotifyTxopEnd(m_linkId);
1807 }
1808 else if (m_apMac && txopHolder && GetWifiRemoteStationManager()->GetEmlsrEnabled(*txopHolder))
1809 {
1810 // EMLSR client terminated its TXOP and is back to listening operation
1811 EmlsrSwitchToListening(*txopHolder, Seconds(0));
1812 }
1813}
1814
1815void
1817{
1818 NS_LOG_FUNCTION(this << txDuration.As(Time::MS) << durationId.As(Time::US));
1819
1820 if (!m_ongoingTxopEnd.IsPending())
1821 {
1822 // nothing to do
1823 return;
1824 }
1825
1826 m_ongoingTxopEnd.Cancel();
1827 Time delay;
1828
1829 if (m_txTimer.IsRunning())
1830 {
1831 // the TX timer is running, hence we are expecting a response. Postpone the TXOP end
1832 // to match the TX timer (which is long enough to get the PHY-RXSTART.indication for
1833 // the response)
1834 delay = m_txTimer.GetDelayLeft();
1835 }
1836 else if (m_earlyTxopEndDetect && durationId <= m_phy->GetSifs())
1837 {
1838 // the TX timer is not running, hence no response is expected, and the Duration/ID value
1839 // is less than or equal to a SIFS; the TXOP will end after this transmission
1840 NS_LOG_DEBUG("Assume TXOP will end based on Duration/ID value");
1841 delay = txDuration;
1842 }
1843 else
1844 {
1845 // the TX Timer is not running, hence no response is expected (e.g., we are
1846 // transmitting a CTS after ICS). The TXOP holder may transmit a frame a SIFS
1847 // after the end of this PPDU, hence we need to postpone the TXOP end in order to
1848 // get the PHY-RXSTART.indication
1849 delay = txDuration + m_phy->GetSifs() + m_phy->GetSlot() + EMLSR_RX_PHY_START_DELAY;
1851 {
1852 // TXOP end cannot be beyond the period protected via Duration/ID
1853 delay = Min(delay, txDuration + durationId);
1854 }
1855 }
1856
1857 NS_LOG_DEBUG("Expected TXOP end=" << (Simulator::Now() + delay).As(Time::S));
1860}
1861
1862void
1864{
1865 NS_LOG_FUNCTION(this << psduDuration.As(Time::MS));
1866
1867 if (!m_ongoingTxopEnd.IsPending() || !psduDuration.IsStrictlyPositive())
1868 {
1869 // nothing to do
1870 return;
1871 }
1872
1873 // postpone the TXOP end until after the reception of the PSDU is completed
1874 m_ongoingTxopEnd.Cancel();
1875
1876 NS_LOG_DEBUG("Expected TXOP end=" << (Simulator::Now() + psduDuration).As(Time::S));
1879 this,
1880 m_txopHolder);
1881}
1882
1883void
1885{
1886 NS_LOG_FUNCTION(this << durationId.As(Time::US));
1887
1888 if (!m_ongoingTxopEnd.IsPending())
1889 {
1890 // nothing to do
1891 return;
1892 }
1893
1894 m_ongoingTxopEnd.Cancel();
1895
1896 // if the Duration/ID of the received frame is less than a SIFS, the TXOP
1897 // is terminated
1898 if (m_earlyTxopEndDetect && durationId <= m_phy->GetSifs())
1899 {
1900 NS_LOG_DEBUG("Assume TXOP ended based on Duration/ID value");
1902 return;
1903 }
1904
1905 // we may send a response after a SIFS or we may receive another frame after a SIFS.
1906 // Postpone the TXOP end by considering the latter (which takes longer)
1907 auto delay = m_phy->GetSifs() + m_phy->GetSlot() + EMLSR_RX_PHY_START_DELAY;
1909 {
1910 // TXOP end cannot be beyond the period protected via Duration/ID
1911 delay = Min(delay, durationId);
1912 }
1913 NS_LOG_DEBUG("Expected TXOP end=" << (Simulator::Now() + delay).As(Time::S));
1916}
1917
1918} // namespace ns3
#define Min(a, b)
a polymophic address class
Definition address.h:114
Headers for BlockAck response.
std::vector< uint32_t > FindPerAidTidInfoWithAid(uint16_t aid) const
For Multi-STA Block Acks, get the indices of the Per AID TID Info subfields carrying the given AID in...
Headers for Trigger frames.
ConstIterator end() const
Get a const iterator indicating past-the-last User Info field in the list.
bool IsMuRts() const
Check if this is a MU-RTS Trigger frame.
void SetPaddingSize(std::size_t size)
Set the size in bytes of the Padding field.
bool IsBsrp() const
Check if this is a Buffer Status Report Poll Trigger frame.
ConstIterator FindUserInfoWithAid(ConstIterator start, uint16_t aid12) const
Get a const iterator pointing to the first User Info field found (starting from the one pointed to by...
EhtFrameExchangeManager handles the frame exchange sequences for EHT stations.
void GenerateInDeviceInterferenceForAll(const Time &txDuration, const WifiTxVector &txVector)
Generate in-device interference caused by a transmission on this link for all the other PHYs of this ...
void PostProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector) override
Perform actions that are possibly needed after receiving any frame, independently of whether the fram...
bool m_earlyTxopEndDetect
whether the Duration/ID value of the frame being transmitted or received can be used to early detect ...
void TransmissionFailed(bool forceCurrentCw=false) override
Take necessary actions upon a transmission failure.
void ForwardPsduMapDown(WifiConstPsduMap psduMap, WifiTxVector &txVector) override
Forward a map of PSDUs down to the PHY layer.
bool GetEmlsrClientCanStartTxop()
This function is expected to be called when an EMLSR client gains channel access to determine whether...
void SendCtsAfterRts(const WifiMacHeader &rtsHdr, const WifiTxVector &rtsTxVector, double rtsSnr) override
Send CTS after receiving RTS.
void ReceivedQosNullAfterBsrpTf(Mac48Address sender) override
Perform the actions required when receiving QoS Null frame(s) from the given sender after a BSRP Trig...
void SetIcfPaddingAndTxVector(CtrlTriggerHeader &trigger, WifiTxVector &txVector) const
Set the padding and the TXVECTOR of the given Trigger Frame, in case it is an Initial Control Frame f...
bool StartFrameExchange() override
Start a frame exchange (including protection frames and acknowledgment frames as needed).
void PreProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector) override
Perform actions that are possibly needed when receiving any frame, independently of whether the frame...
void NavResetTimeout() override
Reset the NAV upon expiration of the NAV reset timer.
void ForwardPsduDown(Ptr< const WifiPsdu > psdu, WifiTxVector &txVector) override
Forward a PSDU down to the PHY layer.
void PsduRxError(Ptr< const WifiPsdu > psdu) override
This method is called when the reception of a PSDU fails.
void EmlsrSwitchToListening(Mac48Address address, const Time &delay)
This method is intended to be called when an AP MLD detects that an EMLSR client previously involved ...
void BlockAcksInTbPpduTimeout(WifiPsduMap *psduMap, std::size_t nSolicitedStations) override
Take the necessary actions after that some BlockAck frames are missing in response to a DL MU PPDU.
void SendEmlOmn(const Mac48Address &dest, const MgtEmlOmn &frame)
Send an EML Operating Mode Notification frame to the given station.
Ptr< WifiMpdu > CreateAliasIfNeeded(Ptr< WifiMpdu > mpdu) const override
Create an alias of the given MPDU for transmission by this Frame Exchange Manager.
void ProtectionCompleted() override
Transmit prepared frame immediately, if no protection was used, or in a SIFS, if protection was compl...
void TbPpduTimeout(WifiPsduMap *psduMap, std::size_t nSolicitedStations) override
Take the necessary actions after that some TB PPDUs are missing in response to Trigger Frame.
void IntraBssNavResetTimeout() override
Reset the intra-BSS NAV upon expiration of the intra-BSS NAV reset timer.
void ApCheckTxBlocked()
This function is expected to be called when the AP is starting a frame exchange and checks that trans...
bool DropReceivedIcf(Ptr< const WifiMpdu > icf)
void GenerateInDeviceInterference(Ptr< WifiPhy > phy, Time duration, Watt_u txPower)
Generate an in-device interference of the given power for the given duration for the given PHY.
bool ShallDropReceivedMpdu(Ptr< const WifiMpdu > mpdu) const
Check if the MPDU that has been received on this link shall be dropped.
void SendCtsAfterMuRts(const WifiMacHeader &muRtsHdr, const CtrlTriggerHeader &trigger, double muRtsSnr) override
Send CTS after receiving an MU-RTS.
void SwitchToListeningOrUnblockLinks(const std::set< Mac48Address > &clients)
For each EMLSR client in the given set of clients that did not respond to a frame requesting a respon...
bool IsCrossLinkCollision(const std::set< Mac48Address > &staMissedResponseFrom) const
Check whether all the stations that did not respond (to a certain frame) are EMLSR clients trying to ...
std::optional< dBm_u > GetMostRecentRssi(const Mac48Address &address) const override
Get the RSSI of the most recent packet received from the station having the given address.
void UpdateTxopEndOnRxEnd(Time durationId)
Update the TXOP end timer when a frame reception ends.
WifiMac::IcfDropTracedCallback m_icfDropCallback
ICF drop reason traced callback (WifiMac exposes this trace source).
bool CheckEmlsrClientStartingTxop(const WifiMacHeader &hdr, const WifiTxVector &txVector)
Check if the frame received (or being received) is sent by an EMLSR client to start an UL TXOP.
void TransmissionSucceeded() override
Take necessary actions upon a transmission success.
bool GetEmlsrSwitchToListening(Ptr< const WifiPsdu > psdu, uint16_t aid, const Mac48Address &address) const
static TypeId GetTypeId()
Get the type ID.
void PrepareFrameToSend(Ptr< WifiMpdu > peekedItem) override
Set the sequence number, determine the transmission parameters and transmit the given MPDU,...
void DoDispose() override
Destructor implementation.
std::unordered_map< Mac48Address, EventId, WifiAddressHash > m_transDelayTimer
MLD address-indexed map of transition delay timers.
EventId m_ongoingTxopEnd
event indicating the possible end of the current TXOP (of which we are not the holder)
void RxStartIndication(WifiTxVector txVector, Time psduDuration) override
void ReceiveMpdu(Ptr< const WifiMpdu > mpdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, bool inAmpdu) override
This method handles the reception of an MPDU (possibly included in an A-MPDU).
void UpdateTxopEndOnTxStart(Time txDuration, Time durationId)
Update the TXOP end timer when starting a frame transmission.
bool CanTransmitBarTo(Mac48Address recipient, tid_t tid) const override
Check if a BlockAckReq to the given recipient for the given TID can be transmitted on this link.
void SendQosNullFramesInTbPpdu(const CtrlTriggerHeader &trigger, const WifiMacHeader &hdr) override
Send QoS Null frames in response to a Basic or BSRP Trigger Frame.
void UpdateTxopEndOnRxStartIndication(Time psduDuration)
Update the TXOP end timer when receiving a PHY-RXSTART.indication.
void TxopEnd(const std::optional< Mac48Address > &txopHolder)
Take actions when a TXOP (of which we are not the holder) ends.
bool m_dlTxopStart
whether a DL TXOP start is detected and needs to be notified to the EMLSR manager after post-processi...
bool UnblockEmlsrLinksIfAllowed(Mac48Address address, bool checkThisLink)
Unblock transmissions on all the links of the given EMLSR client, provided that the latter is not inv...
void CtsAfterMuRtsTimeout(Ptr< WifiMpdu > muRts, const WifiTxVector &txVector) override
Called when no CTS frame is received after an MU-RTS.
void NotifySwitchingEmlsrLink(Ptr< WifiPhy > phy, uint8_t linkId, Time delay)
Notify that the given PHY will switch channel to operate on another EMLSR link after the given delay.
void NotifyChannelReleased() override
Notify the Txop that gained channel access that channel has been released.
void SetLinkId(uint8_t linkId) override
Set the ID of the link this Frame Exchange Manager is associated with.
An identifier for simulation events.
Definition event-id.h:45
std::set< Mac48Address > m_sentRtsTo
the STA(s) which we sent an RTS to (waiting for CTS)
Ptr< AdhocWifiMac > m_adhocMac
ADHOC MAC layer pointer (null if not ADHOC).
uint8_t m_linkId
the ID of the link this object is associated with
Ptr< WifiMac > m_mac
the MAC layer on this station
virtual void ResetPhy()
Remove WifiPhy associated with this FrameExchangeManager.
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager() const
Ptr< MacTxMiddle > m_txMiddle
the MAC TX Middle on this station
virtual bool GetReportRtsFailed() const
Mac48Address m_self
the MAC address of this device
WifiTxTimer m_txTimer
the timer set upon frame transmission
std::set< Mac48Address > m_protectedStas
STAs that have replied to an RTS in this TXOP.
Mac48Address GetAddress() const
Get the MAC address.
virtual void SetLinkId(uint8_t linkId)
Set the ID of the link this Frame Exchange Manager is associated with.
virtual void SendCtsAfterRts(const WifiMacHeader &rtsHdr, const WifiTxVector &rtsTxVector, double rtsSnr)
Send CTS after receiving RTS.
Ptr< WifiAckManager > GetAckManager() const
Get the Acknowledgment Manager used by this node.
Ptr< WifiProtectionManager > GetProtectionManager() const
Get the Protection Manager used by this node.
EventId m_sendCtsEvent
the event to send a CTS after an (MU-)RTS
Ptr< WifiPhy > m_phy
the PHY layer on this station
virtual void NotifyChannelReleased()
Notify the Txop that gained channel access that channel has been released.
virtual void PreProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Perform actions that are possibly needed when receiving any frame, independently of whether the frame...
Ptr< ApWifiMac > m_apMac
AP MAC layer pointer (null if not an AP).
Mac48Address m_bssid
BSSID address (Mac48Address).
virtual void TransmissionFailed(bool forceCurrentCw=false)
Take necessary actions upon a transmission failure.
virtual void PrepareFrameToSend(Ptr< WifiMpdu > peekedItem)
Set the sequence number, determine the transmission parameters and transmit the given MPDU,...
Ptr< StaWifiMac > m_staMac
STA MAC layer pointer (null if not a STA).
virtual bool GetUpdateCwOnCtsTimeout() const
virtual void SendQosNullFramesInTbPpdu(const CtrlTriggerHeader &trigger, const WifiMacHeader &hdr)
Send QoS Null frames in response to a Basic or BSRP Trigger Frame.
void DoDispose() override
Destructor implementation.
virtual void IntraBssNavResetTimeout()
Reset the intra-BSS NAV upon expiration of the intra-BSS NAV reset timer.
virtual void ReceivedQosNullAfterBsrpTf(Mac48Address sender)
Perform the actions required when receiving QoS Null frame(s) from the given sender after a BSRP Trig...
void RxStartIndication(WifiTxVector txVector, Time psduDuration) override
std::optional< Mac48Address > FindTxopHolder(const WifiMacHeader &hdr, const WifiTxVector &txVector) override
Determine the holder of the TXOP, if possible, based on the received frame.
bool StartFrameExchange() override
Start a frame exchange (including protection frames and acknowledgment frames as needed).
virtual void CtsAfterMuRtsTimeout(Ptr< WifiMpdu > muRts, const WifiTxVector &txVector)
Called when no CTS frame is received after an MU-RTS.
void NavResetTimeout() override
Reset the NAV upon expiration of the NAV reset timer.
void ProtectionCompleted() override
Transmit prepared frame immediately, if no protection was used, or in a SIFS, if protection was compl...
virtual void SendCtsAfterMuRts(const WifiMacHeader &muRtsHdr, const CtrlTriggerHeader &trigger, double muRtsSnr)
Send CTS after receiving an MU-RTS.
virtual void BlockAcksInTbPpduTimeout(WifiPsduMap *psduMap, std::size_t nSolicitedStations)
Take the necessary actions after that some BlockAck frames are missing in response to a DL MU PPDU.
void ReceiveMpdu(Ptr< const WifiMpdu > mpdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, bool inAmpdu) override
This method handles the reception of an MPDU (possibly included in an A-MPDU).
virtual void ForwardPsduMapDown(WifiConstPsduMap psduMap, WifiTxVector &txVector)
Forward a map of PSDUs down to the PHY layer.
void PostProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector) override
Perform actions that are possibly needed after receiving any frame, independently of whether the fram...
std::set< Mac48Address > GetTfRecipients(const CtrlTriggerHeader &trigger) const
Get the (link) address of the non-AP stations solicited by the given Trigger Frame.
void DoTbPpduTimeout(WifiPsduMap *psduMap, std::size_t nSolicitedStations, bool updateFailedCw)
Take the necessary actions after that some TB PPDUs are missing in response to Trigger Frame.
virtual std::optional< dBm_u > GetMostRecentRssi(const Mac48Address &address) const
Get the RSSI of the most recent packet received from the station having the given address.
void TransmissionSucceeded() override
Take necessary actions upon a transmission success.
Ptr< MpduAggregator > m_mpduAggregator
A-MPDU aggregator.
virtual void ForwardPsduDown(Ptr< const WifiPsdu > psdu, WifiTxVector &txVector)
Forward a PSDU down to the PHY layer.
virtual bool CanTransmitBarTo(Mac48Address recipient, tid_t tid) const
Check if a BlockAckReq to the given recipient for the given TID can be transmitted on this link.
Ptr< MsduAggregator > m_msduAggregator
A-MSDU aggregator.
an EUI-48 address
Implement the header for Action frames of type EML Operating Mode Notification.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Ptr< QosTxop > m_edca
the EDCAF that gained channel access
std::optional< Mac48Address > m_txopHolder
MAC address of the TXOP holder.
virtual Ptr< WifiMpdu > CreateAliasIfNeeded(Ptr< WifiMpdu > mpdu) const
Create an alias of the given MPDU for transmission by this Frame Exchange Manager.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:614
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
@ US
microsecond
Definition nstime.h:108
@ MS
millisecond
Definition nstime.h:107
@ S
second
Definition nstime.h:106
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:422
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:341
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition nstime.h:1410
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:305
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:664
static constexpr bool DIDNT_HAVE_FRAMES_TO_TRANSMIT
no packet available for transmission was in the queue
Definition txop.h:417
static constexpr bool CHECK_MEDIUM_BUSY
generation of backoff (also) depends on the busy/idle state of the medium
Definition txop.h:419
static constexpr bool DONT_CHECK_MEDIUM_BUSY
generation of backoff is independent of the busy/idle state of the medium
Definition txop.h:421
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
See IEEE 802.11 chapter 7.3.1.11 Header format: | category: 1 | action value: 1 |.
void SetAction(CategoryValue type, ActionValue action)
Set action for this Action header.
Implements the IEEE 802.11 MAC header.
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.
Mac48Address GetAddr2() const
Return the address in the Address 2 field.
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
void SetDsNotTo()
Un-set the To DS bit in the Frame Control field.
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:110
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition wifi-phy.cc:1574
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
WifiPreamble GetPreambleType() const
void SetSigBMode(const WifiMode &mode)
Set the MCS used for SIG-B.
uint8_t GetTxPowerLevel() const
Declaration of ns3::EhtPhy class.
#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_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
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1347
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1364
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
WifiContainerQueueId MakeWifiUnicastQueueId(WifiContainerQueueType type, Mac48Address addr1, std::optional< tid_t > tid=std::nullopt)
Helper function to create WifiContainerQueueId for unicast queues.
@ WIFI_PREAMBLE_EHT_MU
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36).
@ AC_BE
Best Effort.
Definition qos-utils.h:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:501
static constexpr uint8_t WAIT_FOR_RXSTART_DELAY_USEC
Additional time (exceeding 20 us) to wait for a PHY-RXSTART.indication when the PHY is decoding a PHY...
bool IsTrigger(const WifiPsduMap &psduMap)
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:643
std::unordered_map< uint16_t, Ptr< WifiPsdu > > WifiPsduMap
Map of PSDUs indexed by STA-ID.
Definition wifi-mac.h:105
uint8_t tid_t
IEEE 802.11-2020 9.2.4.5.2 TID subfield.
Definition wifi-utils.h:73
@ WIFI_MAC_MGT_ACTION
Ptr< T1 > StaticCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:650
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:39
uint8_t linkId_t
IEEE 802.11be D7.0 Figure 9-207e—Link ID Info field format.
Definition wifi-utils.h:76
double Watt_u
Watt weak type.
Definition wifi-units.h:25
const Time EMLSR_RX_PHY_START_DELAY
aRxPHYStartDelay value to use when waiting for a new frame in the context of EMLSR operations (Sec.
const std::map< AcIndex, WifiAc > wifiAcList
Map containing the four ACs in increasing order of priority (according to Table 10-1 "UP-to-AC Mappin...
Definition qos-utils.cc:115
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
Definition wifi-utils.cc:32
static Time DecodeEmlsrTransitionDelay(uint8_t value)
RxSignalInfo structure containing info on the received signal.
Definition wifi-types.h:85
typedef for union of different ActionValues