From 7ea750447641255cbcad3e1d86fa162610c4bdaa Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Ramonet Date: Tue, 26 Sep 2023 16:59:57 +0900 Subject: [PATCH] lr-wpan: Fix PHY BUSY_RX -> RX_ON --- RELEASE_NOTES.md | 2 + src/lr-wpan/model/lr-wpan-phy.cc | 113 ++++++++++++++++++++----------- src/lr-wpan/model/lr-wpan-phy.h | 43 +++++++++--- 3 files changed, 109 insertions(+), 49 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 02f488230..4748254c7 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -22,6 +22,8 @@ Release 3-dev ### Bugs fixed +- (lr-wpan) !1673 - Fixes PHY BUSY_RX -> RX_ON operation + Release 3.40 ------------ diff --git a/src/lr-wpan/model/lr-wpan-phy.cc b/src/lr-wpan/model/lr-wpan-phy.cc index f0f9ad606..ac8708878 100644 --- a/src/lr-wpan/model/lr-wpan-phy.cc +++ b/src/lr-wpan/model/lr-wpan-phy.cc @@ -87,6 +87,61 @@ const LrWpanPhyPpduHeaderSymbolNumber ppduHeaderSymbolNumbers[IEEE_802_15_4_INVA {8.0, 2.0, 2.0}, }; +std::ostream& +operator<<(std::ostream& os, const LrWpanPhyEnumeration& state) +{ + switch (state) + { + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_BUSY: + os << "BUSY"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_BUSY_RX: + os << "BUSY_RX"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_BUSY_TX: + os << "BUSY_TX"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_FORCE_TRX_OFF: + os << "FORCE_TRX_OFF"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_IDLE: + os << "IDLE"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_INVALID_PARAMETER: + os << "INVALID_PARAMETER"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_RX_ON: + os << "RX_ON"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_SUCCESS: + os << "SUCCESS"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_TRX_OFF: + os << "TRX_OFF"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_TX_ON: + os << "TX_ON"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_UNSUPPORTED_ATTRIBUTE: + os << "UNSUPPORTED"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_READ_ONLY: + os << "READ_ONLY"; + break; + case LrWpanPhyEnumeration::IEEE_802_15_4_PHY_UNSPECIFIED: + os << "UNSPECIFIED"; + break; + } + return os; +}; + +std::ostream& +operator<<(std::ostream& os, const TracedValue& state) +{ + LrWpanPhyEnumeration s = state; + return os << s; +}; + TypeId LrWpanPhy::GetTypeId() { @@ -241,14 +296,12 @@ LrWpanPhy::DoDispose() Ptr LrWpanPhy::GetDevice() const { - NS_LOG_FUNCTION(this); return m_device; } Ptr LrWpanPhy::GetMobility() const { - NS_LOG_FUNCTION(this); return m_mobility; } @@ -297,7 +350,6 @@ LrWpanPhy::GetRxSpectrumModel() const Ptr LrWpanPhy::GetAntenna() const { - NS_LOG_FUNCTION(this); return m_antenna; } @@ -548,6 +600,10 @@ LrWpanPhy::EndRx(Ptr par) if (!m_currentRxPacket.second) { + m_currentRxPacket = std::make_pair(nullptr, true); + ChangeTrxState(IEEE_802_15_4_PHY_RX_ON); + NS_LOG_DEBUG("Packet successfully received"); + // The packet was successfully received, push it up the stack. if (!m_pdDataIndicationCallback.IsNull()) { @@ -556,42 +612,21 @@ LrWpanPhy::EndRx(Ptr par) } else { - // The packet was destroyed, drop it. + // The packet was destroyed due to interference, post-rx corruption or + // cancelled, therefore drop it. m_phyRxDropTrace(currentPacket); - } - Ptr none = nullptr; - m_currentRxPacket = std::make_pair(none, true); + m_currentRxPacket = std::make_pair(nullptr, true); - if (!m_isRxCanceled) - { - // We may be waiting to apply a pending state change. - if (m_trxStatePending != IEEE_802_15_4_PHY_IDLE) - { - // Only change the state immediately, if the transceiver is not already - // switching the state. - if (!m_setTRXState.IsRunning()) - { - NS_LOG_LOGIC("Apply pending state change to " << m_trxStatePending); - ChangeTrxState(m_trxStatePending); - m_trxStatePending = IEEE_802_15_4_PHY_IDLE; - if (!m_plmeSetTRXStateConfirmCallback.IsNull()) - { - m_plmeSetTRXStateConfirmCallback(IEEE_802_15_4_PHY_SUCCESS); - } - } - } - else + if (!m_isRxCanceled) { ChangeTrxState(IEEE_802_15_4_PHY_RX_ON); } - } - else - { - // A TX event was forced during the reception of the frame. - // There is no need to change the PHY state after handling the signal, - // because the Forced TX already changed the PHY state. - // Return flag to default state - m_isRxCanceled = false; + else + { + // The state of The PHY was already changed when the packet was canceled + // due to a forced operation. + m_isRxCanceled = false; + } } } } @@ -776,6 +811,7 @@ LrWpanPhy::PlmeSetTRXStateRequest(LrWpanPhyEnumeration state) (state != IEEE_802_15_4_PHY_FORCE_TRX_OFF) && (state != IEEE_802_15_4_PHY_TX_ON)); NS_LOG_LOGIC("Trying to set m_trxState from " << m_trxState << " to " << state); + // this method always overrides previous state setting attempts if (!m_setTRXState.IsExpired()) { @@ -1321,6 +1357,7 @@ void LrWpanPhy::ChangeTrxState(LrWpanPhyEnumeration newState) { NS_LOG_LOGIC(this << " state: " << m_trxState << " -> " << newState); + m_trxStateLogger(Simulator::Now(), m_trxState, newState); m_trxState = newState; } @@ -1560,8 +1597,6 @@ LrWpanPhy::GetCurrentChannelNum() const double LrWpanPhy::GetDataOrSymbolRate(bool isData) { - NS_LOG_FUNCTION(this << isData); - double rate = 0.0; NS_ASSERT(m_phyOption < IEEE_802_15_4_INVALID_PHY_OPTION); @@ -1691,10 +1726,8 @@ LrWpanPhy::SetPhyOption(LrWpanPhyOption phyOption) SetRxSensitivity(-106.58); m_rxLastUpdate = Seconds(0); - Ptr none_packet = nullptr; - Ptr none_params = nullptr; - m_currentRxPacket = std::make_pair(none_params, true); - m_currentTxPacket = std::make_pair(none_packet, true); + m_currentRxPacket = std::make_pair(nullptr, true); + m_currentTxPacket = std::make_pair(nullptr, true); m_errorModel = nullptr; } diff --git a/src/lr-wpan/model/lr-wpan-phy.h b/src/lr-wpan/model/lr-wpan-phy.h index 995c715c3..5cfbc3913 100644 --- a/src/lr-wpan/model/lr-wpan-phy.h +++ b/src/lr-wpan/model/lr-wpan-phy.h @@ -28,6 +28,8 @@ #include #include +#include + namespace ns3 { @@ -122,6 +124,24 @@ enum LrWpanPhyEnumeration IEEE_802_15_4_PHY_UNSPECIFIED = 0xc // all cases not covered by ieee802.15.4 }; +/** + * Overloaded operator to print the value of a LrWpanPhyEnumeration. + * + * \param os The output stream + * \param state The text value of the PHY state + * \return The output stream with text value of the PHY state + */ +std::ostream& operator<<(std::ostream& os, const LrWpanPhyEnumeration& state); + +/** + * Overloaded operator to print the value of a TracedValue. + * + * \param os The output stream + * \param state The text value of the PHY state + * \return The output stream with text value of the PHY state + */ +std::ostream& operator<<(std::ostream& os, const TracedValue& state); + namespace TracedValueCallback { /** @@ -704,7 +724,10 @@ class LrWpanPhy : public SpectrumPhy /** * The trace source fired when a packet ends the reception process from - * the medium. Second quantity is received SINR. + * the medium. In essence, the notional event of receiving all the energy + * of a signal is traced. The received completed signal might represent + * a complete packet or a packet that is later on dropped because of interference, + * cancellation or post-rx corruption. Second quantity is the received SINR (LQI). * * \see class CallBackTraceSource */ @@ -712,6 +735,8 @@ class LrWpanPhy : public SpectrumPhy /** * The trace source fired when the phy layer drops a packet it has received. + * (Destruction of a packet due to interference, post-rx corruption or + * cancellation of packet rx) * * \see class CallBackTraceSource */ @@ -894,18 +919,18 @@ class LrWpanPhy : public SpectrumPhy Time m_rxLastUpdate; /** - * Statusinformation of the currently received packet. The first parameter - * contains the frame, as well the signal power of the frame. The second - * parameter is set to false, if the frame is either invalid or destroyed - * due to interference. + * Status information of the currently received packet. The first parameter + * contains the frame, as well the signal power of the frame. If the second + * parameter is set to true, the frame is either invalid, destroyed + * due to interference or cancelled. */ std::pair, bool> m_currentRxPacket; /** - * Statusinformation of the currently transmitted packet. The first parameter - * contains the frame. The second parameter is set to false, if the frame not - * completely transmitted, in the event of a force transceiver switch, for - * example. + * Status information of the currently transmitted packet. The first parameter + * contains the frame. If the second parameter is set to true, the frame has not + * been completely transmitted (in the event of a force transceiver switch, for + * example). */ PacketAndStatus m_currentTxPacket;