From c4732010ad83e3c296424f8bd287168769ffddeb Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Fri, 19 May 2023 10:56:14 +0200 Subject: [PATCH] wifi: Move enum for TID-to-Link Mapping IE direction values to wifi-utils Also, use a more generic name given that it can be used in other contexts --- .../model/eht/tid-to-link-mapping-element.cc | 2 +- .../model/eht/tid-to-link-mapping-element.h | 16 ++------- src/wifi/model/wifi-utils.h | 36 +++++++++++++++++++ src/wifi/test/wifi-eht-info-elems-test.cc | 14 ++++---- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/wifi/model/eht/tid-to-link-mapping-element.cc b/src/wifi/model/eht/tid-to-link-mapping-element.cc index 63b291ad7..f1d1e885d 100644 --- a/src/wifi/model/eht/tid-to-link-mapping-element.cc +++ b/src/wifi/model/eht/tid-to-link-mapping-element.cc @@ -66,7 +66,7 @@ TidToLinkMapping::Control::Deserialize(Buffer::Iterator start) auto val = i.ReadU8(); count++; - direction = static_cast(val & 0x03); + direction = static_cast(val & 0x03); defaultMapping = (((val >> 2) & 0x01) == 1); mappingSwitchTimePresent = (((val >> 3) & 0x01) == 1); expectedDurationPresent = (((val >> 4) & 0x01) == 1); diff --git a/src/wifi/model/eht/tid-to-link-mapping-element.h b/src/wifi/model/eht/tid-to-link-mapping-element.h index d9a48e192..7bf6f3641 100644 --- a/src/wifi/model/eht/tid-to-link-mapping-element.h +++ b/src/wifi/model/eht/tid-to-link-mapping-element.h @@ -22,6 +22,7 @@ #include "ns3/nstime.h" #include "ns3/wifi-information-element.h" +#include "ns3/wifi-utils.h" #include #include @@ -30,21 +31,10 @@ namespace ns3 { -/** - * TID-to-Link Mapping Control Direction - * IEEE 802.11be D2.0 Figure 9-1002an - */ -enum class TidLinkMapDir : uint8_t -{ - DOWNLINK = 0, - UPLINK = 1, - BOTH_DIRECTIONS = 2, -}; - /// whether to enforce the default link mapping constexpr auto DEFAULT_WIFI_TID_LINK_MAPPING{true}; /// default value for the Direction subfield of the TID-To-Link Control field -constexpr auto DEFAULT_WIFI_TID_LINK_MAP_DIR{TidLinkMapDir::BOTH_DIRECTIONS}; +constexpr auto DEFAULT_WIFI_TID_LINK_MAP_DIR{WifiDirection::BOTH_DIRECTIONS}; /// size in bytes of the TID-To-Link Control field with default link mapping constexpr uint16_t WIFI_TID_TO_LINK_MAPPING_CONTROL_BASIC_SIZE_B = 1; // IEEE 802.11be D2.0 9.4.2.314 @@ -71,7 +61,7 @@ class TidToLinkMapping : public WifiInformationElement { friend class TidToLinkMapping; - TidLinkMapDir direction{DEFAULT_WIFI_TID_LINK_MAP_DIR}; ///< Direction + WifiDirection direction{DEFAULT_WIFI_TID_LINK_MAP_DIR}; ///< Direction bool defaultMapping{DEFAULT_WIFI_TID_LINK_MAPPING}; ///< Default link mapping /// \return Serialized size of TID-to-Link Mapping Control in octets diff --git a/src/wifi/model/wifi-utils.h b/src/wifi/model/wifi-utils.h index 5b6058163..9aad32cf7 100644 --- a/src/wifi/model/wifi-utils.h +++ b/src/wifi/model/wifi-utils.h @@ -22,6 +22,7 @@ #include "block-ack-type.h" +#include "ns3/fatal-error.h" #include "ns3/ptr.h" #include @@ -34,6 +35,41 @@ namespace ns3 class WifiMacHeader; class Packet; +/** + * Wifi direction. Values are those defined for the TID-to-Link Mapping Control Direction + * field in IEEE 802.11be D3.1 Figure 9-1002ap + */ +enum class WifiDirection : uint8_t +{ + DOWNLINK = 0, + UPLINK = 1, + BOTH_DIRECTIONS = 2, +}; + +/** + * \brief Stream insertion operator. + * + * \param os the stream + * \param direction the direction + * \returns a reference to the stream + */ +inline std::ostream& +operator<<(std::ostream& os, const WifiDirection& direction) +{ + switch (direction) + { + case WifiDirection::DOWNLINK: + return (os << "DOWNLINK"); + case WifiDirection::UPLINK: + return (os << "UPLINK"); + case WifiDirection::BOTH_DIRECTIONS: + return (os << "BOTH_DIRECTIONS"); + default: + NS_FATAL_ERROR("Invalid direction"); + return (os << "INVALID"); + } +} + /// @brief TID-indexed map of the link set to which the TID is mapped using WifiTidLinkMapping = std::map>; diff --git a/src/wifi/test/wifi-eht-info-elems-test.cc b/src/wifi/test/wifi-eht-info-elems-test.cc index 90b0ff0f0..5c8f60c98 100644 --- a/src/wifi/test/wifi-eht-info-elems-test.cc +++ b/src/wifi/test/wifi-eht-info-elems-test.cc @@ -1212,7 +1212,7 @@ class TidToLinkMappingElementTest : public HeaderSerializationTestCase * \param expectedDuration the Expected Duration * \param mappings A TID-indexed map of the link sets the TIDs are mapped to */ - TidToLinkMappingElementTest(TidLinkMapDir direction, + TidToLinkMappingElementTest(WifiDirection direction, std::optional