A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-remote-station-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006,2007 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
21
22#include "ap-wifi-mac.h"
23#include "sta-wifi-mac.h"
24#include "wifi-mac-header.h"
25#include "wifi-mac-trailer.h"
26#include "wifi-mpdu.h"
27#include "wifi-net-device.h"
28#include "wifi-phy.h"
29#include "wifi-tx-parameters.h"
30
31#include "ns3/boolean.h"
32#include "ns3/eht-configuration.h"
33#include "ns3/enum.h"
34#include "ns3/erp-ofdm-phy.h"
35#include "ns3/he-configuration.h"
36#include "ns3/ht-configuration.h"
37#include "ns3/ht-phy.h"
38#include "ns3/log.h"
39#include "ns3/simulator.h"
40#include "ns3/uinteger.h"
41#include "ns3/vht-configuration.h"
42
43namespace ns3
44{
45
46NS_LOG_COMPONENT_DEFINE("WifiRemoteStationManager");
47
48NS_OBJECT_ENSURE_REGISTERED(WifiRemoteStationManager);
49
50TypeId
52{
53 static TypeId tid =
54 TypeId("ns3::WifiRemoteStationManager")
56 .SetGroupName("Wifi")
57 .AddAttribute("MaxSsrc",
58 "The maximum number of retransmission attempts for any packet with size "
59 "<= RtsCtsThreshold. "
60 "This value will not have any effect on some rate control algorithms.",
63 MakeUintegerChecker<uint32_t>())
64 .AddAttribute("MaxSlrc",
65 "The maximum number of retransmission attempts for any packet with size "
66 "> RtsCtsThreshold. "
67 "This value will not have any effect on some rate control algorithms.",
70 MakeUintegerChecker<uint32_t>())
71 .AddAttribute("RtsCtsThreshold",
72 "If the size of the PSDU is bigger than this value, we use an RTS/CTS "
73 "handshake before sending the data frame."
74 "This value will not have any effect on some rate control algorithms.",
75 UintegerValue(4692480),
77 MakeUintegerChecker<uint32_t>(0, 4692480))
78 .AddAttribute("RtsCtsTxDurationThresh",
79 "If this threshold is a strictly positive value and the TX duration of "
80 "the PSDU is greater than or equal to this threshold, we use an RTS/CTS "
81 "handshake before sending the data frame.",
82 TimeValue(Time{0}),
85 .AddAttribute(
86 "FragmentationThreshold",
87 "If the size of the PSDU is bigger than this value, we fragment it such that the "
88 "size of the fragments are equal or smaller. "
89 "This value does not apply when it is carried in an A-MPDU. "
90 "This value will not have any effect on some rate control algorithms.",
91 UintegerValue(65535),
94 MakeUintegerChecker<uint32_t>())
95 .AddAttribute("NonUnicastMode",
96 "Wifi mode used for non-unicast transmissions.",
100 .AddAttribute("DefaultTxPowerLevel",
101 "Default power level to be used for transmissions. "
102 "This is the power level that is used by all those WifiManagers that do "
103 "not implement TX power control.",
104 UintegerValue(0),
106 MakeUintegerChecker<uint8_t>())
107 .AddAttribute("ErpProtectionMode",
108 "Protection mode used when non-ERP STAs are connected to an ERP AP: "
109 "Rts-Cts or Cts-To-Self",
111 MakeEnumAccessor<WifiRemoteStationManager::ProtectionMode>(
114 "Rts-Cts",
116 "Cts-To-Self"))
117 .AddAttribute("HtProtectionMode",
118 "Protection mode used when non-HT STAs are connected to a HT AP: Rts-Cts "
119 "or Cts-To-Self",
121 MakeEnumAccessor<WifiRemoteStationManager::ProtectionMode>(
124 "Rts-Cts",
126 "Cts-To-Self"))
127 .AddTraceSource("MacTxRtsFailed",
128 "The transmission of a RTS by the MAC layer has failed",
130 "ns3::Mac48Address::TracedCallback")
131 .AddTraceSource("MacTxDataFailed",
132 "The transmission of a data packet by the MAC layer has failed",
134 "ns3::Mac48Address::TracedCallback")
135 .AddTraceSource(
136 "MacTxFinalRtsFailed",
137 "The transmission of a RTS has exceeded the maximum number of attempts",
139 "ns3::Mac48Address::TracedCallback")
140 .AddTraceSource(
141 "MacTxFinalDataFailed",
142 "The transmission of a data packet has exceeded the maximum number of attempts",
144 "ns3::Mac48Address::TracedCallback");
145 return tid;
146}
147
149 : m_useNonErpProtection(false),
150 m_useNonHtProtection(false),
151 m_shortPreambleEnabled(false),
152 m_shortSlotTimeEnabled(false)
153{
154 NS_LOG_FUNCTION(this);
155 m_ssrc.fill(0);
156 m_slrc.fill(0);
157}
158
160{
161 NS_LOG_FUNCTION(this);
162}
163
164void
166{
167 NS_LOG_FUNCTION(this);
168 Reset();
169}
170
171void
173{
174 NS_LOG_FUNCTION(this << phy);
175 // We need to track our PHY because it is the object that knows the
176 // full set of transmit rates that are supported. We need to know
177 // this in order to find the relevant mandatory rates when choosing a
178 // transmit rate for automatic control responses like
179 // acknowledgments.
180 m_wifiPhy = phy;
181}
182
183void
185{
186 NS_LOG_FUNCTION(this << mac);
187 // We need to track our MAC because it is the object that knows the
188 // full set of interframe spaces.
189 m_wifiMac = mac;
190}
191
192int64_t
194{
195 NS_LOG_FUNCTION(this << stream);
196 return 0;
197}
198
199void
201{
202 NS_LOG_FUNCTION(this << maxSsrc);
203 m_maxSsrc = maxSsrc;
204}
205
206void
208{
209 NS_LOG_FUNCTION(this << maxSlrc);
210 m_maxSlrc = maxSlrc;
211}
212
213void
215{
216 NS_LOG_FUNCTION(this << threshold);
217 m_rtsCtsThreshold = threshold;
218}
219
220void
222{
223 NS_LOG_FUNCTION(this << threshold);
225}
226
227void
229{
230 NS_LOG_FUNCTION(this << enable);
231 m_shortPreambleEnabled = enable;
232}
233
234void
236{
237 NS_LOG_FUNCTION(this << enable);
238 m_shortSlotTimeEnabled = enable;
239}
240
241bool
243{
245}
246
247bool
249{
251}
252
253bool
255{
256 return (m_wifiPhy->GetDevice()->GetHtConfiguration() &&
258}
259
260bool
262{
266}
267
268bool
270{
271 return bool(m_wifiPhy->GetDevice()->GetHeConfiguration());
272}
273
274bool
276{
277 return bool(m_wifiPhy->GetDevice()->GetEhtConfiguration());
278}
279
280bool
282{
283 if (auto htConfiguration = m_wifiPhy->GetDevice()->GetHtConfiguration())
284 {
285 return htConfiguration->GetLdpcSupported();
286 }
287 return false;
288}
289
290bool
292{
293 if (auto htConfiguration = m_wifiPhy->GetDevice()->GetHtConfiguration())
294 {
295 return htConfiguration->GetShortGuardIntervalSupported();
296 }
297 return false;
298}
299
300uint16_t
302{
303 uint16_t gi = 0;
304 if (GetHeSupported())
305 {
307 NS_ASSERT(heConfiguration); // If HE is supported, we should have a HE configuration
308 // attached
309 gi = static_cast<uint16_t>(heConfiguration->GetGuardInterval().GetNanoSeconds());
310 }
311 return gi;
312}
313
316{
318}
319
320void
322 bool isShortPreambleSupported)
323{
324 NS_LOG_FUNCTION(this << address << isShortPreambleSupported);
325 NS_ASSERT(!address.IsGroup());
326 LookupState(address)->m_shortPreamble = isShortPreambleSupported;
327}
328
329void
331 bool isShortSlotTimeSupported)
332{
333 NS_LOG_FUNCTION(this << address << isShortSlotTimeSupported);
334 NS_ASSERT(!address.IsGroup());
335 LookupState(address)->m_shortSlotTime = isShortSlotTimeSupported;
336}
337
338void
340{
341 NS_LOG_FUNCTION(this << address << mode);
342 NS_ASSERT(!address.IsGroup());
343 auto state = LookupState(address);
344 for (const auto& i : state->m_operationalRateSet)
345 {
346 if (i == mode)
347 {
348 return; // already in
349 }
350 }
351 if ((mode.GetModulationClass() == WIFI_MOD_CLASS_DSSS) ||
353 {
354 state->m_dsssSupported = true;
355 }
357 {
358 state->m_erpOfdmSupported = true;
359 }
360 else if (mode.GetModulationClass() == WIFI_MOD_CLASS_OFDM)
361 {
362 state->m_ofdmSupported = true;
363 }
364 state->m_operationalRateSet.push_back(mode);
365}
366
367void
369{
370 NS_LOG_FUNCTION(this << address);
371 NS_ASSERT(!address.IsGroup());
372 auto state = LookupState(address);
373 state->m_operationalRateSet.clear();
374 for (const auto& mode : m_wifiPhy->GetModeList())
375 {
376 state->m_operationalRateSet.push_back(mode);
377 if (mode.IsMandatory())
378 {
379 AddBasicMode(mode);
380 }
381 }
382}
383
384void
386{
387 NS_LOG_FUNCTION(this << address);
388 NS_ASSERT(!address.IsGroup());
389 auto state = LookupState(address);
390
391 const auto& mcsList = m_wifiPhy->GetMcsList();
392 state->m_operationalMcsSet = WifiModeList(mcsList.begin(), mcsList.end());
393}
394
395void
397{
398 NS_LOG_FUNCTION(this << address);
399 NS_ASSERT(!address.IsGroup());
400 LookupState(address)->m_operationalMcsSet.clear();
401}
402
403void
405{
406 NS_LOG_FUNCTION(this << address << mcs);
407 NS_ASSERT(!address.IsGroup());
408 auto state = LookupState(address);
409 for (const auto& i : state->m_operationalMcsSet)
410 {
411 if (i == mcs)
412 {
413 return; // already in
414 }
415 }
416 state->m_operationalMcsSet.push_back(mcs);
417}
418
419bool
421{
422 return LookupState(address)->m_shortPreamble;
423}
424
425bool
427{
428 return LookupState(address)->m_shortSlotTime;
429}
430
431bool
433{
434 return LookupState(address)->m_qosSupported;
435}
436
437bool
439{
440 if (address.IsGroup())
441 {
442 return false;
443 }
444 return LookupState(address)->m_state == WifiRemoteStationState::BRAND_NEW;
445}
446
447bool
449{
450 if (address.IsGroup())
451 {
452 return true;
453 }
454 return LookupState(address)->m_state == WifiRemoteStationState::GOT_ASSOC_TX_OK;
455}
456
457bool
459{
460 if (address.IsGroup())
461 {
462 return false;
463 }
464 return LookupState(address)->m_state == WifiRemoteStationState::WAIT_ASSOC_TX_OK;
465}
466
467void
469{
470 NS_ASSERT(!address.IsGroup());
472}
473
474void
476{
477 NS_ASSERT(!address.IsGroup());
479}
480
481void
483{
484 NS_ASSERT(!address.IsGroup());
486}
487
488void
490{
491 NS_ASSERT(!address.IsGroup());
493}
494
495bool
497{
498 if (address.IsGroup())
499 {
500 return false;
501 }
502 return LookupState(address)->m_state == WifiRemoteStationState::ASSOC_REFUSED;
503}
504
505void
507{
508 NS_ASSERT(!address.IsGroup());
510}
511
512uint16_t
514{
515 std::shared_ptr<WifiRemoteStationState> state;
516 if (!remoteAddress.IsGroup() &&
517 (state = LookupState(remoteAddress))->m_state == WifiRemoteStationState::GOT_ASSOC_TX_OK)
518 {
519 return state->m_aid;
520 }
521 return SU_STA_ID;
522}
523
524uint16_t
526{
527 NS_LOG_FUNCTION(this << address << txVector);
528
529 uint16_t staId = SU_STA_ID;
530
531 if (txVector.IsMu())
532 {
533 if (m_wifiMac->GetTypeOfStation() == AP)
534 {
535 staId = GetAssociationId(address);
536 }
537 else if (m_wifiMac->GetTypeOfStation() == STA)
538 {
539 Ptr<StaWifiMac> staMac = StaticCast<StaWifiMac>(m_wifiMac);
540 if (staMac->IsAssociated())
541 {
542 staId = staMac->GetAssociationId();
543 }
544 }
545 }
546
547 NS_LOG_DEBUG("Returning STAID = " << staId);
548 return staId;
549}
550
551bool
553{
554 return LookupState(address)->m_isInPsMode;
555}
556
557void
558WifiRemoteStationManager::SetPsMode(const Mac48Address& address, bool isInPsMode)
559{
560 LookupState(address)->m_isInPsMode = isInPsMode;
561}
562
563std::optional<Mac48Address>
565{
566 if (auto stateIt = m_states.find(address);
567 stateIt != m_states.end() && stateIt->second->m_mleCommonInfo)
568 {
569 return stateIt->second->m_mleCommonInfo->m_mldMacAddress;
570 }
571
572 return std::nullopt;
573}
574
575std::optional<Mac48Address>
577{
578 auto stateIt = m_states.find(mldAddress);
579
580 if (stateIt == m_states.end() || !stateIt->second->m_mleCommonInfo)
581 {
582 // MLD address not found
583 return std::nullopt;
584 }
585
586 NS_ASSERT(stateIt->second->m_mleCommonInfo->m_mldMacAddress == mldAddress);
587 return stateIt->second->m_address;
588}
589
591WifiRemoteStationManager::GetDataTxVector(const WifiMacHeader& header, uint16_t allowedWidth)
592{
593 NS_LOG_FUNCTION(this << header << allowedWidth);
594 Mac48Address address = header.GetAddr1();
595 if (!header.IsMgt() && address.IsGroup())
596 {
598 WifiTxVector v;
599 v.SetMode(mode);
603 v.SetChannelWidth(m_wifiPhy->GetTxBandwidth(mode, allowedWidth));
606 v.SetNss(1);
607 v.SetNess(0);
608 return v;
609 }
610 WifiTxVector txVector;
611 if (header.IsMgt())
612 {
613 // Use the lowest basic rate for management frames
614 WifiMode mgtMode;
615 if (GetNBasicModes() > 0)
616 {
617 mgtMode = GetBasicMode(0);
618 }
619 else
620 {
621 mgtMode = GetDefaultMode();
622 }
623 txVector.SetMode(mgtMode);
624 txVector.SetPreambleType(
627 uint16_t channelWidth = allowedWidth;
628 if (!header.GetAddr1().IsGroup())
629 {
630 if (uint16_t rxWidth = GetChannelWidthSupported(header.GetAddr1());
631 rxWidth < channelWidth)
632 {
633 channelWidth = rxWidth;
634 }
635 }
636
637 txVector.SetChannelWidth(m_wifiPhy->GetTxBandwidth(mgtMode, channelWidth));
638 txVector.SetGuardInterval(
640 }
641 else
642 {
643 txVector = DoGetDataTxVector(Lookup(address), allowedWidth);
645 ? false
646 : UseLdpcForDestination(address));
647 }
649 if (heConfiguration)
650 {
651 txVector.SetBssColor(heConfiguration->GetBssColor());
652 }
653 // If both the allowed width and the TXVECTOR channel width are integer multiple
654 // of 20 MHz, then the TXVECTOR channel width must not exceed the allowed width
655 NS_ASSERT_MSG((txVector.GetChannelWidth() % 20 != 0) || (allowedWidth % 20 != 0) ||
656 (txVector.GetChannelWidth() <= allowedWidth),
657 "TXVECTOR channel width (" << txVector.GetChannelWidth()
658 << " MHz) exceeds allowed width (" << allowedWidth
659 << " MHz)");
660 return txVector;
661}
662
665{
666 WifiMode defaultMode = GetDefaultMode();
667 WifiPreamble defaultPreamble;
668 if (defaultMode.GetModulationClass() == WIFI_MOD_CLASS_EHT)
669 {
670 defaultPreamble = WIFI_PREAMBLE_EHT_MU;
671 }
672 else if (defaultMode.GetModulationClass() == WIFI_MOD_CLASS_HE)
673 {
674 defaultPreamble = WIFI_PREAMBLE_HE_SU;
675 }
676 else if (defaultMode.GetModulationClass() == WIFI_MOD_CLASS_VHT)
677 {
678 defaultPreamble = WIFI_PREAMBLE_VHT_SU;
679 }
680 else if (defaultMode.GetModulationClass() == WIFI_MOD_CLASS_HT)
681 {
682 defaultPreamble = WIFI_PREAMBLE_HT_MF;
683 }
684 else
685 {
686 defaultPreamble = WIFI_PREAMBLE_LONG;
687 }
688
689 return WifiTxVector(defaultMode,
691 defaultPreamble,
694 1,
695 0,
696 m_wifiPhy->GetTxBandwidth(defaultMode),
697 false);
698}
699
702{
703 NS_LOG_FUNCTION(this << address << allowedWidth);
704 WifiTxVector v;
705 if (address.IsGroup())
706 {
708 v.SetMode(mode);
715 v.SetNss(1);
716 v.SetNess(0);
717 }
718 else
719 {
720 v = DoGetRtsTxVector(Lookup(address));
721 }
722 auto modulation = v.GetModulationClass();
723
724 if (allowedWidth >= 40 &&
725 (modulation == WIFI_MOD_CLASS_DSSS || modulation == WIFI_MOD_CLASS_HR_DSSS))
726 {
727 // RTS must be sent in a non-HT duplicate PPDU because it must protect a frame being
728 // transmitted on at least 40 MHz. Change the modulation class to ERP-OFDM and the rate
729 // to 6 Mbps
731 modulation = v.GetModulationClass();
732 }
733 // do not set allowedWidth as the TX width if the modulation class is (HR-)DSSS (allowedWidth
734 // may be >= 40 MHz) or allowedWidth is 22 MHz (the selected modulation class may be OFDM)
735 if (modulation != WIFI_MOD_CLASS_DSSS && modulation != WIFI_MOD_CLASS_HR_DSSS &&
736 allowedWidth != 22)
737 {
738 v.SetChannelWidth(allowedWidth);
739 }
740
741 return v;
742}
743
746{
747 NS_ASSERT(!to.IsGroup());
748 WifiMode ctsMode = GetControlAnswerMode(rtsTxMode);
749 WifiTxVector v;
750 v.SetMode(ctsMode);
755 uint16_t ctsTxGuardInterval =
757 v.SetGuardInterval(ctsTxGuardInterval);
758 v.SetNss(1);
759 return v;
760}
761
762void
764{
765 NS_LOG_FUNCTION(this << txVector);
766
767 auto txMode = txVector.GetMode();
768 if (txMode.GetModulationClass() >= WIFI_MOD_CLASS_HT)
769 {
770 auto rate = txMode.GetDataRate(txVector);
771 if (rate >= 24e6)
772 {
773 rate = 24e6;
774 }
775 else if (rate >= 12e6)
776 {
777 rate = 12e6;
778 }
779 else
780 {
781 rate = 6e6;
782 }
785 {
786 txVector.SetMode(ErpOfdmPhy::GetErpOfdmRate(rate));
787 }
788 else
789 {
790 txVector.SetMode(OfdmPhy::GetOfdmRate(rate));
791 }
792 }
793}
794
797{
798 NS_ASSERT(!to.IsGroup());
799 WifiMode ackMode = GetControlAnswerMode(dataTxVector.GetMode(GetStaId(to, dataTxVector)));
800 WifiTxVector v;
801 v.SetMode(ackMode);
806 uint16_t ackTxGuardInterval =
808 v.SetGuardInterval(ackTxGuardInterval);
809 v.SetNss(1);
810 return v;
811}
812
815 const WifiTxVector& dataTxVector) const
816{
817 NS_ASSERT(!to.IsGroup());
818 WifiMode blockAckMode = GetControlAnswerMode(dataTxVector.GetMode(GetStaId(to, dataTxVector)));
819 WifiTxVector v;
820 v.SetMode(blockAckMode);
824 v.SetChannelWidth(m_wifiPhy->GetTxBandwidth(blockAckMode));
825 uint16_t blockAckTxGuardInterval =
827 v.SetGuardInterval(blockAckTxGuardInterval);
828 v.SetNss(1);
829 return v;
830}
831
834{
835 /**
836 * The standard has relatively unambiguous rules for selecting a
837 * control response rate (the below is quoted from IEEE 802.11-2012,
838 * Section 9.7):
839 *
840 * To allow the transmitting STA to calculate the contents of the
841 * Duration/ID field, a STA responding to a received frame shall
842 * transmit its Control Response frame (either CTS or Ack), other
843 * than the BlockAck control frame, at the highest rate in the
844 * BSSBasicRateSet parameter that is less than or equal to the
845 * rate of the immediately previous frame in the frame exchange
846 * sequence (as defined in Annex G) and that is of the same
847 * modulation class (see Section 9.7.8) as the received frame...
848 */
849 NS_LOG_FUNCTION(this << reqMode);
850 WifiMode mode = GetDefaultMode();
851 bool found = false;
852 // First, search the BSS Basic Rate set
853 for (uint8_t i = 0; i < GetNBasicModes(); i++)
854 {
855 WifiMode testMode = GetBasicMode(i);
856 if ((!found || testMode.IsHigherDataRate(mode)) && (!testMode.IsHigherDataRate(reqMode)) &&
858 testMode.GetModulationClass())))
859 {
860 mode = testMode;
861 // We've found a potentially-suitable transmit rate, but we
862 // need to continue and consider all the basic rates before
863 // we can be sure we've got the right one.
864 found = true;
865 }
866 }
868 {
869 if (!found)
870 {
871 mode = GetDefaultMcs();
872 for (uint8_t i = 0; i != GetNBasicMcs(); i++)
873 {
874 WifiMode testMode = GetBasicMcs(i);
875 if ((!found || testMode.IsHigherDataRate(mode)) &&
876 (!testMode.IsHigherDataRate(reqMode)) &&
877 (testMode.GetModulationClass() == reqMode.GetModulationClass()))
878 {
879 mode = testMode;
880 // We've found a potentially-suitable transmit rate, but we
881 // need to continue and consider all the basic rates before
882 // we can be sure we've got the right one.
883 found = true;
884 }
885 }
886 }
887 }
888 // If we found a suitable rate in the BSSBasicRateSet, then we are
889 // done and can return that mode.
890 if (found)
891 {
892 NS_LOG_DEBUG("WifiRemoteStationManager::GetControlAnswerMode returning " << mode);
893 return mode;
894 }
895
896 /**
897 * If no suitable basic rate was found, we search the mandatory
898 * rates. The standard (IEEE 802.11-2007, Section 9.6) says:
899 *
900 * ...If no rate contained in the BSSBasicRateSet parameter meets
901 * these conditions, then the control frame sent in response to a
902 * received frame shall be transmitted at the highest mandatory
903 * rate of the PHY that is less than or equal to the rate of the
904 * received frame, and that is of the same modulation class as the
905 * received frame. In addition, the Control Response frame shall
906 * be sent using the same PHY options as the received frame,
907 * unless they conflict with the requirement to use the
908 * BSSBasicRateSet parameter.
909 *
910 * \todo Note that we're ignoring the last sentence for now, because
911 * there is not yet any manipulation here of PHY options.
912 */
913 for (const auto& thismode : m_wifiPhy->GetModeList())
914 {
915 /* If the rate:
916 *
917 * - is a mandatory rate for the PHY, and
918 * - is equal to or faster than our current best choice, and
919 * - is less than or equal to the rate of the received frame, and
920 * - is of the same modulation class as the received frame
921 *
922 * ...then it's our best choice so far.
923 */
924 if (thismode.IsMandatory() && (!found || thismode.IsHigherDataRate(mode)) &&
925 (!thismode.IsHigherDataRate(reqMode)) &&
927 thismode.GetModulationClass())))
928 {
929 mode = thismode;
930 // As above; we've found a potentially-suitable transmit
931 // rate, but we need to continue and consider all the
932 // mandatory rates before we can be sure we've got the right one.
933 found = true;
934 }
935 }
937 {
938 for (const auto& thismode : m_wifiPhy->GetMcsList())
939 {
940 if (thismode.IsMandatory() && (!found || thismode.IsHigherDataRate(mode)) &&
941 (!thismode.IsHigherCodeRate(reqMode)) &&
942 (thismode.GetModulationClass() == reqMode.GetModulationClass()))
943 {
944 mode = thismode;
945 // As above; we've found a potentially-suitable transmit
946 // rate, but we need to continue and consider all the
947 // mandatory rates before we can be sure we've got the right one.
948 found = true;
949 }
950 }
951 }
952
953 /**
954 * If we still haven't found a suitable rate for the response then
955 * someone has messed up the simulation configuration. This probably means
956 * that the WifiPhyStandard is not set correctly, or that a rate that
957 * is not supported by the PHY has been explicitly requested.
958 *
959 * Either way, it is serious - we can either disobey the standard or
960 * fail, and I have chosen to do the latter...
961 */
962 if (!found)
963 {
964 NS_FATAL_ERROR("Can't find response rate for " << reqMode);
965 }
966
967 NS_LOG_DEBUG("WifiRemoteStationManager::GetControlAnswerMode returning " << mode);
968 return mode;
969}
970
971void
973{
974 NS_LOG_FUNCTION(this << header);
975 NS_ASSERT(!header.GetAddr1().IsGroup());
976 AcIndex ac = QosUtilsMapTidToAc((header.IsQosData()) ? header.GetQosTid() : 0);
977 m_ssrc[ac]++;
978 m_macTxRtsFailed(header.GetAddr1());
980}
981
982void
984{
985 NS_LOG_FUNCTION(this << *mpdu);
986 NS_ASSERT(!mpdu->GetHeader().GetAddr1().IsGroup());
987 AcIndex ac =
988 QosUtilsMapTidToAc((mpdu->GetHeader().IsQosData()) ? mpdu->GetHeader().GetQosTid() : 0);
989 bool longMpdu = (mpdu->GetSize() > m_rtsCtsThreshold);
990 if (longMpdu)
991 {
992 m_slrc[ac]++;
993 }
994 else
995 {
996 m_ssrc[ac]++;
997 }
998 m_macTxDataFailed(mpdu->GetHeader().GetAddr1());
999 DoReportDataFailed(Lookup(mpdu->GetHeader().GetAddr1()));
1000}
1001
1002void
1004 double ctsSnr,
1005 WifiMode ctsMode,
1006 double rtsSnr)
1007{
1008 NS_LOG_FUNCTION(this << header << ctsSnr << ctsMode << rtsSnr);
1009 NS_ASSERT(!header.GetAddr1().IsGroup());
1010 WifiRemoteStation* station = Lookup(header.GetAddr1());
1011 AcIndex ac = QosUtilsMapTidToAc((header.IsQosData()) ? header.GetQosTid() : 0);
1012 station->m_state->m_info.NotifyTxSuccess(m_ssrc[ac]);
1013 m_ssrc[ac] = 0;
1014 DoReportRtsOk(station, ctsSnr, ctsMode, rtsSnr);
1015}
1016
1017void
1019 double ackSnr,
1020 WifiMode ackMode,
1021 double dataSnr,
1022 WifiTxVector dataTxVector)
1023{
1024 NS_LOG_FUNCTION(this << *mpdu << ackSnr << ackMode << dataSnr << dataTxVector);
1025 const WifiMacHeader& hdr = mpdu->GetHeader();
1026 NS_ASSERT(!hdr.GetAddr1().IsGroup());
1027 WifiRemoteStation* station = Lookup(hdr.GetAddr1());
1028 AcIndex ac = QosUtilsMapTidToAc((hdr.IsQosData()) ? hdr.GetQosTid() : 0);
1029 bool longMpdu = (mpdu->GetSize() > m_rtsCtsThreshold);
1030 if (longMpdu)
1031 {
1032 station->m_state->m_info.NotifyTxSuccess(m_slrc[ac]);
1033 m_slrc[ac] = 0;
1034 }
1035 else
1036 {
1037 station->m_state->m_info.NotifyTxSuccess(m_ssrc[ac]);
1038 m_ssrc[ac] = 0;
1039 }
1040 DoReportDataOk(station,
1041 ackSnr,
1042 ackMode,
1043 dataSnr,
1044 dataTxVector.GetChannelWidth(),
1045 dataTxVector.GetNss(GetStaId(hdr.GetAddr1(), dataTxVector)));
1046}
1047
1048void
1050{
1051 NS_LOG_FUNCTION(this << header);
1052 NS_ASSERT(!header.GetAddr1().IsGroup());
1053 WifiRemoteStation* station = Lookup(header.GetAddr1());
1054 AcIndex ac = QosUtilsMapTidToAc((header.IsQosData()) ? header.GetQosTid() : 0);
1055 station->m_state->m_info.NotifyTxFailed();
1056 m_ssrc[ac] = 0;
1058 DoReportFinalRtsFailed(station);
1059}
1060
1061void
1063{
1064 NS_LOG_FUNCTION(this << *mpdu);
1065 NS_ASSERT(!mpdu->GetHeader().GetAddr1().IsGroup());
1066 WifiRemoteStation* station = Lookup(mpdu->GetHeader().GetAddr1());
1067 AcIndex ac =
1068 QosUtilsMapTidToAc((mpdu->GetHeader().IsQosData()) ? mpdu->GetHeader().GetQosTid() : 0);
1069 station->m_state->m_info.NotifyTxFailed();
1070 bool longMpdu = (mpdu->GetSize() > m_rtsCtsThreshold);
1071 if (longMpdu)
1072 {
1073 m_slrc[ac] = 0;
1074 }
1075 else
1076 {
1077 m_ssrc[ac] = 0;
1078 }
1079 m_macTxFinalDataFailed(mpdu->GetHeader().GetAddr1());
1080 DoReportFinalDataFailed(station);
1081}
1082
1083void
1085 RxSignalInfo rxSignalInfo,
1086 WifiTxVector txVector)
1087{
1088 NS_LOG_FUNCTION(this << address << rxSignalInfo << txVector);
1089 if (address.IsGroup())
1090 {
1091 return;
1092 }
1093 WifiRemoteStation* station = Lookup(address);
1094 DoReportRxOk(station, rxSignalInfo.snr, txVector.GetMode(GetStaId(address, txVector)));
1095 station->m_rssiAndUpdateTimePair = std::make_pair(rxSignalInfo.rssi, Simulator::Now());
1096}
1097
1098void
1100 uint16_t nSuccessfulMpdus,
1101 uint16_t nFailedMpdus,
1102 double rxSnr,
1103 double dataSnr,
1104 WifiTxVector dataTxVector)
1105{
1106 NS_LOG_FUNCTION(this << address << nSuccessfulMpdus << nFailedMpdus << rxSnr << dataSnr
1107 << dataTxVector);
1108 NS_ASSERT(!address.IsGroup());
1109 for (uint16_t i = 0; i < nFailedMpdus; i++)
1110 {
1111 m_macTxDataFailed(address);
1112 }
1114 nSuccessfulMpdus,
1115 nFailedMpdus,
1116 rxSnr,
1117 dataSnr,
1118 dataTxVector.GetChannelWidth(),
1119 dataTxVector.GetNss(GetStaId(address, dataTxVector)));
1120}
1121
1122bool
1124{
1125 NS_LOG_FUNCTION(this << header << &txParams);
1126 auto address = header.GetAddr1();
1127 const auto modulationClass = txParams.m_txVector.GetModulationClass();
1128 if (address.IsGroup())
1129 {
1130 return false;
1131 }
1133 ((modulationClass == WIFI_MOD_CLASS_ERP_OFDM) || (modulationClass == WIFI_MOD_CLASS_HT) ||
1134 (modulationClass == WIFI_MOD_CLASS_VHT) || (modulationClass == WIFI_MOD_CLASS_HE) ||
1135 (modulationClass == WIFI_MOD_CLASS_EHT)) &&
1137 {
1139 "WifiRemoteStationManager::NeedRTS returning true to protect non-ERP stations");
1140 return true;
1141 }
1142 else if (m_htProtectionMode == RTS_CTS &&
1143 ((modulationClass == WIFI_MOD_CLASS_HT) || (modulationClass == WIFI_MOD_CLASS_VHT)) &&
1145 {
1146 NS_LOG_DEBUG("WifiRemoteStationManager::NeedRTS returning true to protect non-HT stations");
1147 return true;
1148 }
1149 NS_ASSERT(txParams.m_txDuration.has_value());
1150 auto size = txParams.GetSize(header.GetAddr1());
1151 bool normally =
1154 return DoNeedRts(Lookup(address), size, normally);
1155}
1156
1157bool
1159{
1160 WifiMode mode = txVector.GetMode();
1161 NS_LOG_FUNCTION(this << mode);
1169 {
1171 "WifiRemoteStationManager::NeedCtsToSelf returning true to protect non-ERP stations");
1172 return true;
1173 }
1174 else if (m_htProtectionMode == CTS_TO_SELF &&
1178 {
1180 "WifiRemoteStationManager::NeedCtsToSelf returning true to protect non-HT stations");
1181 return true;
1182 }
1183 else if (!m_useNonErpProtection)
1184 {
1185 // search for the BSS Basic Rate set, if the used mode is in the basic set then there is no
1186 // need for CTS To Self
1187 for (auto i = m_bssBasicRateSet.begin(); i != m_bssBasicRateSet.end(); i++)
1188 {
1189 if (mode == *i)
1190 {
1191 NS_LOG_DEBUG("WifiRemoteStationManager::NeedCtsToSelf returning false");
1192 return false;
1193 }
1194 }
1196 {
1197 // search for the BSS Basic MCS set, if the used mode is in the basic set then there is
1198 // no need for CTS To Self
1199 for (auto i = m_bssBasicMcsSet.begin(); i != m_bssBasicMcsSet.end(); i++)
1200 {
1201 if (mode == *i)
1202 {
1203 NS_LOG_DEBUG("WifiRemoteStationManager::NeedCtsToSelf returning false");
1204 return false;
1205 }
1206 }
1207 }
1208 NS_LOG_DEBUG("WifiRemoteStationManager::NeedCtsToSelf returning true");
1209 return true;
1210 }
1211 return false;
1212}
1213
1214void
1216{
1217 NS_LOG_FUNCTION(this << enable);
1218 m_useNonErpProtection = enable;
1219}
1220
1221bool
1223{
1224 return m_useNonErpProtection;
1225}
1226
1227void
1229{
1230 NS_LOG_FUNCTION(this << enable);
1231 m_useNonHtProtection = enable;
1232}
1233
1234bool
1236{
1237 return m_useNonHtProtection;
1238}
1239
1240bool
1242{
1243 NS_LOG_FUNCTION(this << *mpdu);
1244 NS_ASSERT(!mpdu->GetHeader().GetAddr1().IsGroup());
1245 AcIndex ac =
1246 QosUtilsMapTidToAc((mpdu->GetHeader().IsQosData()) ? mpdu->GetHeader().GetQosTid() : 0);
1247 bool longMpdu = (mpdu->GetSize() > m_rtsCtsThreshold);
1248 uint32_t retryCount;
1249 uint32_t maxRetryCount;
1250 if (longMpdu)
1251 {
1252 retryCount = m_slrc[ac];
1253 maxRetryCount = m_maxSlrc;
1254 }
1255 else
1256 {
1257 retryCount = m_ssrc[ac];
1258 maxRetryCount = m_maxSsrc;
1259 }
1260 bool normally = retryCount < maxRetryCount;
1261 NS_LOG_DEBUG("WifiRemoteStationManager::NeedRetransmission count: "
1262 << retryCount << " result: " << std::boolalpha << normally);
1263 return DoNeedRetransmission(Lookup(mpdu->GetHeader().GetAddr1()), mpdu->GetPacket(), normally);
1264}
1265
1266bool
1268{
1269 NS_LOG_FUNCTION(this << *mpdu);
1270 if (mpdu->GetHeader().GetAddr1().IsGroup())
1271 {
1272 return false;
1273 }
1274 bool normally = mpdu->GetSize() > GetFragmentationThreshold();
1275 NS_LOG_DEBUG("WifiRemoteStationManager::NeedFragmentation result: " << std::boolalpha
1276 << normally);
1277 return DoNeedFragmentation(Lookup(mpdu->GetHeader().GetAddr1()), mpdu->GetPacket(), normally);
1278}
1279
1280void
1282{
1283 NS_LOG_FUNCTION(this << threshold);
1284 if (threshold < 256)
1285 {
1286 /*
1287 * ASN.1 encoding of the MAC and PHY MIB (256 ... 8000)
1288 */
1289 NS_LOG_WARN("Fragmentation threshold should be larger than 256. Setting to 256.");
1291 }
1292 else
1293 {
1294 /*
1295 * The length of each fragment shall be an even number of octets, except for the last
1296 * fragment if an MSDU or MMPDU, which may be either an even or an odd number of octets.
1297 */
1298 if (threshold % 2 != 0)
1299 {
1300 NS_LOG_WARN("Fragmentation threshold should be an even number. Setting to "
1301 << threshold - 1);
1302 m_fragmentationThreshold = threshold - 1;
1303 }
1304 else
1305 {
1306 m_fragmentationThreshold = threshold;
1307 }
1308 }
1309}
1310
1313{
1315}
1316
1319{
1320 NS_LOG_FUNCTION(this << *mpdu);
1321 // The number of bytes a fragment can support is (Threshold - WIFI_HEADER_SIZE - WIFI_FCS).
1322 uint32_t nFragments =
1323 (mpdu->GetPacket()->GetSize() /
1324 (GetFragmentationThreshold() - mpdu->GetHeader().GetSize() - WIFI_MAC_FCS_LENGTH));
1325
1326 // If the size of the last fragment is not 0.
1327 if ((mpdu->GetPacket()->GetSize() %
1328 (GetFragmentationThreshold() - mpdu->GetHeader().GetSize() - WIFI_MAC_FCS_LENGTH)) > 0)
1329 {
1330 nFragments++;
1331 }
1332 NS_LOG_DEBUG("WifiRemoteStationManager::GetNFragments returning " << nFragments);
1333 return nFragments;
1334}
1335
1338{
1339 NS_LOG_FUNCTION(this << *mpdu << fragmentNumber);
1340 NS_ASSERT(!mpdu->GetHeader().GetAddr1().IsGroup());
1341 uint32_t nFragment = GetNFragments(mpdu);
1342 if (fragmentNumber >= nFragment)
1343 {
1344 NS_LOG_DEBUG("WifiRemoteStationManager::GetFragmentSize returning 0");
1345 return 0;
1346 }
1347 // Last fragment
1348 if (fragmentNumber == nFragment - 1)
1349 {
1350 uint32_t lastFragmentSize =
1351 mpdu->GetPacket()->GetSize() -
1352 (fragmentNumber *
1353 (GetFragmentationThreshold() - mpdu->GetHeader().GetSize() - WIFI_MAC_FCS_LENGTH));
1354 NS_LOG_DEBUG("WifiRemoteStationManager::GetFragmentSize returning " << lastFragmentSize);
1355 return lastFragmentSize;
1356 }
1357 // All fragments but the last, the number of bytes is (Threshold - WIFI_HEADER_SIZE - WIFI_FCS).
1358 else
1359 {
1360 uint32_t fragmentSize =
1361 GetFragmentationThreshold() - mpdu->GetHeader().GetSize() - WIFI_MAC_FCS_LENGTH;
1362 NS_LOG_DEBUG("WifiRemoteStationManager::GetFragmentSize returning " << fragmentSize);
1363 return fragmentSize;
1364 }
1365}
1366
1369{
1370 NS_LOG_FUNCTION(this << *mpdu << fragmentNumber);
1371 NS_ASSERT(!mpdu->GetHeader().GetAddr1().IsGroup());
1372 NS_ASSERT(fragmentNumber < GetNFragments(mpdu));
1373 uint32_t fragmentOffset = fragmentNumber * (GetFragmentationThreshold() -
1374 mpdu->GetHeader().GetSize() - WIFI_MAC_FCS_LENGTH);
1375 NS_LOG_DEBUG("WifiRemoteStationManager::GetFragmentOffset returning " << fragmentOffset);
1376 return fragmentOffset;
1377}
1378
1379bool
1381{
1382 NS_LOG_FUNCTION(this << *mpdu << fragmentNumber);
1383 NS_ASSERT(!mpdu->GetHeader().GetAddr1().IsGroup());
1384 bool isLast = fragmentNumber == (GetNFragments(mpdu) - 1);
1385 NS_LOG_DEBUG("WifiRemoteStationManager::IsLastFragment returning " << std::boolalpha << isLast);
1386 return isLast;
1387}
1388
1389uint8_t
1391{
1392 return m_defaultTxPowerLevel;
1393}
1394
1397{
1398 return LookupState(address)->m_info;
1399}
1400
1401std::optional<double>
1403{
1404 auto station = Lookup(address);
1405 auto rssi = station->m_rssiAndUpdateTimePair.first;
1406 auto ts = station->m_rssiAndUpdateTimePair.second;
1407 if (ts.IsStrictlyPositive())
1408 {
1409 return rssi;
1410 }
1411 return std::nullopt;
1412}
1413
1414std::shared_ptr<WifiRemoteStationState>
1416{
1417 NS_LOG_FUNCTION(this << address);
1418 auto stateIt = m_states.find(address);
1419
1420 if (stateIt != m_states.end())
1421 {
1422 NS_LOG_DEBUG("WifiRemoteStationManager::LookupState returning existing state");
1423 return stateIt->second;
1424 }
1425
1426 auto state = std::make_shared<WifiRemoteStationState>();
1427 state->m_state = WifiRemoteStationState::BRAND_NEW;
1428 state->m_address = address;
1429 state->m_aid = 0;
1430 state->m_operationalRateSet.push_back(GetDefaultMode());
1431 state->m_operationalMcsSet.push_back(GetDefaultMcs());
1432 state->m_dsssSupported = false;
1433 state->m_erpOfdmSupported = false;
1434 state->m_ofdmSupported = false;
1435 state->m_htCapabilities = nullptr;
1436 state->m_vhtCapabilities = nullptr;
1437 state->m_heCapabilities = nullptr;
1438 state->m_ehtCapabilities = nullptr;
1439 state->m_mleCommonInfo = nullptr;
1440 state->m_emlsrEnabled = false;
1441 state->m_channelWidth = m_wifiPhy->GetChannelWidth();
1442 state->m_guardInterval = GetGuardInterval();
1443 state->m_ness = 0;
1444 state->m_aggregation = false;
1445 state->m_qosSupported = false;
1446 state->m_isInPsMode = false;
1447 const_cast<WifiRemoteStationManager*>(this)->m_states.insert({address, state});
1448 NS_LOG_DEBUG("WifiRemoteStationManager::LookupState returning new state");
1449 return state;
1450}
1451
1452WifiRemoteStation*
1453WifiRemoteStationManager::Lookup(Mac48Address address) const
1454{
1455 NS_LOG_FUNCTION(this << address);
1456 NS_ASSERT(!address.IsGroup());
1457 NS_ASSERT(address != m_wifiMac->GetAddress());
1458 auto stationIt = m_stations.find(address);
1459
1460 if (stationIt != m_stations.end())
1461 {
1462 return stationIt->second;
1463 }
1464
1465 WifiRemoteStation* station = DoCreateStation();
1466 station->m_state = LookupState(address).get();
1467 station->m_rssiAndUpdateTimePair = std::make_pair(0, Seconds(0));
1468 const_cast<WifiRemoteStationManager*>(this)->m_stations.insert({address, station});
1469 return station;
1470}
1471
1472void
1473WifiRemoteStationManager::SetAssociationId(Mac48Address remoteAddress, uint16_t aid)
1474{
1475 NS_LOG_FUNCTION(this << remoteAddress << aid);
1476 LookupState(remoteAddress)->m_aid = aid;
1477}
1478
1479void
1480WifiRemoteStationManager::SetQosSupport(Mac48Address from, bool qosSupported)
1481{
1482 NS_LOG_FUNCTION(this << from << qosSupported);
1483 LookupState(from)->m_qosSupported = qosSupported;
1484}
1485
1486void
1487WifiRemoteStationManager::SetEmlsrEnabled(const Mac48Address& from, bool emlsrEnabled)
1488{
1489 NS_LOG_FUNCTION(this << from << emlsrEnabled);
1490 LookupState(from)->m_emlsrEnabled = emlsrEnabled;
1491}
1492
1493void
1494WifiRemoteStationManager::AddStationHtCapabilities(Mac48Address from, HtCapabilities htCapabilities)
1495{
1496 // Used by all stations to record HT capabilities of remote stations
1497 NS_LOG_FUNCTION(this << from << htCapabilities);
1498 auto state = LookupState(from);
1499 if (htCapabilities.GetSupportedChannelWidth() == 1)
1500 {
1501 state->m_channelWidth = 40;
1502 }
1503 else
1504 {
1505 state->m_channelWidth = 20;
1506 }
1507 SetQosSupport(from, true);
1508 for (const auto& mcs : m_wifiPhy->GetMcsList(WIFI_MOD_CLASS_HT))
1509 {
1510 if (htCapabilities.IsSupportedMcs(mcs.GetMcsValue()))
1511 {
1512 AddSupportedMcs(from, mcs);
1513 }
1514 }
1515 state->m_htCapabilities = Create<const HtCapabilities>(htCapabilities);
1516}
1517
1518void
1519WifiRemoteStationManager::AddStationVhtCapabilities(Mac48Address from,
1520 VhtCapabilities vhtCapabilities)
1521{
1522 // Used by all stations to record VHT capabilities of remote stations
1523 NS_LOG_FUNCTION(this << from << vhtCapabilities);
1524 auto state = LookupState(from);
1525 if (vhtCapabilities.GetSupportedChannelWidthSet() == 1)
1526 {
1527 state->m_channelWidth = 160;
1528 }
1529 else
1530 {
1531 state->m_channelWidth = 80;
1532 }
1533 for (uint8_t i = 1; i <= m_wifiPhy->GetMaxSupportedTxSpatialStreams(); i++)
1534 {
1535 for (const auto& mcs : m_wifiPhy->GetMcsList(WIFI_MOD_CLASS_VHT))
1536 {
1537 if (vhtCapabilities.IsSupportedMcs(mcs.GetMcsValue(), i))
1538 {
1539 AddSupportedMcs(from, mcs);
1540 }
1541 }
1542 }
1543 state->m_vhtCapabilities = Create<const VhtCapabilities>(vhtCapabilities);
1544}
1545
1546void
1547WifiRemoteStationManager::AddStationHeCapabilities(Mac48Address from, HeCapabilities heCapabilities)
1548{
1549 // Used by all stations to record HE capabilities of remote stations
1550 NS_LOG_FUNCTION(this << from << heCapabilities);
1551 auto state = LookupState(from);
1552 if ((m_wifiPhy->GetPhyBand() == WIFI_PHY_BAND_5GHZ) ||
1553 (m_wifiPhy->GetPhyBand() == WIFI_PHY_BAND_6GHZ))
1554 {
1555 if (heCapabilities.GetChannelWidthSet() & 0x04)
1556 {
1557 state->m_channelWidth = 160;
1558 }
1559 else if (heCapabilities.GetChannelWidthSet() & 0x02)
1560 {
1561 state->m_channelWidth = 80;
1562 }
1563 // For other cases at 5 GHz, the supported channel width is set by the VHT capabilities
1564 }
1565 else if (m_wifiPhy->GetPhyBand() == WIFI_PHY_BAND_2_4GHZ)
1566 {
1567 if (heCapabilities.GetChannelWidthSet() & 0x01)
1568 {
1569 state->m_channelWidth = 40;
1570 }
1571 else
1572 {
1573 state->m_channelWidth = 20;
1574 }
1575 }
1576 if (heCapabilities.GetHeSuPpdu1xHeLtf800nsGi())
1577 {
1578 state->m_guardInterval = 800;
1579 }
1580 else
1581 {
1582 // todo: Using 3200ns, default value for HeConfiguration::GuardInterval
1583 state->m_guardInterval = 3200;
1584 }
1585 for (const auto& mcs : m_wifiPhy->GetMcsList(WIFI_MOD_CLASS_HE))
1586 {
1587 if (heCapabilities.GetHighestMcsSupported() >= mcs.GetMcsValue())
1588 {
1589 AddSupportedMcs(from, mcs);
1590 }
1591 }
1592 state->m_heCapabilities = Create<const HeCapabilities>(heCapabilities);
1593 SetQosSupport(from, true);
1594}
1595
1596void
1597WifiRemoteStationManager::AddStationHe6GhzCapabilities(
1598 const Mac48Address& from,
1599 const He6GhzBandCapabilities& he6GhzCapabilities)
1600{
1601 // Used by all stations to record HE 6GHz band capabilities of remote stations
1602 NS_LOG_FUNCTION(this << from << he6GhzCapabilities);
1603 auto state = LookupState(from);
1604 state->m_he6GhzBandCapabilities = Create<const He6GhzBandCapabilities>(he6GhzCapabilities);
1605 SetQosSupport(from, true);
1606}
1607
1608void
1609WifiRemoteStationManager::AddStationEhtCapabilities(Mac48Address from,
1610 EhtCapabilities ehtCapabilities)
1611{
1612 // Used by all stations to record EHT capabilities of remote stations
1613 NS_LOG_FUNCTION(this << from << ehtCapabilities);
1614 auto state = LookupState(from);
1615 for (const auto& mcs : m_wifiPhy->GetMcsList(WIFI_MOD_CLASS_EHT))
1616 {
1617 for (uint8_t mapType = 0; mapType < EhtMcsAndNssSet::EHT_MCS_MAP_TYPE_MAX; ++mapType)
1618 {
1619 if (ehtCapabilities.GetHighestSupportedRxMcs(
1620 static_cast<EhtMcsAndNssSet::EhtMcsMapType>(mapType)) >= mcs.GetMcsValue())
1621 {
1622 AddSupportedMcs(from, mcs);
1623 }
1624 }
1625 }
1626 state->m_ehtCapabilities = Create<const EhtCapabilities>(ehtCapabilities);
1627 SetQosSupport(from, true);
1628}
1629
1630void
1631WifiRemoteStationManager::AddStationMleCommonInfo(
1632 Mac48Address from,
1633 const std::shared_ptr<CommonInfoBasicMle>& mleCommonInfo)
1634{
1635 NS_LOG_FUNCTION(this << from);
1636 auto state = LookupState(from);
1637 state->m_mleCommonInfo = mleCommonInfo;
1638 // insert another entry in m_states indexed by the MLD address and pointing to the same state
1639 const_cast<WifiRemoteStationManager*>(this)->m_states.insert(
1640 {mleCommonInfo->m_mldMacAddress, state});
1641}
1642
1643Ptr<const HtCapabilities>
1644WifiRemoteStationManager::GetStationHtCapabilities(Mac48Address from)
1645{
1646 return LookupState(from)->m_htCapabilities;
1647}
1648
1650WifiRemoteStationManager::GetStationVhtCapabilities(Mac48Address from)
1651{
1652 return LookupState(from)->m_vhtCapabilities;
1653}
1654
1656WifiRemoteStationManager::GetStationHeCapabilities(Mac48Address from)
1657{
1658 return LookupState(from)->m_heCapabilities;
1659}
1660
1662WifiRemoteStationManager::GetStationHe6GhzCapabilities(const Mac48Address& from) const
1663{
1664 return LookupState(from)->m_he6GhzBandCapabilities;
1665}
1666
1668WifiRemoteStationManager::GetStationEhtCapabilities(Mac48Address from)
1669{
1670 return LookupState(from)->m_ehtCapabilities;
1671}
1672
1673std::optional<std::reference_wrapper<CommonInfoBasicMle::EmlCapabilities>>
1674WifiRemoteStationManager::GetStationEmlCapabilities(const Mac48Address& from)
1675{
1676 if (auto state = LookupState(from);
1677 state->m_mleCommonInfo && state->m_mleCommonInfo->m_emlCapabilities)
1678 {
1679 return state->m_mleCommonInfo->m_emlCapabilities.value();
1680 }
1681 return std::nullopt;
1682}
1683
1684std::optional<std::reference_wrapper<CommonInfoBasicMle::MldCapabilities>>
1685WifiRemoteStationManager::GetStationMldCapabilities(const Mac48Address& from)
1686{
1687 if (auto state = LookupState(from);
1688 state->m_mleCommonInfo && state->m_mleCommonInfo->m_mldCapabilities)
1689 {
1690 return state->m_mleCommonInfo->m_mldCapabilities.value();
1691 }
1692 return std::nullopt;
1693}
1694
1695bool
1696WifiRemoteStationManager::GetLdpcSupported(Mac48Address address) const
1697{
1698 Ptr<const HtCapabilities> htCapabilities = LookupState(address)->m_htCapabilities;
1699 Ptr<const VhtCapabilities> vhtCapabilities = LookupState(address)->m_vhtCapabilities;
1700 Ptr<const HeCapabilities> heCapabilities = LookupState(address)->m_heCapabilities;
1701 bool supported = false;
1702 if (htCapabilities)
1703 {
1704 supported |= htCapabilities->GetLdpc();
1705 }
1706 if (vhtCapabilities)
1707 {
1708 supported |= vhtCapabilities->GetRxLdpc();
1709 }
1710 if (heCapabilities)
1711 {
1712 supported |= heCapabilities->GetLdpcCodingInPayload();
1713 }
1714 return supported;
1715}
1716
1718WifiRemoteStationManager::GetDefaultMode() const
1719{
1720 NS_ASSERT(m_wifiPhy);
1721 auto defaultTxMode = m_wifiPhy->GetDefaultMode();
1722 NS_ASSERT(defaultTxMode.IsMandatory());
1723 return defaultTxMode;
1724}
1725
1727WifiRemoteStationManager::GetDefaultMcs() const
1728{
1729 return HtPhy::GetHtMcs0();
1730}
1731
1733WifiRemoteStationManager::GetDefaultModeForSta(const WifiRemoteStation* st) const
1734{
1735 NS_LOG_FUNCTION(this << st);
1736
1737 if ((!m_wifiPhy->GetDevice()->GetHtConfiguration()) ||
1738 (!GetHtSupported(st) && !GetStationHe6GhzCapabilities(st->m_state->m_address)))
1739 {
1740 return GetDefaultMode();
1741 }
1742
1743 // find the highest modulation class supported by both stations
1745 if (GetHeSupported() && GetHeSupported(st))
1746 {
1747 modClass = WIFI_MOD_CLASS_HE;
1748 }
1749 else if (GetVhtSupported() && GetVhtSupported(st))
1750 {
1751 modClass = WIFI_MOD_CLASS_VHT;
1752 }
1753
1754 // return the MCS with lowest index
1755 return *m_wifiPhy->GetPhyEntity(modClass)->begin();
1756}
1757
1758void
1759WifiRemoteStationManager::Reset()
1760{
1761 NS_LOG_FUNCTION(this);
1762 m_states.clear();
1763 for (auto& state : m_stations)
1764 {
1765 delete (state.second);
1766 }
1767 m_stations.clear();
1768 m_bssBasicRateSet.clear();
1769 m_bssBasicMcsSet.clear();
1770 m_ssrc.fill(0);
1771 m_slrc.fill(0);
1772}
1773
1774void
1775WifiRemoteStationManager::AddBasicMode(WifiMode mode)
1776{
1777 NS_LOG_FUNCTION(this << mode);
1779 {
1780 NS_FATAL_ERROR("It is not allowed to add a HT rate in the BSSBasicRateSet!");
1781 }
1782 for (uint8_t i = 0; i < GetNBasicModes(); i++)
1783 {
1784 if (GetBasicMode(i) == mode)
1785 {
1786 return;
1787 }
1788 }
1789 m_bssBasicRateSet.push_back(mode);
1790}
1791
1792uint8_t
1793WifiRemoteStationManager::GetNBasicModes() const
1794{
1795 return static_cast<uint8_t>(m_bssBasicRateSet.size());
1796}
1797
1799WifiRemoteStationManager::GetBasicMode(uint8_t i) const
1800{
1801 NS_ASSERT(i < GetNBasicModes());
1802 return m_bssBasicRateSet[i];
1803}
1804
1806WifiRemoteStationManager::GetNNonErpBasicModes() const
1807{
1808 uint32_t size = 0;
1809 for (auto i = m_bssBasicRateSet.begin(); i != m_bssBasicRateSet.end(); i++)
1810 {
1811 if (i->GetModulationClass() == WIFI_MOD_CLASS_ERP_OFDM)
1812 {
1813 continue;
1814 }
1815 size++;
1816 }
1817 return size;
1818}
1819
1821WifiRemoteStationManager::GetNonErpBasicMode(uint8_t i) const
1822{
1823 NS_ASSERT(i < GetNNonErpBasicModes());
1824 uint32_t index = 0;
1825 bool found = false;
1826 for (auto j = m_bssBasicRateSet.begin(); j != m_bssBasicRateSet.end();)
1827 {
1828 if (i == index)
1829 {
1830 found = true;
1831 }
1832 if (j->GetModulationClass() != WIFI_MOD_CLASS_ERP_OFDM)
1833 {
1834 if (found)
1835 {
1836 break;
1837 }
1838 }
1839 index++;
1840 j++;
1841 }
1842 return m_bssBasicRateSet[index];
1843}
1844
1845void
1846WifiRemoteStationManager::AddBasicMcs(WifiMode mcs)
1847{
1848 NS_LOG_FUNCTION(this << +mcs.GetMcsValue());
1849 for (uint8_t i = 0; i < GetNBasicMcs(); i++)
1850 {
1851 if (GetBasicMcs(i) == mcs)
1852 {
1853 return;
1854 }
1855 }
1856 m_bssBasicMcsSet.push_back(mcs);
1857}
1858
1859uint8_t
1860WifiRemoteStationManager::GetNBasicMcs() const
1861{
1862 return static_cast<uint8_t>(m_bssBasicMcsSet.size());
1863}
1864
1866WifiRemoteStationManager::GetBasicMcs(uint8_t i) const
1867{
1868 NS_ASSERT(i < GetNBasicMcs());
1869 return m_bssBasicMcsSet[i];
1870}
1871
1873WifiRemoteStationManager::GetNonUnicastMode() const
1874{
1875 if (m_nonUnicastMode == WifiMode())
1876 {
1877 if (GetNBasicModes() > 0)
1878 {
1879 return GetBasicMode(0);
1880 }
1881 else
1882 {
1883 return GetDefaultMode();
1884 }
1885 }
1886 else
1887 {
1888 return m_nonUnicastMode;
1889 }
1890}
1891
1892bool
1893WifiRemoteStationManager::DoNeedRts(WifiRemoteStation* station, uint32_t size, bool normally)
1894{
1895 return normally;
1896}
1897
1898bool
1899WifiRemoteStationManager::DoNeedRetransmission(WifiRemoteStation* station,
1900 Ptr<const Packet> packet,
1901 bool normally)
1902{
1903 return normally;
1904}
1905
1906bool
1907WifiRemoteStationManager::DoNeedFragmentation(WifiRemoteStation* station,
1908 Ptr<const Packet> packet,
1909 bool normally)
1910{
1911 return normally;
1912}
1913
1914void
1915WifiRemoteStationManager::DoReportAmpduTxStatus(WifiRemoteStation* station,
1916 uint16_t nSuccessfulMpdus,
1917 uint16_t nFailedMpdus,
1918 double rxSnr,
1919 double dataSnr,
1920 uint16_t dataChannelWidth,
1921 uint8_t dataNss)
1922{
1923 NS_LOG_DEBUG("DoReportAmpduTxStatus received but the manager does not handle A-MPDUs!");
1924}
1925
1927WifiRemoteStationManager::GetSupported(const WifiRemoteStation* station, uint8_t i) const
1928{
1929 NS_ASSERT(i < GetNSupported(station));
1930 return station->m_state->m_operationalRateSet[i];
1931}
1932
1934WifiRemoteStationManager::GetMcsSupported(const WifiRemoteStation* station, uint8_t i) const
1935{
1936 NS_ASSERT(i < GetNMcsSupported(station));
1937 return station->m_state->m_operationalMcsSet[i];
1938}
1939
1941WifiRemoteStationManager::GetNonErpSupported(const WifiRemoteStation* station, uint8_t i) const
1942{
1943 NS_ASSERT(i < GetNNonErpSupported(station));
1944 // IEEE 802.11g standard defines that if the protection mechanism is enabled, RTS, CTS and
1945 // CTS-To-Self frames should select a rate in the BSSBasicRateSet that corresponds to an 802.11b
1946 // basic rate. This is a implemented here to avoid changes in every RAA, but should maybe be
1947 // moved in case it breaks standard rules.
1948 uint32_t index = 0;
1949 bool found = false;
1950 for (auto j = station->m_state->m_operationalRateSet.begin();
1951 j != station->m_state->m_operationalRateSet.end();)
1952 {
1953 if (i == index)
1954 {
1955 found = true;
1956 }
1957 if (j->GetModulationClass() != WIFI_MOD_CLASS_ERP_OFDM)
1958 {
1959 if (found)
1960 {
1961 break;
1962 }
1963 }
1964 index++;
1965 j++;
1966 }
1967 return station->m_state->m_operationalRateSet[index];
1968}
1969
1971WifiRemoteStationManager::GetAddress(const WifiRemoteStation* station) const
1972{
1973 return station->m_state->m_address;
1974}
1975
1976uint16_t
1977WifiRemoteStationManager::GetChannelWidth(const WifiRemoteStation* station) const
1978{
1979 return station->m_state->m_channelWidth;
1980}
1981
1982bool
1983WifiRemoteStationManager::GetShortGuardIntervalSupported(const WifiRemoteStation* station) const
1984{
1985 Ptr<const HtCapabilities> htCapabilities = station->m_state->m_htCapabilities;
1986
1987 if (!htCapabilities)
1988 {
1989 return false;
1990 }
1991 return htCapabilities->GetShortGuardInterval20();
1992}
1993
1994uint16_t
1995WifiRemoteStationManager::GetGuardInterval(const WifiRemoteStation* station) const
1996{
1997 return station->m_state->m_guardInterval;
1998}
1999
2000bool
2001WifiRemoteStationManager::GetAggregation(const WifiRemoteStation* station) const
2002{
2003 return station->m_state->m_aggregation;
2004}
2005
2006uint8_t
2007WifiRemoteStationManager::GetNumberOfSupportedStreams(const WifiRemoteStation* station) const
2008{
2009 const auto htCapabilities = station->m_state->m_htCapabilities;
2010
2011 if (!htCapabilities)
2012 {
2013 if (const auto heCapabilities = station->m_state->m_heCapabilities)
2014 {
2015 return heCapabilities->GetHighestNssSupported();
2016 }
2017 return 1;
2018 }
2019 return htCapabilities->GetRxHighestSupportedAntennas();
2020}
2021
2022uint8_t
2023WifiRemoteStationManager::GetNess(const WifiRemoteStation* station) const
2024{
2025 return station->m_state->m_ness;
2026}
2027
2029WifiRemoteStationManager::GetPhy() const
2030{
2031 return m_wifiPhy;
2032}
2033
2035WifiRemoteStationManager::GetMac() const
2036{
2037 return m_wifiMac;
2038}
2039
2040uint8_t
2041WifiRemoteStationManager::GetNSupported(const WifiRemoteStation* station) const
2042{
2043 return static_cast<uint8_t>(station->m_state->m_operationalRateSet.size());
2044}
2045
2046bool
2047WifiRemoteStationManager::GetQosSupported(const WifiRemoteStation* station) const
2048{
2049 return station->m_state->m_qosSupported;
2050}
2051
2052bool
2053WifiRemoteStationManager::GetHtSupported(const WifiRemoteStation* station) const
2054{
2055 return bool(station->m_state->m_htCapabilities);
2056}
2057
2058bool
2059WifiRemoteStationManager::GetVhtSupported(const WifiRemoteStation* station) const
2060{
2061 return bool(station->m_state->m_vhtCapabilities);
2062}
2063
2064bool
2065WifiRemoteStationManager::GetHeSupported(const WifiRemoteStation* station) const
2066{
2067 return bool(station->m_state->m_heCapabilities);
2068}
2069
2070bool
2071WifiRemoteStationManager::GetEhtSupported(const WifiRemoteStation* station) const
2072{
2073 return (bool)(station->m_state->m_ehtCapabilities);
2074}
2075
2076bool
2077WifiRemoteStationManager::GetEmlsrSupported(const WifiRemoteStation* station) const
2078{
2079 auto mleCommonInfo = station->m_state->m_mleCommonInfo;
2080 return mleCommonInfo && mleCommonInfo->m_emlCapabilities &&
2081 mleCommonInfo->m_emlCapabilities->emlsrSupport == 1;
2082}
2083
2084bool
2085WifiRemoteStationManager::GetEmlsrEnabled(const WifiRemoteStation* station) const
2086{
2087 return station->m_state->m_emlsrEnabled;
2088}
2089
2090uint8_t
2091WifiRemoteStationManager::GetNMcsSupported(const WifiRemoteStation* station) const
2092{
2093 return static_cast<uint8_t>(station->m_state->m_operationalMcsSet.size());
2094}
2095
2097WifiRemoteStationManager::GetNNonErpSupported(const WifiRemoteStation* station) const
2098{
2099 uint32_t size = 0;
2100 for (auto i = station->m_state->m_operationalRateSet.begin();
2101 i != station->m_state->m_operationalRateSet.end();
2102 i++)
2103 {
2104 if (i->GetModulationClass() == WIFI_MOD_CLASS_ERP_OFDM)
2105 {
2106 continue;
2107 }
2108 size++;
2109 }
2110 return size;
2111}
2112
2113uint16_t
2114WifiRemoteStationManager::GetChannelWidthSupported(Mac48Address address) const
2115{
2116 return LookupState(address)->m_channelWidth;
2117}
2118
2119bool
2120WifiRemoteStationManager::GetShortGuardIntervalSupported(Mac48Address address) const
2121{
2122 Ptr<const HtCapabilities> htCapabilities = LookupState(address)->m_htCapabilities;
2123
2124 if (!htCapabilities)
2125 {
2126 return false;
2127 }
2128 return htCapabilities->GetShortGuardInterval20();
2129}
2130
2131uint8_t
2132WifiRemoteStationManager::GetNumberOfSupportedStreams(Mac48Address address) const
2133{
2134 Ptr<const HtCapabilities> htCapabilities = LookupState(address)->m_htCapabilities;
2135
2136 if (!htCapabilities)
2137 {
2138 return 1;
2139 }
2140 return htCapabilities->GetRxHighestSupportedAntennas();
2141}
2142
2143uint8_t
2144WifiRemoteStationManager::GetNMcsSupported(Mac48Address address) const
2145{
2146 return static_cast<uint8_t>(LookupState(address)->m_operationalMcsSet.size());
2147}
2148
2149bool
2150WifiRemoteStationManager::GetDsssSupported(const Mac48Address& address) const
2151{
2152 return (LookupState(address)->m_dsssSupported);
2153}
2154
2155bool
2156WifiRemoteStationManager::GetErpOfdmSupported(const Mac48Address& address) const
2157{
2158 return (LookupState(address)->m_erpOfdmSupported);
2159}
2160
2161bool
2162WifiRemoteStationManager::GetOfdmSupported(const Mac48Address& address) const
2163{
2164 return (LookupState(address)->m_ofdmSupported);
2165}
2166
2167bool
2168WifiRemoteStationManager::GetHtSupported(Mac48Address address) const
2169{
2170 return bool(LookupState(address)->m_htCapabilities);
2171}
2172
2173bool
2174WifiRemoteStationManager::GetVhtSupported(Mac48Address address) const
2175{
2176 return bool(LookupState(address)->m_vhtCapabilities);
2177}
2178
2179bool
2180WifiRemoteStationManager::GetHeSupported(Mac48Address address) const
2181{
2182 return bool(LookupState(address)->m_heCapabilities);
2183}
2184
2185bool
2186WifiRemoteStationManager::GetEhtSupported(Mac48Address address) const
2187{
2188 return (bool)(LookupState(address)->m_ehtCapabilities);
2189}
2190
2191bool
2192WifiRemoteStationManager::GetEmlsrSupported(const Mac48Address& address) const
2193{
2194 auto mleCommonInfo = LookupState(address)->m_mleCommonInfo;
2195 return mleCommonInfo && mleCommonInfo->m_emlCapabilities &&
2196 mleCommonInfo->m_emlCapabilities->emlsrSupport == 1;
2197}
2198
2199bool
2200WifiRemoteStationManager::GetEmlsrEnabled(const Mac48Address& address) const
2201{
2202 if (auto stateIt = m_states.find(address); stateIt != m_states.cend())
2203 {
2204 return stateIt->second->m_emlsrEnabled;
2205 }
2206 return false;
2207}
2208
2209void
2210WifiRemoteStationManager::SetDefaultTxPowerLevel(uint8_t txPower)
2211{
2212 m_defaultTxPowerLevel = txPower;
2213}
2214
2215uint8_t
2216WifiRemoteStationManager::GetNumberOfAntennas() const
2217{
2218 return m_wifiPhy->GetNumberOfAntennas();
2219}
2220
2221uint8_t
2222WifiRemoteStationManager::GetMaxNumberOfTransmitStreams() const
2223{
2224 return m_wifiPhy->GetMaxSupportedTxSpatialStreams();
2225}
2226
2227bool
2228WifiRemoteStationManager::UseLdpcForDestination(Mac48Address dest) const
2229{
2230 return (GetLdpcSupported() && GetLdpcSupported(dest));
2231}
2232
2233} // namespace ns3
The IEEE 802.11be EHT Capabilities.
uint8_t GetHighestSupportedRxMcs(EhtMcsAndNssSet::EhtMcsMapType mapType)
Get the highest supported RX MCS for a given EHT-MCS map type.
Hold variables of type enum.
Definition: enum.h:62
static WifiMode GetErpOfdmRate(uint64_t rate)
Return a WifiMode for ERP-OFDM corresponding to the provided rate.
static WifiMode GetErpOfdmRate6Mbps()
Return a WifiMode for ERP-OFDM at 6 Mbps.
The HE 6 GHz Band Capabilities (IEEE 802.11ax-2021 9.4.2.263)
The IEEE 802.11ax HE Capabilities.
uint8_t GetHighestMcsSupported() const
Get highest MCS supported.
bool GetHeSuPpdu1xHeLtf800nsGi() const
Get 1xHE-LTF and 800ns GI in HE SU PPDU reception support.
uint8_t GetChannelWidthSet() const
Get channel width set.
The HT Capabilities Information Element.
uint8_t GetSupportedChannelWidth() const
Return the supported channel width.
bool IsSupportedMcs(uint8_t mcs) const
Return the is MCS supported flag.
an EUI-48 address
Definition: mac48-address.h:46
bool IsGroup() const
A base class which provides memory management and object aggregation.
Definition: object.h:89
static WifiMode GetOfdmRate(uint64_t rate, uint16_t bw=20)
Return a WifiMode for OFDM corresponding to the provided rate and the channel bandwidth (20,...
Definition: ofdm-phy.cc:414
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition: nstime.h:351
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold an unsigned integer type.
Definition: uinteger.h:45
The IEEE 802.11ac VHT Capabilities.
bool IsSupportedMcs(uint8_t mcs, uint8_t nss) const
Get the is MCS supported.
uint8_t GetSupportedChannelWidthSet() const
Get the supported channel width set.
Implements the IEEE 802.11 MAC header.
uint8_t GetQosTid() const
Return the Traffic ID of a QoS header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
bool IsMgt() const
Return true if the Type is Management.
bool IsQosData() const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
TypeOfStation GetTypeOfStation() const
Return the type of station.
Definition: wifi-mac.cc:466
represent a single transmission mode
Definition: wifi-mode.h:51
bool IsHigherDataRate(WifiMode mode) const
Definition: wifi-mode.cc:208
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
uint8_t GetMcsValue() const
Definition: wifi-mode.cc:163
Ptr< VhtConfiguration > GetVhtConfiguration() const
Ptr< EhtConfiguration > GetEhtConfiguration() const
Ptr< HtConfiguration > GetHtConfiguration() const
Ptr< HeConfiguration > GetHeConfiguration() const
uint16_t GetChannelWidth() const
Definition: wifi-phy.cc:1083
WifiPhyBand GetPhyBand() const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:1053
Ptr< WifiNetDevice > GetDevice() const
Return the device this PHY is associated with.
Definition: wifi-phy.cc:631
uint16_t GetTxBandwidth(WifiMode mode, uint16_t maxAllowedBandWidth=std::numeric_limits< uint16_t >::max()) const
Get the bandwidth for a transmission occurring on the current operating channel and using the given W...
Definition: wifi-phy.cc:1107
std::list< WifiMode > GetMcsList() const
The WifiPhy::GetMcsList() method is used (e.g., by a WifiRemoteStationManager) to determine the set o...
Definition: wifi-phy.cc:2066
std::list< WifiMode > GetModeList() const
The WifiPhy::GetModeList() method is used (e.g., by a WifiRemoteStationManager) to determine the set ...
Definition: wifi-phy.cc:2017
TID independent remote station statistics.
void NotifyTxSuccess(uint32_t retryCounter)
Updates average frame error rate when data or RTS was transmitted successfully.
void NotifyTxFailed()
Updates average frame error rate when final data or RTS has failed.
hold a list of per-remote-station state.
void ReportDataFailed(Ptr< const WifiMpdu > mpdu)
Should be invoked whenever the AckTimeout associated to a transmission attempt expires.
bool GetQosSupported(Mac48Address address) const
Return whether the given station is QoS capable.
WifiTxVector GetAckTxVector(Mac48Address to, const WifiTxVector &dataTxVector) const
Return a TXVECTOR for the Ack frame given the destination and the mode of the Data used by the sender...
virtual bool DoNeedFragmentation(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
uint32_t m_fragmentationThreshold
Current threshold for fragmentation.
void SetShortSlotTimeEnabled(bool enable)
Enable or disable short slot time.
void SetPsMode(const Mac48Address &address, bool isInPsMode)
Register whether the STA is in Power Save mode or not.
void AddBasicMode(WifiMode mode)
Invoked in a STA upon association to store the set of rates which belong to the BSSBasicRateSet of th...
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
uint32_t GetNFragments(Ptr< const WifiMpdu > mpdu)
Return the number of fragments needed for the given packet.
uint16_t GetAssociationId(Mac48Address remoteAddress) const
Get the AID of a remote station.
ProtectionMode m_htProtectionMode
Protection mode for HT stations when non-HT stations are detected.
void AdjustTxVectorForIcf(WifiTxVector &txVector) const
Adjust the TXVECTOR for an initial Control frame to ensure that the modulation class is non-HT and th...
std::array< uint32_t, AC_BE_NQOS > m_slrc
long retry count per AC
WifiRemoteStation * Lookup(Mac48Address address) const
Return the station associated with the given address.
uint32_t GetFragmentationThreshold() const
Return the fragmentation threshold.
bool NeedRetransmission(Ptr< const WifiMpdu > mpdu)
uint8_t GetNBasicModes() const
Return the number of basic modes we support.
bool UseLdpcForDestination(Mac48Address dest) const
uint32_t m_maxSsrc
Maximum STA short retry count (SSRC)
void SetRtsCtsThreshold(uint32_t threshold)
Sets the RTS threshold.
void AddAllSupportedMcs(Mac48Address address)
Invoked in a STA or AP to store all of the MCS supported by a destination which is also supported loc...
TracedCallback< Mac48Address > m_macTxRtsFailed
The trace source fired when the transmission of a single RTS has failed.
virtual bool DoNeedRts(WifiRemoteStation *station, uint32_t size, bool normally)
void DoSetFragmentationThreshold(uint32_t threshold)
Actually sets the fragmentation threshold, it also checks the validity of the given threshold.
bool IsBrandNew(Mac48Address address) const
Return whether the station state is brand new.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)=0
This method is a pure virtual method that must be implemented by the sub-class.
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)=0
This method is a pure virtual method that must be implemented by the sub-class.
Time m_rtsCtsTxDurationThresh
TX duration threshold for RTS/CTS.
bool GetShortSlotTimeEnabled() const
Return whether the device uses short slot time.
void DoDispose() override
Destructor implementation.
virtual void DoReportDataFailed(WifiRemoteStation *station)=0
This method is a pure virtual method that must be implemented by the sub-class.
bool IsLastFragment(Ptr< const WifiMpdu > mpdu, uint32_t fragmentNumber)
void ReportFinalDataFailed(Ptr< const WifiMpdu > mpdu)
Should be invoked after calling ReportDataFailed if NeedRetransmission returns false.
void SetUseNonErpProtection(bool enable)
Enable or disable protection for non-ERP stations.
bool m_useNonHtProtection
flag if protection for non-HT stations against HT transmissions is enabled
bool GetShortPreambleSupported(Mac48Address address) const
Return whether the station supports short PHY preamble or not.
void AddAllSupportedModes(Mac48Address address)
Invoked in a STA or AP to store all of the modes supported by a destination which is also supported l...
std::optional< Mac48Address > GetAffiliatedStaAddress(const Mac48Address &mldAddress) const
Get the address of the remote station operating on this link and affiliated with the MLD having the g...
void ReportRtsOk(const WifiMacHeader &header, double ctsSnr, WifiMode ctsMode, double rtsSnr)
Should be invoked whenever we receive the CTS associated to an RTS we just sent.
void AddSupportedMcs(Mac48Address address, WifiMode mcs)
Record the MCS index supported by the station.
WifiTxVector GetBlockAckTxVector(Mac48Address to, const WifiTxVector &dataTxVector) const
Return a TXVECTOR for the BlockAck frame given the destination and the mode of the Data used by the s...
void RemoveAllSupportedMcs(Mac48Address address)
Invoked in a STA or AP to delete all of the supported MCS by a destination.
uint32_t DoGetFragmentationThreshold() const
Return the current fragmentation threshold.
WifiModeList m_bssBasicMcsSet
basic MCS set
TracedCallback< Mac48Address > m_macTxFinalRtsFailed
The trace source fired when the transmission of a RTS has exceeded the maximum number of attempts.
WifiMode GetNonUnicastMode() const
Return a mode for non-unicast packets.
bool m_shortPreambleEnabled
flag if short PHY preamble is enabled
bool GetShortSlotTimeSupported(Mac48Address address) const
Return whether the station supports short ERP slot time or not.
void SetShortPreambleEnabled(bool enable)
Enable or disable short PHY preambles.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth)=0
WifiMode GetDefaultMcs() const
Return the default Modulation and Coding Scheme (MCS) index.
Ptr< WifiPhy > m_wifiPhy
This is a pointer to the WifiPhy associated with this WifiRemoteStationManager that is set on call to...
void ReportRxOk(Mac48Address address, RxSignalInfo rxSignalInfo, WifiTxVector txVector)
uint8_t m_defaultTxPowerLevel
Default transmission power level.
static TypeId GetTypeId()
Get the type ID.
WifiMode m_nonUnicastMode
Transmission mode for non-unicast Data frames.
void SetUseNonHtProtection(bool enable)
Enable or disable protection for non-HT stations.
uint16_t GetGuardInterval() const
Return the supported HE guard interval duration (in nanoseconds).
bool IsAssociated(Mac48Address address) const
Return whether the station associated.
bool NeedFragmentation(Ptr< const WifiMpdu > mpdu)
void ReportAmpduTxStatus(Mac48Address address, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus, double rxSnr, double dataSnr, WifiTxVector dataTxVector)
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
uint32_t GetFragmentOffset(Ptr< const WifiMpdu > mpdu, uint32_t fragmentNumber)
WifiRemoteStationInfo GetInfo(Mac48Address address)
uint32_t GetFragmentSize(Ptr< const WifiMpdu > mpdu, uint32_t fragmentNumber)
WifiTxVector GetCtsToSelfTxVector()
Since CTS-to-self parameters are not dependent on the station, it is implemented in wifi remote stati...
uint8_t GetNBasicMcs() const
Return the number of basic MCS index.
bool GetHtSupported() const
Return whether the device has HT capability support enabled on the link this manager is associated wi...
void RecordWaitAssocTxOk(Mac48Address address)
Records that we are waiting for an ACK for the association response we sent.
void SetFragmentationThreshold(uint32_t threshold)
Sets a fragmentation threshold.
Ptr< WifiMac > m_wifiMac
This is a pointer to the WifiMac associated with this WifiRemoteStationManager that is set on call to...
void RecordGotAssocTxOk(Mac48Address address)
Records that we got an ACK for the association response we sent.
bool GetLdpcSupported() const
Return whether the device has LDPC support enabled.
WifiTxVector GetRtsTxVector(Mac48Address address, uint16_t allowedWidth)
bool GetEhtSupported() const
Return whether the device has EHT capability support enabled.
void AddSupportedMode(Mac48Address address, WifiMode mode)
Invoked in a STA or AP to store the set of modes supported by a destination which is also supported l...
std::optional< double > GetMostRecentRssi(Mac48Address address) const
std::shared_ptr< WifiRemoteStationState > LookupState(Mac48Address address) const
Return the state of the station associated with the given address.
std::array< uint32_t, AC_BE_NQOS > m_ssrc
short retry count per AC
void RecordAssocRefused(Mac48Address address)
Records that association request was refused.
bool IsInPsMode(const Mac48Address &address) const
Return whether the STA is currently in Power Save mode.
void ReportFinalRtsFailed(const WifiMacHeader &header)
Should be invoked after calling ReportRtsFailed if NeedRetransmission returns false.
StationStates m_states
States of known stations.
bool NeedCtsToSelf(WifiTxVector txVector)
Return if we need to do CTS-to-self before sending a DATA.
WifiTxVector GetCtsTxVector(Mac48Address to, WifiMode rtsTxMode) const
Return a TXVECTOR for the CTS frame given the destination and the mode of the RTS used by the sender.
void SetMaxSsrc(uint32_t maxSsrc)
Sets the maximum STA short retry count (SSRC).
WifiMode GetBasicMcs(uint8_t i) const
Return the MCS at the given list index.
TracedCallback< Mac48Address > m_macTxDataFailed
The trace source fired when the transmission of a single data packet has failed.
uint16_t GetStaId(Mac48Address address, const WifiTxVector &txVector) const
If the given TXVECTOR is used for a MU transmission, return the STAID of the station with the given a...
WifiMode GetBasicMode(uint8_t i) const
Return a basic mode from the set of basic modes.
void AddSupportedPhyPreamble(Mac48Address address, bool isShortPreambleSupported)
Record whether the short PHY preamble is supported by the station.
bool GetShortGuardIntervalSupported() const
Return whether the device has SGI support enabled.
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
virtual void DoReportRtsFailed(WifiRemoteStation *station)=0
This method is a pure virtual method that must be implemented by the sub-class.
void RecordDisassociated(Mac48Address address)
Records that the STA was disassociated.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)=0
uint16_t GetChannelWidthSupported(Mac48Address address) const
Return the channel width supported by the station.
uint32_t m_maxSlrc
Maximum STA long retry count (SLRC)
void Reset()
Reset the station, invoked in a STA upon dis-association or in an AP upon reboot.
bool GetUseNonErpProtection() const
Return whether the device supports protection of non-ERP stations.
bool IsAssocRefused(Mac48Address address) const
Return whether we refused an association request from the given station.
virtual void DoReportAmpduTxStatus(WifiRemoteStation *station, uint16_t nSuccessfulMpdus, uint16_t nFailedMpdus, double rxSnr, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
Typically called per A-MPDU, either when a Block ACK was successfully received or when a BlockAckTime...
bool GetVhtSupported() const
Return whether the device has VHT capability support enabled on the link this manager is associated w...
ProtectionMode m_erpProtectionMode
Protection mode for ERP stations when non-ERP stations are detected.
WifiModeList m_bssBasicRateSet
This member is the list of WifiMode objects that comprise the BSSBasicRateSet parameter.
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)=0
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector GetDataTxVector(const WifiMacHeader &header, uint16_t allowedWidth)
void ReportDataOk(Ptr< const WifiMpdu > mpdu, double ackSnr, WifiMode ackMode, double dataSnr, WifiTxVector dataTxVector)
Should be invoked whenever we receive the ACK associated to a data packet we just sent.
void ReportRtsFailed(const WifiMacHeader &header)
Should be invoked whenever the RtsTimeout associated to a transmission attempt expires.
void AddSupportedErpSlotTime(Mac48Address address, bool isShortSlotTimeSupported)
Record whether the short ERP slot time is supported by the station.
bool GetShortPreambleEnabled() const
Return whether the device uses short PHY preambles.
bool GetHeSupported() const
Return whether the device has HE capability support enabled.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)=0
This method is a pure virtual method that must be implemented by the sub-class.
virtual bool DoNeedRetransmission(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
WifiMode GetDefaultMode() const
Return the default transmission mode.
void RecordGotAssocTxFailed(Mac48Address address)
Records that we missed an ACK for the association response we sent.
std::optional< Mac48Address > GetMldAddress(const Mac48Address &address) const
Get the address of the MLD the given station is affiliated with, if any.
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)=0
This method is a pure virtual method that must be implemented by the sub-class.
virtual void SetupMac(const Ptr< WifiMac > mac)
Set up MAC associated with this device since it is the object that knows the full set of timing param...
bool NeedRts(const WifiMacHeader &header, const WifiTxParameters &txParams)
uint32_t m_rtsCtsThreshold
Threshold for RTS/CTS.
bool m_useNonErpProtection
flag if protection for non-ERP stations against ERP transmissions is enabled
WifiMode GetControlAnswerMode(WifiMode reqMode) const
Get control answer mode function.
bool m_shortSlotTimeEnabled
flag if short slot time is enabled
bool IsWaitAssocTxOk(Mac48Address address) const
Return whether we are waiting for an ACK for the association response we sent.
void SetMaxSlrc(uint32_t maxSlrc)
Sets the maximum STA long retry count (SLRC).
TracedCallback< Mac48Address > m_macTxFinalDataFailed
The trace source fired when the transmission of a data packet has exceeded the maximum number of atte...
bool GetUseNonHtProtection() const
Return whether the device supports protection of non-HT stations.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
std::optional< Time > m_txDuration
TX duration of the frame.
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver.
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetNess(uint8_t ness)
Sets the Ness number.
void SetTxPowerLevel(uint8_t powerlevel)
Sets the selected transmission power level.
void SetLdpc(bool ldpc)
Sets if LDPC FEC coding is being used.
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
void SetGuardInterval(uint16_t guardInterval)
Sets the guard interval duration (in nanoseconds)
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.
WifiModulationClass GetModulationClass() const
Get the modulation class specified by this TXVECTOR.
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
void SetBssColor(uint8_t color)
Set the BSS color.
void SetNTx(uint8_t nTx)
Sets the number of TX antennas.
uint16_t GetChannelWidth() const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetNss(uint8_t nss)
Sets the number of Nss.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#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 ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#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:1319
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
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:73
@ STA
Definition: wifi-mac.h:68
@ AP
Definition: wifi-mac.h:69
@ WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_EHT_MU
@ WIFI_PREAMBLE_HE_SU
@ WIFI_PREAMBLE_VHT_SU
@ WIFI_PREAMBLE_HT_MF
@ WIFI_PHY_BAND_6GHZ
The 6 GHz band.
Definition: wifi-phy-band.h:39
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
Definition: wifi-phy-band.h:35
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Definition: wifi-phy-band.h:37
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
@ WIFI_MOD_CLASS_HR_DSSS
HR/DSSS (Clause 16)
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
@ WIFI_MOD_CLASS_DSSS
DSSS (Clause 15)
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeWifiModeAccessor(T1 a1)
Definition: wifi-mode.h:254
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1407
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octets of the IEEE 802.11 MAC FCS field.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
bool IsAllowedControlAnswerModulationClass(WifiModulationClass modClassReq, WifiModulationClass modClassAnswer)
Return whether the modulation class of the selected mode for the control answer frame is allowed.
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:189
uint16_t ConvertGuardIntervalToNanoSeconds(WifiMode mode, const Ptr< WifiNetDevice > device)
Convert the guard interval to nanoseconds based on the WifiMode.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeChecker > MakeWifiModeChecker()
Definition: wifi-mode.cc:263
std::vector< WifiMode > WifiModeList
In various parts of the code, folk are interested in maintaining a list of transmission modes.
Definition: wifi-mode.h:262
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition: wifi-mode.h:35
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1427
EhtMcsMapType
The different EHT-MCS map types as defined in 9.4.2.313.4 Supported EHT-MCS And NSS Set field.
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:69
double rssi
RSSI in dBm.
Definition: phy-entity.h:71
double snr
SNR in linear scale.
Definition: phy-entity.h:70
hold per-remote-station state.
WifiRemoteStationState * m_state
Remote station state.
std::pair< double, Time > m_rssiAndUpdateTimePair
RSSI (in dBm) of the most recent packet received from the remote station along with update time.
std::shared_ptr< CommonInfoBasicMle > m_mleCommonInfo
remote station Multi-Link Element Common Info
Mac48Address m_address
Mac48Address of the remote station.
uint16_t m_channelWidth
Channel width (in MHz) supported by the remote station.
uint8_t m_ness
Number of extended spatial streams of the remote station.
bool m_aggregation
Flag if MPDU aggregation is used by the remote station.
bool m_qosSupported
Flag if QoS is supported by the station.
WifiModeList m_operationalRateSet
This member is the list of WifiMode objects that comprise the OperationalRateSet parameter for this r...
WifiModeList m_operationalMcsSet
operational MCS set
uint16_t m_guardInterval
HE Guard interval duration (in nanoseconds) supported by the remote station.
Ptr< const EhtCapabilities > m_ehtCapabilities
remote station EHT capabilities
Ptr< const VhtCapabilities > m_vhtCapabilities
remote station VHT capabilities
WifiRemoteStationInfo m_info
remote station info
bool m_emlsrEnabled
whether EMLSR mode is enabled on this link
Ptr< const HtCapabilities > m_htCapabilities
remote station HT capabilities
Ptr< const HeCapabilities > m_heCapabilities
remote station HE capabilities