From 5a4b72fa3dcc14352d94a71ce96ad6ef6fa4510d Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Fri, 9 Dec 2022 16:29:12 +0000 Subject: [PATCH] lr-wpan: Remove {Get,Set}UnitBackoffPeriod() functions Move the corresponding constant to lr-wpan-constants.h --- CHANGES.md | 1 + src/lr-wpan/model/lr-wpan-constants.h | 5 +++++ src/lr-wpan/model/lr-wpan-csmaca.cc | 27 ++++++--------------------- src/lr-wpan/model/lr-wpan-csmaca.h | 24 ++---------------------- src/lr-wpan/model/lr-wpan-mac.cc | 2 +- 5 files changed, 15 insertions(+), 44 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 34ffee479..b7a8be4f1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,6 +30,7 @@ Changes from ns-3.37 to ns-3.38 * (internet) `TcpCubic` attribute `HyStartDetect` changed from `int` to `enum HybridSSDetectionMode`. * (internet-apps) Classes `v4Ping` and `Ping6` will be deprecated and removed in the future, replaced by the new `Ping` class. * (lr-wpan) Add file `src/lr-wpan/model/lr-wpan-constants.h` with common constants of the LR-WPAN module. +* (lr-wpan) Remove the functions `LrWpanCsmaCa::GetUnitBackoffPeriod()` and `LrWpanCsmaCa::SetUnitBackoffPeriod()`, and move the constant `m_aUnitBackoffPeriod` to `src/lr-wpan/model/lr-wpan-constants.h`. ### Changes to build system diff --git a/src/lr-wpan/model/lr-wpan-constants.h b/src/lr-wpan/model/lr-wpan-constants.h index af5da70e3..1c6cefa0a 100644 --- a/src/lr-wpan/model/lr-wpan-constants.h +++ b/src/lr-wpan/model/lr-wpan-constants.h @@ -96,6 +96,11 @@ constexpr uint32_t aMaxPhyPacketSize{127}; */ constexpr uint32_t aTurnaroundTime{12}; +/** + * Number of symbols per CSMA/CA time unit, default 20 symbols. + */ +constexpr uint32_t aUnitBackoffPeriod{20}; + /** @} */ } // namespace lrwpan diff --git a/src/lr-wpan/model/lr-wpan-csmaca.cc b/src/lr-wpan/model/lr-wpan-csmaca.cc index af1190e99..1cc3c39e7 100644 --- a/src/lr-wpan/model/lr-wpan-csmaca.cc +++ b/src/lr-wpan/model/lr-wpan-csmaca.cc @@ -61,7 +61,6 @@ LrWpanCsmaCa::LrWpanCsmaCa() m_macMinBE = 3; m_macMaxBE = 5; m_macMaxCSMABackoffs = 4; - m_aUnitBackoffPeriod = 20; // symbols m_random = CreateObject(); m_BE = m_macMinBE; m_ccaRequestRunning = false; @@ -171,20 +170,6 @@ LrWpanCsmaCa::GetMacMaxCSMABackoffs() const return m_macMaxCSMABackoffs; } -void -LrWpanCsmaCa::SetUnitBackoffPeriod(uint64_t unitBackoffPeriod) -{ - NS_LOG_FUNCTION(this << unitBackoffPeriod); - m_aUnitBackoffPeriod = unitBackoffPeriod; -} - -uint64_t -LrWpanCsmaCa::GetUnitBackoffPeriod() const -{ - NS_LOG_FUNCTION(this); - return m_aUnitBackoffPeriod; -} - Time LrWpanCsmaCa::GetTimeToNextSlot() const { @@ -221,8 +206,8 @@ LrWpanCsmaCa::GetTimeToNextSlot() const // get a close value to the the boundary in symbols elapsedSuperframeSymbols = elapsedSuperframe.GetSeconds() * symbolRate; - symbolsToBoundary = - m_aUnitBackoffPeriod - std::fmod((double)elapsedSuperframeSymbols, m_aUnitBackoffPeriod); + symbolsToBoundary = lrwpan::aUnitBackoffPeriod - + std::fmod((double)elapsedSuperframeSymbols, lrwpan::aUnitBackoffPeriod); timeAtBoundary = Seconds((double)(elapsedSuperframeSymbols + symbolsToBoundary) / symbolRate); @@ -310,7 +295,7 @@ LrWpanCsmaCa::RandomBackoffDelay() } randomBackoff = - Seconds((double)(m_randomBackoffPeriodsLeft * GetUnitBackoffPeriod()) / symbolRate); + Seconds((double)(m_randomBackoffPeriodsLeft * lrwpan::aUnitBackoffPeriod) / symbolRate); if (IsUnSlottedCsmaCa()) { @@ -332,14 +317,14 @@ LrWpanCsmaCa::RandomBackoffDelay() << randomBackoff.As(Time::S) << ")"); NS_LOG_DEBUG("Backoff periods left in CAP: " - << ((timeLeftInCap.GetSeconds() * symbolRate) / m_aUnitBackoffPeriod) << " (" - << (timeLeftInCap.GetSeconds() * symbolRate) << " symbols or " + << ((timeLeftInCap.GetSeconds() * symbolRate) / lrwpan::aUnitBackoffPeriod) + << " (" << (timeLeftInCap.GetSeconds() * symbolRate) << " symbols or " << timeLeftInCap.As(Time::S) << ")"); if (randomBackoff >= timeLeftInCap) { uint64_t usedBackoffs = - (double)(timeLeftInCap.GetSeconds() * symbolRate) / m_aUnitBackoffPeriod; + (double)(timeLeftInCap.GetSeconds() * symbolRate) / lrwpan::aUnitBackoffPeriod; m_randomBackoffPeriodsLeft -= usedBackoffs; NS_LOG_DEBUG("No time in CAP to complete backoff delay, deferring to the next CAP"); m_endCapEvent = diff --git a/src/lr-wpan/model/lr-wpan-csmaca.h b/src/lr-wpan/model/lr-wpan-csmaca.h index ac9532dea..c7e9e6348 100644 --- a/src/lr-wpan/model/lr-wpan-csmaca.h +++ b/src/lr-wpan/model/lr-wpan-csmaca.h @@ -149,22 +149,6 @@ class LrWpanCsmaCa : public Object * \return the maximum number of backoffs */ uint8_t GetMacMaxCSMABackoffs() const; - /** - * Set the number of symbols forming the basic time period used by the - * CSMA-CA algorithm. - * See IEEE 802.15.4-2006, section 7.4.1, Table 85. - * - * \param unitBackoffPeriod the period length in symbols - */ - void SetUnitBackoffPeriod(uint64_t unitBackoffPeriod); - /** - * Get the number of symbols forming the basic time period used by the - * CSMA-CA algorithm. - * See IEEE 802.15.4-2006, section 7.4.1, Table 85. - * - * \return the period length in symbols - */ - uint64_t GetUnitBackoffPeriod() const; /** * Locates the time to the next backoff period boundary in the SUPERFRAME * and returns the amount of time left to this moment. @@ -277,7 +261,7 @@ class LrWpanCsmaCa : public Object */ bool m_isSlotted; /** - * The MAC instance for which this CSMA/CA implemenation is configured. + * The MAC instance for which this CSMA/CA implementation is configured. */ Ptr m_mac; /** @@ -299,7 +283,7 @@ class LrWpanCsmaCa : public Object /** * Minimum backoff exponent. 0 - macMaxBE, default 3 */ - uint8_t m_macMinBE; // + uint8_t m_macMinBE; /** * Maximum backoff exponent. 3 - 8, default 5 */ @@ -308,10 +292,6 @@ class LrWpanCsmaCa : public Object * Maximum number of backoffs. 0 - 5, default 4 */ uint8_t m_macMaxCSMABackoffs; - /** - * Number of symbols per CSMA/CA time unit, default 20 symbols. - */ - uint64_t m_aUnitBackoffPeriod; /** * Count the number of remaining random backoff periods left to delay. */ diff --git a/src/lr-wpan/model/lr-wpan-mac.cc b/src/lr-wpan/model/lr-wpan-mac.cc index 734383ed2..b7067a46d 100644 --- a/src/lr-wpan/model/lr-wpan-mac.cc +++ b/src/lr-wpan/model/lr-wpan-mac.cc @@ -3435,7 +3435,7 @@ LrWpanMac::ChangeMacState(LrWpanMacState newState) uint64_t LrWpanMac::GetMacAckWaitDuration() const { - return m_csmaCa->GetUnitBackoffPeriod() + lrwpan::aTurnaroundTime + m_phy->GetPhySHRDuration() + + return lrwpan::aUnitBackoffPeriod + lrwpan::aTurnaroundTime + m_phy->GetPhySHRDuration() + ceil(6 * m_phy->GetPhySymbolsPerOctet()); }