diff --git a/src/wifi/model/phy-entity.cc b/src/wifi/model/phy-entity.cc index 872cc5436..b883b0f96 100644 --- a/src/wifi/model/phy-entity.cc +++ b/src/wifi/model/phy-entity.cc @@ -299,7 +299,7 @@ PhyEntity::EndReceiveField (WifiPpduField field, Ptr event) AbortCurrentReception (status.reason); if (event->GetEndTime () > (Simulator::Now () + m_state->GetDelayUntilIdle ())) { - m_wifiPhy->SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (ppdu)); + m_wifiPhy->SwitchMaybeToCcaBusy (ppdu); } break; case DROP: @@ -384,9 +384,9 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel NS_LOG_DEBUG ("Cannot start RX because device is OFF"); if (endRx > (Simulator::Now () + m_state->GetDelayUntilIdle ())) { - m_wifiPhy->SwitchMaybeToCcaBusy (m_wifiPhy->GetMeasurementChannelWidth (nullptr)); + m_wifiPhy->SwitchMaybeToCcaBusy (nullptr); } - DropPreambleEvent (ppdu, WifiPhyRxfailureReason::POWERED_OFF, endRx, m_wifiPhy->GetMeasurementChannelWidth (ppdu)); + DropPreambleEvent (ppdu, WifiPhyRxfailureReason::POWERED_OFF, endRx); return; } @@ -395,9 +395,9 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel NS_LOG_DEBUG ("Packet reception stopped because transmitter has been switched off"); if (endRx > (Simulator::Now () + m_state->GetDelayUntilIdle ())) { - m_wifiPhy->SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (ppdu)); + m_wifiPhy->SwitchMaybeToCcaBusy (ppdu); } - DropPreambleEvent (ppdu, WifiPhyRxfailureReason::TRUNCATED_TX, endRx, m_wifiPhy->GetMeasurementChannelWidth (ppdu)); + DropPreambleEvent (ppdu, WifiPhyRxfailureReason::TRUNCATED_TX, endRx); return; } @@ -413,7 +413,7 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel * busy due to other devices' transmissions started before the end of * the switching. */ - DropPreambleEvent (ppdu, CHANNEL_SWITCHING, endRx, m_wifiPhy->GetMeasurementChannelWidth (ppdu)); + DropPreambleEvent (ppdu, CHANNEL_SWITCHING, endRx); break; case WifiPhyState::RX: if (m_wifiPhy->m_frameCaptureModel != 0 @@ -427,7 +427,7 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel else { NS_LOG_DEBUG ("Drop packet because already in Rx"); - DropPreambleEvent (ppdu, RXING, endRx, m_wifiPhy->GetMeasurementChannelWidth (ppdu)); + DropPreambleEvent (ppdu, RXING, endRx); if (m_wifiPhy->m_currentEvent == 0) { /* @@ -442,7 +442,7 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel break; case WifiPhyState::TX: NS_LOG_DEBUG ("Drop packet because already in Tx"); - DropPreambleEvent (ppdu, TXING, endRx, m_wifiPhy->GetMeasurementChannelWidth (ppdu)); + DropPreambleEvent (ppdu, TXING, endRx); break; case WifiPhyState::CCA_BUSY: if (m_wifiPhy->m_currentEvent != 0) @@ -458,7 +458,7 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel else { NS_LOG_DEBUG ("Drop packet because already decoding preamble"); - DropPreambleEvent (ppdu, BUSY_DECODING_PREAMBLE, endRx, m_wifiPhy->GetMeasurementChannelWidth (ppdu)); + DropPreambleEvent (ppdu, BUSY_DECODING_PREAMBLE, endRx); } } else @@ -472,7 +472,7 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel break; case WifiPhyState::SLEEP: NS_LOG_DEBUG ("Drop packet because in sleep mode"); - DropPreambleEvent (ppdu, SLEEPING, endRx, m_wifiPhy->GetMeasurementChannelWidth (nullptr)); + DropPreambleEvent (ppdu, SLEEPING, endRx); break; default: NS_FATAL_ERROR ("Invalid WifiPhy state."); @@ -481,19 +481,19 @@ PhyEntity::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannel } void -PhyEntity::DropPreambleEvent (Ptr ppdu, WifiPhyRxfailureReason reason, Time endRx, uint16_t measurementChannelWidth) +PhyEntity::DropPreambleEvent (Ptr ppdu, WifiPhyRxfailureReason reason, Time endRx) { - NS_LOG_FUNCTION (this << ppdu << reason << endRx << measurementChannelWidth); + NS_LOG_FUNCTION (this << ppdu << reason << endRx); m_wifiPhy->NotifyRxDrop (GetAddressedPsduInPpdu (ppdu), reason); auto it = m_wifiPhy->m_currentPreambleEvents.find (std::make_pair (ppdu->GetUid (), ppdu->GetPreamble ())); if (it != m_wifiPhy->m_currentPreambleEvents.end ()) { m_wifiPhy->m_currentPreambleEvents.erase (it); } - if (endRx > (Simulator::Now () + m_state->GetDelayUntilIdle ())) + if (!m_wifiPhy->IsStateSleep () && !m_wifiPhy->IsStateOff () && (endRx > (Simulator::Now () + m_state->GetDelayUntilIdle ()))) { //that PPDU will be noise _after_ the end of the current event. - m_wifiPhy->SwitchMaybeToCcaBusy (measurementChannelWidth); + m_wifiPhy->SwitchMaybeToCcaBusy (ppdu); } } @@ -514,7 +514,7 @@ PhyEntity::ErasePreambleEvent (Ptr ppdu, Time rxDuration) if (rxDuration > m_state->GetDelayUntilIdle ()) { //this PPDU will be noise _after_ the completion of the current event - m_wifiPhy->SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (ppdu)); + m_wifiPhy->SwitchMaybeToCcaBusy (ppdu); } } @@ -665,7 +665,7 @@ PhyEntity::EndReceivePayload (Ptr event) } DoEndReceivePayload (ppdu); - m_wifiPhy->SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (ppdu)); + m_wifiPhy->SwitchMaybeToCcaBusy (ppdu); } void @@ -903,7 +903,7 @@ PhyEntity::EndPreambleDetectionPeriod (Ptr event) NS_LOG_DEBUG ("Drop packet because PHY preamble detection failed"); // Like CCA-SD, CCA-ED is governed by the 4 us CCA window to flag CCA-BUSY // for any received signal greater than the CCA-ED threshold. - DropPreambleEvent (m_wifiPhy->m_currentEvent->GetPpdu (), PREAMBLE_DETECT_FAILURE, m_wifiPhy->m_currentEvent->GetEndTime (), m_wifiPhy->GetMeasurementChannelWidth (m_wifiPhy->m_currentEvent->GetPpdu ())); + DropPreambleEvent (m_wifiPhy->m_currentEvent->GetPpdu (), PREAMBLE_DETECT_FAILURE, m_wifiPhy->m_currentEvent->GetEndTime ()); if (m_wifiPhy->m_currentPreambleEvents.empty ()) { //Do not erase events if there are still pending preamble events to be processed @@ -1004,7 +1004,7 @@ PhyEntity::ResetReceive (Ptr event) m_endRxPayloadEvents.clear (); m_wifiPhy->m_currentEvent = 0; m_wifiPhy->m_currentPreambleEvents.clear (); - m_wifiPhy->SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (event->GetPpdu ())); + m_wifiPhy->SwitchMaybeToCcaBusy (event->GetPpdu ()); } void @@ -1045,15 +1045,16 @@ PhyEntity::GetRxChannelWidth (const WifiTxVector& txVector) const } void -PhyEntity::SwitchMaybeToCcaBusy (uint16_t channelWidth) +PhyEntity::SwitchMaybeToCcaBusy (const Ptr ppdu) { - NS_LOG_FUNCTION (this << channelWidth); //We are here because we have received the first bit of a packet and we are //not going to be able to synchronize on it //In this model, CCA becomes busy when the aggregation of all signals as //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold + const uint16_t channelWidth = m_wifiPhy->GetMeasurementChannelWidth (ppdu); + NS_LOG_FUNCTION (this << channelWidth); const Time delayUntilCcaEnd = m_wifiPhy->m_interference->GetEnergyDuration (m_wifiPhy->m_ccaEdThresholdW, m_wifiPhy->GetPrimaryBand (channelWidth)); - if (!delayUntilCcaEnd.IsZero ()) + if (delayUntilCcaEnd.IsStrictlyPositive ()) { NS_LOG_DEBUG ("Calling SwitchMaybeToCcaBusy for " << delayUntilCcaEnd.As (Time::S)); m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd); diff --git a/src/wifi/model/phy-entity.h b/src/wifi/model/phy-entity.h index b72b50452..b96fb147a 100644 --- a/src/wifi/model/phy-entity.h +++ b/src/wifi/model/phy-entity.h @@ -442,13 +442,11 @@ public: /** * Check if PHY state should move to CCA busy state based on current - * state of interference tracker. In this model, CCA becomes busy when - * the aggregation of all signals as tracked by the InterferenceHelper - * class is higher than the CcaEdThreshold + * state of interference tracker. * - * \param channelWidth the channel width in MHz used for RSSI measurement + * \param ppdu the incoming PPDU or nullptr for any signal */ - virtual void SwitchMaybeToCcaBusy (uint16_t channelWidth); + virtual void SwitchMaybeToCcaBusy (const Ptr ppdu); /** * This function is called by SpectrumWifiPhy to send @@ -606,9 +604,8 @@ protected: * \param ppdu the incoming PPDU * \param reason the reason the PPDU is dropped * \param endRx the end of the incoming PPDU's reception - * \param measurementChannelWidth the measurement width (in MHz) to consider for the PPDU */ - void DropPreambleEvent (Ptr ppdu, WifiPhyRxfailureReason reason, Time endRx, uint16_t measurementChannelWidth); + void DropPreambleEvent (Ptr ppdu, WifiPhyRxfailureReason reason, Time endRx); /** * Erase the event corresponding to the PPDU from the list of preamble events, diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index a7361a035..fad6ee60f 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -330,14 +330,14 @@ SpectrumWifiPhy::StartRx (Ptr rxParams) { NS_LOG_INFO ("Received non Wi-Fi signal"); m_interference->AddForeignSignal (rxDuration, rxPowerW); - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (nullptr)); + SwitchMaybeToCcaBusy (nullptr); return; } if (wifiRxParams && m_disableWifiReception) { NS_LOG_INFO ("Received Wi-Fi signal but blocked from syncing"); m_interference->AddForeignSignal (rxDuration, rxPowerW); - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (nullptr)); + SwitchMaybeToCcaBusy (nullptr); return; } // Do no further processing if signal is too weak @@ -349,7 +349,7 @@ SpectrumWifiPhy::StartRx (Ptr rxParams) NS_LOG_INFO ("Received signal too weak to process: " << WToDbm (totalRxPowerW) << " dBm"); m_interference->Add (wifiRxParams->ppdu, wifiRxParams->ppdu->GetTxVector (), rxDuration, rxPowerW); - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (nullptr)); + SwitchMaybeToCcaBusy (nullptr); return; } @@ -369,7 +369,7 @@ SpectrumWifiPhy::StartRx (Ptr rxParams) NS_LOG_INFO ("Cannot receive the PPDU, consider it as interference"); m_interference->Add (wifiRxParams->ppdu, wifiRxParams->ppdu->GetTxVector (), rxDuration, rxPowerW); - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (wifiRxParams->ppdu)); + SwitchMaybeToCcaBusy (wifiRxParams->ppdu); return; } } diff --git a/src/wifi/model/wifi-phy.cc b/src/wifi/model/wifi-phy.cc index 72bd55c38..3450dc694 100644 --- a/src/wifi/model/wifi-phy.cc +++ b/src/wifi/model/wifi-phy.cc @@ -1264,7 +1264,7 @@ WifiPhy::ResumeFromSleep (void) { NS_LOG_DEBUG ("resuming from sleep mode"); m_state->SwitchFromSleep (); - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (nullptr)); + SwitchMaybeToCcaBusy (nullptr); break; } default: @@ -1295,7 +1295,7 @@ WifiPhy::ResumeFromOff (void) { NS_LOG_DEBUG ("resuming from off mode"); m_state->SwitchFromOff (); - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (nullptr)); + SwitchMaybeToCcaBusy (nullptr); break; } default: @@ -1636,7 +1636,7 @@ WifiPhy::Reset (void) { phyEntity.second->CancelAllEvents (); } - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (nullptr)); + SwitchMaybeToCcaBusy (nullptr); } void @@ -1653,7 +1653,7 @@ WifiPhy::StartReceivePreamble (Ptr ppdu, RxPowerWattPerChannelBa //TODO find a fallback PHY for receiving the PPDU (e.g. 11a for 11ax due to preamble structure) NS_LOG_DEBUG ("Unsupported modulation received (" << modulation << "), consider as noise"); m_interference->Add (ppdu, ppdu->GetTxVector (), rxDuration, rxPowersW); - SwitchMaybeToCcaBusy (GetMeasurementChannelWidth (nullptr)); + SwitchMaybeToCcaBusy (nullptr); } } @@ -1874,10 +1874,10 @@ WifiPhy::GetLastRxEndTime (void) const } void -WifiPhy::SwitchMaybeToCcaBusy (uint16_t channelWidth) +WifiPhy::SwitchMaybeToCcaBusy (const Ptr ppdu) { - NS_LOG_FUNCTION (this << channelWidth); - GetPhyEntity (m_standard)->SwitchMaybeToCcaBusy (channelWidth); + NS_LOG_FUNCTION (this); + GetPhyEntity (m_standard)->SwitchMaybeToCcaBusy (ppdu); } void diff --git a/src/wifi/model/wifi-phy.h b/src/wifi/model/wifi-phy.h index 079ee0c0b..3de84beff 100644 --- a/src/wifi/model/wifi-phy.h +++ b/src/wifi/model/wifi-phy.h @@ -1077,13 +1077,11 @@ protected: /** * Check if PHY state should move to CCA busy state based on current - * state of interference tracker. In this model, CCA becomes busy when - * the aggregation of all signals as tracked by the InterferenceHelper - * class is higher than the CcaEdThreshold + * state of interference tracker. * - * \param channelWidth the channel width in MHz used for RSSI measurement + * \param ppdu the incoming PPDU or nullptr for any signal */ - void SwitchMaybeToCcaBusy (uint16_t channelWidth); + void SwitchMaybeToCcaBusy (const Ptr ppdu); /** * Return the channel width used to measure the RSSI.