From c4a7058738c3c8fea7aa18b8fda2405e9bbb50e0 Mon Sep 17 00:00:00 2001 From: Sebastien Deronne Date: Wed, 22 Jun 2022 08:33:50 +0200 Subject: [PATCH] wifi: Rework SIG-A and SIG-B processing functions to avoid duplicated code --- src/wifi/model/he/he-phy.cc | 18 ++++++ src/wifi/model/he/he-phy.h | 23 +++++++- src/wifi/model/vht/vht-phy.cc | 107 ++++++++++++++-------------------- src/wifi/model/vht/vht-phy.h | 40 +++++-------- 4 files changed, 98 insertions(+), 90 deletions(-) diff --git a/src/wifi/model/he/he-phy.cc b/src/wifi/model/he/he-phy.cc index 0e013a5df..e92763849 100644 --- a/src/wifi/model/he/he-phy.cc +++ b/src/wifi/model/he/he-phy.cc @@ -546,6 +546,23 @@ HePhy::GetStaId (const Ptr ppdu) const return PhyEntity::GetStaId (ppdu); } +PhyEntity::PhyFieldRxStatus +HePhy::ProcessSig (Ptr event, PhyFieldRxStatus status, WifiPpduField field) +{ + NS_LOG_FUNCTION (this << *event << status << field); + NS_ASSERT (event->GetTxVector ().GetPreambleType () >= WIFI_PREAMBLE_HE_SU); + switch (field) + { + case WIFI_PPDU_FIELD_SIG_A: + return ProcessSigA (event, status); + case WIFI_PPDU_FIELD_SIG_B: + return ProcessSigB (event, status); + default: + NS_ASSERT_MSG (false, "Invalid PPDU field"); + } + return status; +} + PhyEntity::PhyFieldRxStatus HePhy::ProcessSigA (Ptr event, PhyFieldRxStatus status) { @@ -643,6 +660,7 @@ PhyEntity::PhyFieldRxStatus HePhy::ProcessSigB (Ptr event, PhyFieldRxStatus status) { NS_LOG_FUNCTION (this << *event << status); + NS_ASSERT (IsDlMu (event->GetTxVector ().GetPreambleType ())); if (status.isSuccess) { //Check if PPDU is filtered only if the SIG-B content is supported (not explicitly stated but assumed based on behavior for SIG-A) diff --git a/src/wifi/model/he/he-phy.h b/src/wifi/model/he/he-phy.h index cb1b2cbd7..35f11dcf3 100644 --- a/src/wifi/model/he/he-phy.h +++ b/src/wifi/model/he/he-phy.h @@ -382,8 +382,7 @@ public: static bool IsAllowed (const WifiTxVector& txVector); protected: - PhyFieldRxStatus ProcessSigA (Ptr event, PhyFieldRxStatus status) override; - PhyFieldRxStatus ProcessSigB (Ptr event, PhyFieldRxStatus status) override; + PhyFieldRxStatus ProcessSig (Ptr event, PhyFieldRxStatus status, WifiPpduField field) override; Ptr DoGetEvent (Ptr ppdu, RxPowerWattPerChannelBand& rxPowersW) override; bool IsConfigSupported (Ptr ppdu) const override; Time DoStartReceivePayload (Ptr event) override; @@ -400,6 +399,26 @@ protected: uint32_t GetMaxPsduSize (void) const override; WifiConstPsduMap GetWifiConstPsduMap (Ptr psdu, const WifiTxVector& txVector) const override; + /** + * Process SIG-A, perform amendment-specific actions, and + * provide an updated status of the reception. + * + * \param event the event holding incoming PPDU's information + * \param status the status of the reception of the correctly received SIG-A after the configuration support check + * \return the updated status of the reception of the SIG-A + */ + virtual PhyFieldRxStatus ProcessSigA (Ptr event, PhyFieldRxStatus status); + + /** + * Process SIG-B, perform amendment-specific actions, and + * provide an updated status of the reception. + * + * \param event the event holding incoming PPDU's information + * \param status the status of the reception of the correctly received SIG-A after the configuration support check + * \return the updated status of the reception of the SIG-B + */ + virtual PhyFieldRxStatus ProcessSigB (Ptr event, PhyFieldRxStatus status); + /** * Start receiving the PSDU (i.e. the first symbol of the PSDU has arrived) of an UL-OFDMA transmission. * This function is called upon the RX event corresponding to the OFDMA part of the UL MU PPDU. diff --git a/src/wifi/model/vht/vht-phy.cc b/src/wifi/model/vht/vht-phy.cc index 2692cb4a1..5d72747d3 100644 --- a/src/wifi/model/vht/vht-phy.cc +++ b/src/wifi/model/vht/vht-phy.cc @@ -254,78 +254,59 @@ VhtPhy::DoEndReceiveField (WifiPpduField field, Ptr event) switch (field) { case WIFI_PPDU_FIELD_SIG_A: - return EndReceiveSigA (event); + [[fallthrough]]; case WIFI_PPDU_FIELD_SIG_B: - return EndReceiveSigB (event); + return EndReceiveSig (event, field); default: return HtPhy::DoEndReceiveField (field, event); } } PhyEntity::PhyFieldRxStatus -VhtPhy::EndReceiveSigA (Ptr event) +VhtPhy::EndReceiveSig (Ptr event, WifiPpduField field) { - NS_LOG_FUNCTION (this << *event); + NS_LOG_FUNCTION (this << *event << field); + SnrPer snrPer = GetPhyHeaderSnrPer (field, event); + NS_LOG_DEBUG (field << ": SNR(dB)=" << RatioToDb (snrPer.snr) << ", PER=" << snrPer.per); + PhyFieldRxStatus status (GetRandomValue () > snrPer.per); + if (status.isSuccess) + { + NS_LOG_DEBUG ("Received " << field); + if (!IsAllConfigSupported (WIFI_PPDU_FIELD_SIG_A, event->GetPpdu ())) + { + status = PhyFieldRxStatus (false, UNSUPPORTED_SETTINGS, DROP); + } + status = ProcessSig (event, status, field); + } + else + { + NS_LOG_DEBUG ("Drop packet because " << field << " reception failed"); + status.reason = GetFailureReason (field); + status.actionIfFailure = DROP; + } + return status; +} + +WifiPhyRxfailureReason +VhtPhy::GetFailureReason (WifiPpduField field) const +{ + switch (field) + { + case WIFI_PPDU_FIELD_SIG_A: + return SIG_A_FAILURE; + case WIFI_PPDU_FIELD_SIG_B: + return SIG_B_FAILURE; + default: + NS_ASSERT_MSG (false, "Unknown PPDU field"); + return UNKNOWN; + } +} + +PhyEntity::PhyFieldRxStatus +VhtPhy::ProcessSig (Ptr event, PhyFieldRxStatus status, WifiPpduField field) +{ + NS_LOG_FUNCTION (this << *event << status << field); NS_ASSERT (event->GetTxVector ().GetPreambleType () >= WIFI_PREAMBLE_VHT_SU); - SnrPer snrPer = GetPhyHeaderSnrPer (WIFI_PPDU_FIELD_SIG_A, event); - NS_LOG_DEBUG ("SIG-A: SNR(dB)=" << RatioToDb (snrPer.snr) << ", PER=" << snrPer.per); - PhyFieldRxStatus status (GetRandomValue () > snrPer.per); - if (status.isSuccess) - { - NS_LOG_DEBUG ("Received SIG-A"); - if (!IsAllConfigSupported (WIFI_PPDU_FIELD_SIG_A, event->GetPpdu ())) - { - status = PhyFieldRxStatus (false, UNSUPPORTED_SETTINGS, DROP); - } - status = ProcessSigA (event, status); - } - else - { - NS_LOG_DEBUG ("Drop packet because SIG-A reception failed"); - status.reason = SIG_A_FAILURE; - status.actionIfFailure = DROP; - } - return status; -} - -PhyEntity::PhyFieldRxStatus -VhtPhy::ProcessSigA (Ptr event, PhyFieldRxStatus status) -{ - NS_LOG_FUNCTION (this << *event << status); - //TODO see if something should be done here once MU-MIMO is supported - return status; //nothing special for VHT -} - -PhyEntity::PhyFieldRxStatus -VhtPhy::EndReceiveSigB (Ptr event) -{ - NS_LOG_FUNCTION (this << *event); - NS_ASSERT (event->GetPpdu ()->GetType () == WIFI_PPDU_TYPE_DL_MU); - SnrPer snrPer = GetPhyHeaderSnrPer (WIFI_PPDU_FIELD_SIG_B, event); - NS_LOG_DEBUG ("SIG-B: SNR(dB)=" << RatioToDb (snrPer.snr) << ", PER=" << snrPer.per); - PhyFieldRxStatus status (GetRandomValue () > snrPer.per); - if (status.isSuccess) - { - NS_LOG_DEBUG ("Received SIG-B"); - if (!IsAllConfigSupported (WIFI_PPDU_FIELD_SIG_A, event->GetPpdu ())) - { - status = PhyFieldRxStatus (false, UNSUPPORTED_SETTINGS, DROP); - } - status = ProcessSigB (event, status); - } - else - { - NS_LOG_DEBUG ("Drop reception because SIG-B reception failed"); - status.reason = SIG_B_FAILURE; - status.actionIfFailure = DROP; - } - return status; -} - -PhyEntity::PhyFieldRxStatus -VhtPhy::ProcessSigB (Ptr event, PhyFieldRxStatus status) -{ - NS_LOG_FUNCTION (this << *event << status); //TODO see if something should be done here once MU-MIMO is supported return status; //nothing special for VHT } diff --git a/src/wifi/model/vht/vht-phy.h b/src/wifi/model/vht/vht-phy.h index 29ee8fa26..3671197de 100644 --- a/src/wifi/model/vht/vht-phy.h +++ b/src/wifi/model/vht/vht-phy.h @@ -274,46 +274,36 @@ protected: CcaIndication GetCcaIndication (const Ptr ppdu) override; /** - * End receiving the SIG-A, perform VHT-specific actions, and + * End receiving the SIG-A or SIG-B, perform VHT-specific actions, and * provide the status of the reception. * * Child classes can perform amendment-specific actions by specializing - * \see ProcessSigA. + * \see ProcessSig. * * \param event the event holding incoming PPDU's information - * \return status of the reception of the SIG-A + * \param field the current PPDU field + * \return status of the reception of the SIG-A of SIG-B */ - PhyFieldRxStatus EndReceiveSigA (Ptr event); - /** - * End receiving the SIG-B, perform VHT-specific actions, and - * provide the status of the reception. - * - * Child classes can perform amendment-specific actions by specializing - * \see ProcessSigB. - * - * \param event the event holding incoming PPDU's information - * \return status of the reception of the SIG-B - */ - PhyFieldRxStatus EndReceiveSigB (Ptr event); + PhyFieldRxStatus EndReceiveSig (Ptr event, WifiPpduField field); /** - * Process SIG-A, perform amendment-specific actions, and - * provide an updated status of the reception. + * Get the failure reason corresponding to the unsuccessful processing of a given PPDU field. * - * \param event the event holding incoming PPDU's information - * \param status the status of the reception of the correctly received SIG-A after the configuration support check - * \return the updated status of the reception of the SIG-A + * \param field the PPDU field + * \return the failure reason corresponding to the unsuccessful processing of the PPDU field */ - virtual PhyFieldRxStatus ProcessSigA (Ptr event, PhyFieldRxStatus status); + virtual WifiPhyRxfailureReason GetFailureReason (WifiPpduField field) const; + /** - * Process SIG-B, perform amendment-specific actions, and + * Process SIG-A or SIG-B, perform amendment-specific actions, and * provide an updated status of the reception. * * \param event the event holding incoming PPDU's information - * \param status the status of the reception of the correctly received SIG-B after the configuration support check - * \return the updated status of the reception of the SIG-B + * \param status the status of the reception of the correctly received SIG-A or SIG-B after the configuration support check + * \param field the current PPDU field to identify whether it is SIG-A or SIG-B + * \return the updated status of the reception of the SIG-A or SIG-B */ - virtual PhyFieldRxStatus ProcessSigB (Ptr event, PhyFieldRxStatus status); + virtual PhyFieldRxStatus ProcessSig (Ptr event, PhyFieldRxStatus status, WifiPpduField field); /** * Return the rate (in bps) of the non-HT Reference Rate