From 0f58f70d62445dbbd5c911ff976405ea419917d2 Mon Sep 17 00:00:00 2001 From: sanjaybhat2004 Date: Sat, 31 Aug 2024 19:22:08 +0530 Subject: [PATCH] wifi: (fixes #1055) Overload WifiHelper::SetStandard to take a string as an argument --- src/wifi/helper/wifi-helper.cc | 47 ++++++++++++++++++++++++++++++++++ src/wifi/helper/wifi-helper.h | 11 ++++++++ 2 files changed, 58 insertions(+) diff --git a/src/wifi/helper/wifi-helper.cc b/src/wifi/helper/wifi-helper.cc index 7b5a512a2..32f18f2fb 100644 --- a/src/wifi/helper/wifi-helper.cc +++ b/src/wifi/helper/wifi-helper.cc @@ -723,12 +723,59 @@ WifiHelper::WifiHelper() m_ehtConfig.SetTypeId("ns3::EhtConfiguration"); } +namespace +{ +/// Map strings to WifiStandard enum values +const std::unordered_map WIFI_STANDARDS_NAME_MAP{ + // clang-format off + {"802.11a", WIFI_STANDARD_80211a}, + {"11a", WIFI_STANDARD_80211a}, + + {"802.11b", WIFI_STANDARD_80211b}, + {"11b", WIFI_STANDARD_80211b}, + + {"802.11g", WIFI_STANDARD_80211g}, + {"11g", WIFI_STANDARD_80211g}, + + {"802.11p", WIFI_STANDARD_80211p}, + {"11p", WIFI_STANDARD_80211p}, + + {"802.11n", WIFI_STANDARD_80211n}, + {"11n", WIFI_STANDARD_80211n}, + {"HT", WIFI_STANDARD_80211n}, + + {"802.11ac", WIFI_STANDARD_80211ac}, + {"11ac", WIFI_STANDARD_80211ac}, + {"VHT", WIFI_STANDARD_80211ac}, + + {"802.11ad", WIFI_STANDARD_80211ad}, + {"11ad", WIFI_STANDARD_80211ad}, + + {"802.11ax", WIFI_STANDARD_80211ax}, + {"11ax", WIFI_STANDARD_80211ax}, + {"HE", WIFI_STANDARD_80211ax}, + + {"802.11be", WIFI_STANDARD_80211be}, + {"11be", WIFI_STANDARD_80211be}, + {"EHT", WIFI_STANDARD_80211be}, + // clang-format on +}; +} // namespace + void WifiHelper::SetStandard(WifiStandard standard) { m_standard = standard; } +void +WifiHelper::SetStandard(const std::string& standard) +{ + NS_ABORT_MSG_IF(!WIFI_STANDARDS_NAME_MAP.contains(standard), + "Specified Wi-Fi standard " << standard << " is currently not supported"); + SetStandard(WIFI_STANDARDS_NAME_MAP.at(standard)); +} + void WifiHelper::DisableFlowControl() { diff --git a/src/wifi/helper/wifi-helper.h b/src/wifi/helper/wifi-helper.h index 33b0ebcd5..66fb1ee22 100644 --- a/src/wifi/helper/wifi-helper.h +++ b/src/wifi/helper/wifi-helper.h @@ -444,6 +444,17 @@ class WifiHelper */ virtual void SetStandard(WifiStandard standard); + /** + * \param standard String representation of the Wi-Fi standard + * + * This method overloads WifiHelper::SetStandard(WifiStandard standard) by allowing + * selected string names. For example, the strings "802.11ax", "11ax", and "HE" + * are equivalent and map to WIFI_STANDARD_80211ax. See the documentation of the specified + * function to see how it interacts with attribute configuration. + * \sa WifiHelper::SetStandard(WifiStandard standard) + */ + void SetStandard(const std::string& standard); + /** * Helper function used to configure the HT options listed as attributes of * the HtConfiguration class.