diff --git a/src/wifi/model/ap-wifi-mac.cc b/src/wifi/model/ap-wifi-mac.cc index d9c1c80d1..eef050863 100644 --- a/src/wifi/model/ap-wifi-mac.cc +++ b/src/wifi/model/ap-wifi-mac.cc @@ -662,7 +662,7 @@ ApWifiMac::GetMultiLinkElement(uint8_t linkId, WifiMacType frameType, const Mac4 NS_LOG_FUNCTION(this << +linkId << frameType << to); NS_ABORT_IF(GetNLinks() == 1); - MultiLinkElement mle(MultiLinkElement::BASIC_VARIANT, frameType); + MultiLinkElement mle(MultiLinkElement::BASIC_VARIANT); mle.SetMldMacAddress(GetAddress()); mle.SetLinkIdInfo(linkId); mle.SetBssParamsChangeCount(0); diff --git a/src/wifi/model/eht/multi-link-element.cc b/src/wifi/model/eht/multi-link-element.cc index 595b2cdd0..39d79b697 100644 --- a/src/wifi/model/eht/multi-link-element.cc +++ b/src/wifi/model/eht/multi-link-element.cc @@ -222,15 +222,14 @@ CommonInfoBasicMle::DecodeEmlsrTransitionDelay(uint8_t value) /** * MultiLinkElement */ -MultiLinkElement::MultiLinkElement(WifiMacType frameType, ContainingFrame frame) +MultiLinkElement::MultiLinkElement(ContainingFrame frame) : m_containingFrame(frame), - m_frameType(frameType), m_commonInfo(std::in_place_type) // initialize as UNSET { } -MultiLinkElement::MultiLinkElement(Variant variant, WifiMacType frameType, ContainingFrame frame) - : MultiLinkElement(frameType, frame) +MultiLinkElement::MultiLinkElement(Variant variant, ContainingFrame frame) + : MultiLinkElement(frame) { NS_ASSERT(variant != UNSET); SetVariant(variant); @@ -495,10 +494,8 @@ MultiLinkElement::GetTransitionTimeout() const return MicroSeconds(1 << (6 + emlCapabilities->transitionTimeout)); } -MultiLinkElement::PerStaProfileSubelement::PerStaProfileSubelement(Variant variant, - WifiMacType frameType) +MultiLinkElement::PerStaProfileSubelement::PerStaProfileSubelement(Variant variant) : m_variant(variant), - m_frameType(frameType), m_staControl(0) { } @@ -506,7 +503,6 @@ MultiLinkElement::PerStaProfileSubelement::PerStaProfileSubelement(Variant varia MultiLinkElement::PerStaProfileSubelement::PerStaProfileSubelement( const PerStaProfileSubelement& perStaProfile) : m_variant(perStaProfile.m_variant), - m_frameType(perStaProfile.m_frameType), m_staControl(perStaProfile.m_staControl), m_staMacAddress(perStaProfile.m_staMacAddress) { @@ -536,7 +532,6 @@ MultiLinkElement::PerStaProfileSubelement::operator=(const PerStaProfileSubeleme } m_variant = perStaProfile.m_variant; - m_frameType = perStaProfile.m_frameType; m_staControl = perStaProfile.m_staControl; m_staMacAddress = perStaProfile.m_staMacAddress; @@ -608,52 +603,35 @@ void MultiLinkElement::PerStaProfileSubelement::SetAssocRequest( const std::variant& assoc) { - switch (m_frameType) - { - case WIFI_MAC_MGT_ASSOCIATION_REQUEST: - m_staProfile = - std::make_unique(std::get(assoc)); - break; - case WIFI_MAC_MGT_REASSOCIATION_REQUEST: - m_staProfile = - std::make_unique(std::get(assoc)); - break; - default: - NS_ABORT_MSG("Invalid frame type: " << m_frameType); - } + std::visit( + [&](auto&& frame) { + m_staProfile = std::make_unique>(frame); + }, + assoc); } void MultiLinkElement::PerStaProfileSubelement::SetAssocRequest( std::variant&& assoc) { - switch (m_frameType) - { - case WIFI_MAC_MGT_ASSOCIATION_REQUEST: - m_staProfile = std::make_unique( - std::move(std::get(assoc))); - break; - case WIFI_MAC_MGT_REASSOCIATION_REQUEST: - m_staProfile = std::make_unique( - std::move(std::get(assoc))); - break; - default: - NS_ABORT_MSG("Invalid frame type: " << m_frameType); - } + std::visit( + [&](auto&& frame) { + using T = std::decay_t; + m_staProfile = std::make_unique(std::forward(frame)); + }, + assoc); } bool MultiLinkElement::PerStaProfileSubelement::HasAssocRequest() const { - return m_frameType == WIFI_MAC_MGT_ASSOCIATION_REQUEST && - std::holds_alternative>(m_staProfile); + return std::holds_alternative>(m_staProfile); } bool MultiLinkElement::PerStaProfileSubelement::HasReassocRequest() const { - return m_frameType == WIFI_MAC_MGT_REASSOCIATION_REQUEST && - std::holds_alternative>(m_staProfile); + return std::holds_alternative>(m_staProfile); } AssocReqRefVariant @@ -670,25 +648,19 @@ MultiLinkElement::PerStaProfileSubelement::GetAssocRequest() const void MultiLinkElement::PerStaProfileSubelement::SetAssocResponse(const MgtAssocResponseHeader& assoc) { - NS_ABORT_IF(m_frameType != WIFI_MAC_MGT_ASSOCIATION_RESPONSE && - m_frameType != WIFI_MAC_MGT_REASSOCIATION_RESPONSE); m_staProfile = std::make_unique(assoc); } void MultiLinkElement::PerStaProfileSubelement::SetAssocResponse(MgtAssocResponseHeader&& assoc) { - NS_ABORT_IF(m_frameType != WIFI_MAC_MGT_ASSOCIATION_RESPONSE && - m_frameType != WIFI_MAC_MGT_REASSOCIATION_RESPONSE); m_staProfile = std::make_unique(std::move(assoc)); } bool MultiLinkElement::PerStaProfileSubelement::HasAssocResponse() const { - return (m_frameType == WIFI_MAC_MGT_ASSOCIATION_RESPONSE || - m_frameType == WIFI_MAC_MGT_REASSOCIATION_RESPONSE) && - std::holds_alternative>(m_staProfile); + return std::holds_alternative>(m_staProfile); } MgtAssocResponseHeader& @@ -824,8 +796,7 @@ MultiLinkElement::AddPerStaProfileSubelement() { auto variant = GetVariant(); NS_ABORT_IF(variant == UNSET); - NS_ABORT_IF(m_frameType == WIFI_MAC_DATA); - m_perStaProfileSubelements.emplace_back(variant, m_frameType); + m_perStaProfileSubelements.emplace_back(variant); } std::size_t diff --git a/src/wifi/model/eht/multi-link-element.h b/src/wifi/model/eht/multi-link-element.h index 1465e064b..d81e67419 100644 --- a/src/wifi/model/eht/multi-link-element.h +++ b/src/wifi/model/eht/multi-link-element.h @@ -193,18 +193,16 @@ class MultiLinkElement : public WifiInformationElement /** * Construct a Multi-Link Element with no variant set. * - * \param frameType the type of the frame containing the Multi-Link Element * \param frame the management frame containing this Multi-Link Element */ - MultiLinkElement(WifiMacType frameType, ContainingFrame frame = {}); + MultiLinkElement(ContainingFrame frame = {}); /** * Constructor * * \param variant the Multi-Link element variant (cannot be UNSET) - * \param frameType the type of the frame containing the Multi-Link Element * \param frame the management frame containing this Multi-Link Element */ - MultiLinkElement(Variant variant, WifiMacType frameType, ContainingFrame frame = {}); + MultiLinkElement(Variant variant, ContainingFrame frame = {}); WifiInformationElementId ElementId() const override; WifiInformationElementId ElementIdExt() const override; @@ -429,9 +427,8 @@ class MultiLinkElement : public WifiInformationElement * Constructor * * \param variant the Multi-Link element variant - * \param frameType the type of the frame containing the Multi-Link Element */ - PerStaProfileSubelement(Variant variant, WifiMacType frameType); + PerStaProfileSubelement(Variant variant); /** * Copy constructor performing a deep copy of the object @@ -570,7 +567,6 @@ class MultiLinkElement : public WifiInformationElement uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override; Variant m_variant; //!< Multi-Link element variant - WifiMacType m_frameType; //!< type of the frame containing the Multi-Link Element uint16_t m_staControl; //!< STA Control field Mac48Address m_staMacAddress; //!< STA MAC address std::variant::DeserializeImpl(i); } -void -MgtProbeResponseHeader::InitForDeserialization(std::optional& optElem) -{ - optElem.emplace(WIFI_MAC_MGT_PROBE_RESPONSE); -} - /*********************************************************** * Beacons ***********************************************************/ @@ -155,12 +149,6 @@ MgtBeaconHeader::GetTypeId() return tid; } -void -MgtBeaconHeader::InitForDeserialization(std::optional& optElem) -{ - optElem.emplace(WIFI_MAC_MGT_BEACON); -} - /*********************************************************** * Assoc Request ***********************************************************/ @@ -293,13 +281,6 @@ MgtAssocRequestHeader::DeserializeFromPerStaProfileImpl(Buffer::Iterator start, DeserializeFromPerStaProfileImpl(i, length - distance, frame); } -void -MgtAssocRequestHeader::InitForDeserialization(std::optional& optElem) -{ - optElem.emplace(WIFI_MAC_MGT_ASSOCIATION_REQUEST); - optElem->m_containingFrame = *this; -} - /*********************************************************** * Ressoc Request ***********************************************************/ @@ -449,13 +430,6 @@ MgtReassocRequestHeader::DeserializeFromPerStaProfileImpl(Buffer::Iterator start DeserializeFromPerStaProfileImpl(i, length - distance, frame); } -void -MgtReassocRequestHeader::InitForDeserialization(std::optional& optElem) -{ - optElem.emplace(WIFI_MAC_MGT_REASSOCIATION_REQUEST); - optElem->m_containingFrame = *this; -} - /*********************************************************** * Assoc/Reassoc Response ***********************************************************/ @@ -611,13 +585,6 @@ MgtAssocResponseHeader::DeserializeFromPerStaProfileImpl(Buffer::Iterator start, DeserializeFromPerStaProfileImpl(i, length - distance, frame); } -void -MgtAssocResponseHeader::InitForDeserialization(std::optional& optElem) -{ - optElem.emplace(WIFI_MAC_MGT_ASSOCIATION_RESPONSE); - optElem->m_containingFrame = *this; -} - /********************************************************** * ActionFrame **********************************************************/ diff --git a/src/wifi/model/mgt-headers.h b/src/wifi/model/mgt-headers.h index 6de77aa01..41888a324 100644 --- a/src/wifi/model/mgt-headers.h +++ b/src/wifi/model/mgt-headers.h @@ -228,14 +228,6 @@ class MgtAssocRequestHeader const MgtAssocRequestHeader& frame); private: - using WifiMgtHeader::InitForDeserialization; - - /** - * \param optElem the MultiLinkElement object to initialize for deserializing the - * information element into - */ - void InitForDeserialization(std::optional& optElem); - CapabilityInformation m_capability; //!< Capability information uint16_t m_listenInterval{0}; //!< listen interval }; @@ -328,14 +320,6 @@ class MgtReassocRequestHeader const MgtReassocRequestHeader& frame); private: - using WifiMgtHeader::InitForDeserialization; - - /** - * \param optElem the MultiLinkElement object to initialize for deserializing the - * information element into - */ - void InitForDeserialization(std::optional& optElem); - Mac48Address m_currentApAddr; //!< Address of the current access point CapabilityInformation m_capability; //!< Capability information uint16_t m_listenInterval{0}; //!< listen interval @@ -435,14 +419,6 @@ class MgtAssocResponseHeader const MgtAssocResponseHeader& frame); private: - using WifiMgtHeader::InitForDeserialization; - - /** - * \param optElem the MultiLinkElement object to initialize for deserializing the - * information element into - */ - void InitForDeserialization(std::optional& optElem); - CapabilityInformation m_capability; //!< Capability information StatusCode m_code; //!< Status code uint16_t m_aid{0}; //!< AID @@ -523,14 +499,6 @@ class MgtProbeResponseHeader : public WifiMgtHeader::InitForDeserialization; - - /** - * \param optElem the MultiLinkElement object to initialize for deserializing the - * information element into - */ - void InitForDeserialization(std::optional& optElem); - uint64_t m_timestamp; //!< Timestamp uint64_t m_beaconInterval; //!< Beacon interval CapabilityInformation m_capability; //!< Capability information @@ -550,15 +518,6 @@ class MgtBeaconHeader : public MgtProbeResponseHeader * \return The TypeId. */ static TypeId GetTypeId(); - - private: - // using WifiMgtHeader::InitForDeserialization; - - /** - * \param optElem the MultiLinkElement object to initialize for deserializing the - * information element into - */ - void InitForDeserialization(std::optional& optElem); }; /**************************** diff --git a/src/wifi/model/sta-wifi-mac.cc b/src/wifi/model/sta-wifi-mac.cc index f92d63632..3741907eb 100644 --- a/src/wifi/model/sta-wifi-mac.cc +++ b/src/wifi/model/sta-wifi-mac.cc @@ -347,9 +347,7 @@ StaWifiMac::GetMultiLinkElement(bool isReassoc, uint8_t linkId) const { NS_LOG_FUNCTION(this << isReassoc << +linkId); - MultiLinkElement multiLinkElement(MultiLinkElement::BASIC_VARIANT, - isReassoc ? WIFI_MAC_MGT_REASSOCIATION_REQUEST - : WIFI_MAC_MGT_ASSOCIATION_REQUEST); + MultiLinkElement multiLinkElement(MultiLinkElement::BASIC_VARIANT); // The Common info field of the Basic Multi-Link element carried in the (Re)Association // Request frame shall include the MLD MAC address, the MLD Capabilities and Operations, // and the EML Capabilities subfields, and shall not include the Link ID Info, the BSS diff --git a/src/wifi/model/wifi-mgt-header.h b/src/wifi/model/wifi-mgt-header.h index 36a0d2e8a..4923acf1c 100644 --- a/src/wifi/model/wifi-mgt-header.h +++ b/src/wifi/model/wifi-mgt-header.h @@ -277,6 +277,8 @@ class MgtHeaderInPerStaProfile> void CopyIesFromContainingFrame(const Derived& frame); protected: + using WifiMgtHeader>::InitForDeserialization; + /** * \param frame the frame containing the Multi-Link Element * \return the number of bytes that are needed to serialize this header into a Per-STA Profile @@ -309,6 +311,12 @@ class MgtHeaderInPerStaProfile> */ void SetMleContainingFrame() const; + /** + * \param optElem the MultiLinkElement object to initialize for deserializing the + * information element into + */ + void InitForDeserialization(std::optional& optElem); + private: using WifiMgtHeader>::DoDeserialize; using WifiMgtHeader>::m_elements; @@ -382,6 +390,14 @@ WifiMgtHeader>::InitForDeserialization( } } +template +void +MgtHeaderInPerStaProfile>::InitForDeserialization( + std::optional& optElem) +{ + optElem.emplace(*static_cast(this)); +} + namespace internal { diff --git a/src/wifi/test/wifi-eht-info-elems-test.cc b/src/wifi/test/wifi-eht-info-elems-test.cc index c0f2497a5..a095d577b 100644 --- a/src/wifi/test/wifi-eht-info-elems-test.cc +++ b/src/wifi/test/wifi-eht-info-elems-test.cc @@ -63,14 +63,12 @@ class BasicMultiLinkElementTest : public HeaderSerializationTestCase private: void DoRun() override; - WifiMacType m_frameType; //!< the type of frame possibly included in the MLE MgtAssocRequestHeader m_outerAssoc; //!< the frame containing the MLE }; BasicMultiLinkElementTest::BasicMultiLinkElementTest() : HeaderSerializationTestCase( - "Check serialization and deserialization of Basic variant Multi-Link elements"), - m_frameType(WIFI_MAC_MGT_ASSOCIATION_REQUEST) + "Check serialization and deserialization of Basic variant Multi-Link elements") { } @@ -83,7 +81,7 @@ BasicMultiLinkElementTest::GetMultiLinkElement( const CommonInfoBasicMle& commonInfo, std::vector subelements) { - MultiLinkElement mle(MultiLinkElement::BASIC_VARIANT, m_frameType); + MultiLinkElement mle(MultiLinkElement::BASIC_VARIANT); mle.SetMldMacAddress(commonInfo.m_mldMacAddress); if (commonInfo.m_linkIdInfo.has_value()) { @@ -128,17 +126,17 @@ BasicMultiLinkElementTest::DoRun() }; // Common Info with MLD MAC address - TestHeaderSerialization(GetMultiLinkElement(commonInfo, {}), m_frameType); + TestHeaderSerialization(GetMultiLinkElement(commonInfo, {})); commonInfo.m_linkIdInfo = 3; // Adding Link ID Info - TestHeaderSerialization(GetMultiLinkElement(commonInfo, {}), m_frameType); + TestHeaderSerialization(GetMultiLinkElement(commonInfo, {})); commonInfo.m_bssParamsChangeCount = 1; // Adding BSS Parameters Change Count - TestHeaderSerialization(GetMultiLinkElement(commonInfo, {}), m_frameType); + TestHeaderSerialization(GetMultiLinkElement(commonInfo, {})); commonInfo.m_mediumSyncDelayInfo = CommonInfoBasicMle::MediumSyncDelayInfo{.mediumSyncDuration = 1, @@ -146,7 +144,7 @@ BasicMultiLinkElementTest::DoRun() .mediumSyncMaxNTxops = 5}; // Adding Medium Sync Delay Information - TestHeaderSerialization(GetMultiLinkElement(commonInfo, {}), m_frameType); + TestHeaderSerialization(GetMultiLinkElement(commonInfo, {})); commonInfo.m_emlCapabilities = CommonInfoBasicMle::EmlCapabilities{.emlsrSupport = 1, .emlsrPaddingDelay = 4, @@ -154,7 +152,7 @@ BasicMultiLinkElementTest::DoRun() .transitionTimeout = 10}; // Adding Medium Sync Delay Information - TestHeaderSerialization(GetMultiLinkElement(commonInfo, {}), m_frameType); + TestHeaderSerialization(GetMultiLinkElement(commonInfo, {})); /** * To test the serialization/deserialization of Per-STA Profile subelements, we include @@ -204,8 +202,7 @@ BasicMultiLinkElementTest::DoRun() // to the containing frame, so that all the IEs are inherited and the Per-STA Profile // does not contain any Information Element. - MultiLinkElement::PerStaProfileSubelement perStaProfile1(MultiLinkElement::BASIC_VARIANT, - m_frameType); + MultiLinkElement::PerStaProfileSubelement perStaProfile1(MultiLinkElement::BASIC_VARIANT); perStaProfile1.SetLinkId(3); perStaProfile1.SetCompleteProfile(); perStaProfile1.SetAssocRequest(m_outerAssoc); @@ -233,8 +230,7 @@ BasicMultiLinkElementTest::DoRun() // EhtCapabilities IE is present in the containing frame but not in the Per-STA Profile // subelement, hence it is listed in a Non-Inheritance element - MultiLinkElement::PerStaProfileSubelement perStaProfile2(MultiLinkElement::BASIC_VARIANT, - m_frameType); + MultiLinkElement::PerStaProfileSubelement perStaProfile2(MultiLinkElement::BASIC_VARIANT); perStaProfile2.SetLinkId(0); perStaProfile2.SetCompleteProfile(); perStaProfile2.SetStaMacAddress(Mac48Address("ba:98:76:54:32:10"));