From 7ba8f348dcb659b028ab06e3977f7eb409b0d89c Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Thu, 19 Jul 2018 16:32:45 -0500 Subject: [PATCH] [mac] separate configs for macMaxCSMABackoffs and macMaxFrameRetries (#2881) This commit aligns the MAC CSMA backoff and retransmit configuration more closely with IEEE 802.15.4-2006. --- include/openthread/platform/radio.h | 3 +- src/core/Makefile.am | 1 + src/core/api/link_raw.hpp | 4 +- src/core/api/link_raw_api.cpp | 21 +++++++---- src/core/mac/mac.cpp | 35 ++++++++--------- src/core/mac/mac.hpp | 30 ++++++--------- src/core/mac/mac_frame.hpp | 40 +++++++++++++++++--- src/core/openthread-core-config-check.h | 42 +++++++++++++++++++++ src/core/openthread-core-config.h | 2 + src/core/openthread-core-default-config.h | 46 ++++++++++++++++++----- src/core/thread/mesh_forwarder.cpp | 16 +++++--- src/core/thread/mesh_forwarder.hpp | 3 +- src/core/thread/mesh_forwarder_ftd.cpp | 7 ++-- src/ncp/ncp_base_radio.cpp | 3 +- 14 files changed, 178 insertions(+), 75 deletions(-) create mode 100644 src/core/openthread-core-config-check.h diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index 1d5aa9829..15b99174c 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -124,7 +124,8 @@ typedef struct otRadioFrame */ struct { - uint8_t mMaxTxAttempts; ///< Max number of transmit attempts for an outbound frame. + uint8_t mMaxCsmaBackoffs; ///< Maximum number of backoffs attempts before declaring CCA failure. + uint8_t mMaxFrameRetries; ///< Maximum number of retries allowed after a transmission failure. bool mIsARetx : 1; ///< True if this frame is a retransmission (ignored by radio driver). bool mCsmaCaEnabled : 1; ///< Set to true to enable CSMA-CA for this packet, false otherwise. const uint8_t *mAesKey; ///< The key used for AES-CCM frame security. diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 28c6cb805..0c509c43a 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -233,6 +233,7 @@ libopenthread_ftd_a_SOURCES = \ $(NULL) HEADERS_COMMON = \ + openthread-core-config-check.h \ openthread-core-config.h \ openthread-core-default-config.h \ api/link_raw.hpp \ diff --git a/src/core/api/link_raw.hpp b/src/core/api/link_raw.hpp index f9de0b84c..2a4c42fbd 100644 --- a/src/core/api/link_raw.hpp +++ b/src/core/api/link_raw.hpp @@ -263,8 +263,8 @@ private: #if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT - uint8_t mTransmitAttempts; - uint8_t mCsmaAttempts; + uint8_t mTransmitRetries; + uint8_t mCsmaBackoffs; #endif // OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT diff --git a/src/core/api/link_raw_api.cpp b/src/core/api/link_raw_api.cpp index bebc8c260..67dd6f0f4 100644 --- a/src/core/api/link_raw_api.cpp +++ b/src/core/api/link_raw_api.cpp @@ -53,6 +53,10 @@ LinkRaw::LinkRaw(Instance &aInstance) , mTimerMicro(aInstance, &LinkRaw::HandleTimer, this) #endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER #endif // OPENTHREAD_LINKRAW_TIMER_REQUIRED +#if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT + , mTransmitRetries(0) + , mCsmaBackoffs(0) +#endif // OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT #if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN , mEnergyScanTask(aInstance, &LinkRaw::HandleEnergyScanTask, this) #endif // OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN @@ -225,8 +229,8 @@ otError LinkRaw::Transmit(otRadioFrame *aFrame, otLinkRawTransmitDone aCallback) mTransmitDoneCallback = aCallback; #if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT - mTransmitAttempts = 0; - mCsmaAttempts = 0; + mTransmitRetries = 0; + mCsmaBackoffs = 0; #endif // OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT #if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_CSMA_BACKOFF @@ -260,9 +264,10 @@ void LinkRaw::InvokeTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, if (aError == OT_ERROR_CHANNEL_ACCESS_FAILURE) { - if (mCsmaAttempts < Mac::kMaxCSMABackoffs) + mCsmaBackoffs++; + + if (mCsmaBackoffs < aFrame->mInfo.mTxInfo.mMaxCsmaBackoffs) { - mCsmaAttempts++; #if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_CSMA_BACKOFF StartCsmaBackoff(); #else @@ -279,14 +284,14 @@ void LinkRaw::InvokeTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, } else { - mCsmaAttempts = 0; + mCsmaBackoffs = 0; } if (aError == OT_ERROR_NO_ACK) { - if (mTransmitAttempts < aFrame->mInfo.mTxInfo.mMaxTxAttempts) + if (mTransmitRetries < aFrame->mInfo.mTxInfo.mMaxFrameRetries) { - mTransmitAttempts++; + mTransmitRetries++; #if OPENTHREAD_CONFIG_ENABLE_SOFTWARE_CSMA_BACKOFF StartCsmaBackoff(); #else @@ -451,7 +456,7 @@ void LinkRaw::HandleTimer(void) void LinkRaw::StartCsmaBackoff(void) { - uint32_t backoffExponent = Mac::kMinBE + mTransmitAttempts + mCsmaAttempts; + uint32_t backoffExponent = Mac::kMinBE + mTransmitRetries + mCsmaBackoffs; uint32_t backoff; if (backoffExponent > Mac::kMaxBE) diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index ec9f3ad6b..17982ac59 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -177,8 +177,8 @@ Mac::Mac(Instance &aInstance) , mReceiveTail(NULL) , mBeaconSequence(Random::GetUint8()) , mDataSequence(Random::GetUint8()) - , mCsmaAttempts(0) - , mTransmitAttempts(0) + , mCsmaBackoffs(0) + , mTransmitRetries(0) , mBroadcastTransmitCount(0) , mScanChannelMask() , mScanDuration(0) @@ -1029,14 +1029,14 @@ void Mac::StartCsmaBackoff(void) BeginTransmit(); } #if OPENTHREAD_CONFIG_DISABLE_CSMA_CA_ON_LAST_ATTEMPT - else if (mTransmitAttempts == (sendFrame.GetMaxTxAttempts() - 1)) + else if ((sendFrame.GetMaxFrameRetries() > 0) && (sendFrame.GetMaxFrameRetries() <= mTransmitRetries)) { BeginTransmit(); } #endif else { - uint32_t backoffExponent = kMinBE + mTransmitAttempts + mCsmaAttempts; + uint32_t backoffExponent = kMinBE + mTransmitRetries + mCsmaBackoffs; uint32_t backoff; bool shouldReceive; @@ -1145,7 +1145,7 @@ void Mac::BeginTransmit(void) VerifyOrExit(mEnabled, error = OT_ERROR_ABORT); #if OPENTHREAD_CONFIG_DISABLE_CSMA_CA_ON_LAST_ATTEMPT - if (mTransmitAttempts == (sendFrame.GetMaxTxAttempts() - 1)) + else if ((sendFrame.GetMaxFrameRetries() > 0) && (sendFrame.GetMaxFrameRetries() <= mTransmitRetries)) { sendFrame.SetCsmaCaEnabled(false); } @@ -1155,7 +1155,7 @@ void Mac::BeginTransmit(void) sendFrame.SetCsmaCaEnabled(true); } - if (mCsmaAttempts == 0 && mTransmitAttempts == 0 && mBroadcastTransmitCount == 0) + if (mCsmaBackoffs == 0 && mTransmitRetries == 0 && mBroadcastTransmitCount == 0) { switch (mOperation) { @@ -1164,14 +1164,16 @@ void Mac::BeginTransmit(void) sendFrame.SetChannel(mScanChannel); SendBeaconRequest(sendFrame); sendFrame.SetSequence(0); - sendFrame.SetMaxTxAttempts(kDirectFrameMacTxAttempts); + sendFrame.SetMaxCsmaBackoffs(kMaxCsmaBackoffsDirect); + sendFrame.SetMaxFrameRetries(kMaxFrameRetriesDirect); break; case kOperationTransmitBeacon: sendFrame.SetChannel(mRadioChannel); SendBeacon(sendFrame); sendFrame.SetSequence(mBeaconSequence++); - sendFrame.SetMaxTxAttempts(kDirectFrameMacTxAttempts); + sendFrame.SetMaxCsmaBackoffs(kMaxCsmaBackoffsDirect); + sendFrame.SetMaxFrameRetries(kMaxFrameRetriesDirect); break; case kOperationTransmitData: @@ -1332,15 +1334,15 @@ void Mac::HandleTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otEr { mCounters.mTxErrCca++; - if (!RadioSupportsCsmaBackoff() && mCsmaAttempts < kMaxCSMABackoffs) + if (!RadioSupportsCsmaBackoff() && mCsmaBackoffs < sendFrame.GetMaxCsmaBackoffs()) { - mCsmaAttempts++; + mCsmaBackoffs++; StartCsmaBackoff(); ExitNow(); } } - mCsmaAttempts = 0; + mCsmaBackoffs = 0; sendFrame.GetDstAddr(dstAddr); neighbor = GetNetif().GetMle().GetNeighbor(dstAddr); @@ -1378,23 +1380,22 @@ void Mac::HandleTransmitDone(otRadioFrame *aFrame, otRadioFrame *aAckFrame, otEr // Determine whether to re-transmit the frame. - mTransmitAttempts++; - if (aError != OT_ERROR_NONE) { LogFrameTxFailure(sendFrame, aError); otDumpDebgMac(GetInstance(), "TX ERR", sendFrame.GetHeader(), 16); - if (mEnabled && !RadioSupportsRetries() && mTransmitAttempts < sendFrame.GetMaxTxAttempts()) + if (mEnabled && !RadioSupportsRetries() && mTransmitRetries < sendFrame.GetMaxFrameRetries()) { + mTransmitRetries++; mCounters.mTxRetry++; StartCsmaBackoff(); ExitNow(); } } - mTransmitAttempts = 0; + mTransmitRetries = 0; // Process the ack frame for "frame pending". @@ -2331,8 +2332,8 @@ void Mac::LogFrameRxFailure(const Frame *aFrame, otError aError) const void Mac::LogFrameTxFailure(const Frame &aFrame, otError aError) const { - otLogInfoMac(GetInstance(), "Frame tx failed, error:%s, attempt:%d/%d, %s", otThreadErrorToString(aError), - mTransmitAttempts, aFrame.GetMaxTxAttempts(), aFrame.ToInfoString().AsCString()); + otLogInfoMac(GetInstance(), "Frame tx failed, error:%s, retries:%d/%d, %s", otThreadErrorToString(aError), + mTransmitRetries, aFrame.GetMaxFrameRetries(), aFrame.ToInfoString().AsCString()); } void Mac::LogBeacon(const char *aActionText, const BeaconPayload &aBeaconPayload) const diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 13e655a56..30ff5cdb5 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -71,7 +71,6 @@ enum { kMinBE = 3, ///< macMinBE (IEEE 802.15.4-2006). kMaxBE = 5, ///< macMaxBE (IEEE 802.15.4-2006). - kMaxCSMABackoffs = 4, ///< macMaxCSMABackoffs (IEEE 802.15.4-2006). kUnitBackoffPeriod = 20, ///< Number of symbols (IEEE 802.15.4-2006). kMinBackoff = 1, ///< Minimum backoff (milliseconds). @@ -84,24 +83,17 @@ enum kScanChannelsAll = OT_CHANNEL_ALL, ///< All channels. kScanDurationDefault = 300, ///< Default interval between channels (milliseconds). - /** - * Maximum number of MAC layer tx attempts for an outbound direct frame. - * - */ - kDirectFrameMacTxAttempts = OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_DIRECT, + kMaxCsmaBackoffsDirect = + OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT, ///< macMaxCsmaBackoffs for direct transmissions + kMaxCsmaBackoffsIndirect = + OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_INDIRECT, ///< macMaxCsmaBackoffs for indirect transmissions - /** - * Maximum number of MAC layer tx attempts for an outbound indirect frame (for a sleepy child) after receiving - * a data request command (data poll) from the child. - * - */ - kIndirectFrameMacTxAttempts = OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_PER_POLL, + kMaxFrameRetriesDirect = + OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_DIRECT, ///< macMaxFrameRetries for direct transmissions + kMaxFrameRetriesIndirect = + OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_INDIRECT, ///< macMaxFrameRetries for indirect transmissions - /** - * The transmit number of a broadcast frame in MAC layer. - * - */ - kTxNumBcast = OPENTHREAD_CONFIG_TX_NUM_BCAST, + kTxNumBcast = OPENTHREAD_CONFIG_TX_NUM_BCAST ///< Number of times each broadcast frame is transmitted }; /** @@ -1059,8 +1051,8 @@ private: uint8_t mBeaconSequence; uint8_t mDataSequence; - uint8_t mCsmaAttempts; - uint8_t mTransmitAttempts; + uint8_t mCsmaBackoffs; + uint8_t mTransmitRetries; uint8_t mBroadcastTransmitCount; ChannelMask mScanChannelMask; diff --git a/src/core/mac/mac_frame.hpp b/src/core/mac/mac_frame.hpp index 67fdfb560..fd45070ab 100644 --- a/src/core/mac/mac_frame.hpp +++ b/src/core/mac/mac_frame.hpp @@ -989,20 +989,48 @@ public: void SetLqi(uint8_t aLqi) { mInfo.mRxInfo.mLqi = aLqi; } /** - * This method returns the maximum number of transmit attempts for the frame. + * This method returns the maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel + * access failure. * - * @returns The maximum number of transmit attempts. + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006. + * + * @returns The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access + * failure. * */ - uint8_t GetMaxTxAttempts(void) const { return mInfo.mTxInfo.mMaxTxAttempts; } + uint8_t GetMaxCsmaBackoffs(void) const { return mInfo.mTxInfo.mMaxCsmaBackoffs; } /** - * This method set the maximum number of transmit attempts for frame. + * This method sets the maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel + * access failure. * - * @returns The maximum number of transmit attempts. + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006. + * + * @param[in] aMaxCsmaBackoffs The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring + * a channel access failure. * */ - void SetMaxTxAttempts(uint8_t aMaxTxAttempts) { mInfo.mTxInfo.mMaxTxAttempts = aMaxTxAttempts; } + void SetMaxCsmaBackoffs(uint8_t aMaxCsmaBackoffs) { mInfo.mTxInfo.mMaxCsmaBackoffs = aMaxCsmaBackoffs; } + + /** + * This method returns the maximum number of retries allowed after a transmission failure. + * + * Equivalent to macMaxFrameRetries in IEEE 802.15.4-2006. + * + * @returns The maximum number of retries allowed after a transmission failure. + * + */ + uint8_t GetMaxFrameRetries(void) const { return mInfo.mTxInfo.mMaxFrameRetries; } + + /** + * This method sets the maximum number of retries allowed after a transmission failure. + * + * Equivalent to macMaxFrameRetries in IEEE 802.15.4-2006. + * + * @param[in] aMaxFrameRetries The maximum number of retries allowed after a transmission failure. + * + */ + void SetMaxFrameRetries(uint8_t aMaxFrameRetries) { mInfo.mTxInfo.mMaxFrameRetries = aMaxFrameRetries; } /** * This method indicates whether or not the frame is a retransmission. diff --git a/src/core/openthread-core-config-check.h b/src/core/openthread-core-config-check.h new file mode 100644 index 000000000..96c3d7c3e --- /dev/null +++ b/src/core/openthread-core-config-check.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * Sanity checking for configuration options. + */ + +#ifndef OPENTHREAD_CORE_CONFIG_CHECK_H_ +#define OPENTHREAD_CORE_CONFIG_CHECK_H_ + +#ifdef OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_PER_POLL +#error \ + "OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_PER_POLL was replaced by OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_INDIRECT." +#endif + +#endif // OPENTHREAD_CORE_CONFIG_CHECK_H_ diff --git a/src/core/openthread-core-config.h b/src/core/openthread-core-config.h index 9fd0a88b8..ab0d82777 100644 --- a/src/core/openthread-core-config.h +++ b/src/core/openthread-core-config.h @@ -46,4 +46,6 @@ #undef OPENTHREAD_CORE_CONFIG_H_IN +#include "openthread-core-config-check.h" + #endif // OPENTHREAD_CORE_CONFIG_H_ diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index fd0e9c9a6..4f40aa62b 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -126,25 +126,51 @@ #endif /** - * @def OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_DIRECT + * @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT * - * Maximum number of MAC layer transmit attempts for an outbound direct frame. - * Per IEEE 802.15.4-2006, default value is set to (macMaxFrameRetries + 1) with macMaxFrameRetries = 3. + * The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4. * */ -#ifndef OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_DIRECT -#define OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_DIRECT 4 +#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT 32 #endif /** - * @def OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_PER_POLL + * @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_INDIRECT * - * Maximum number of MAC layer transmit attempts for an outbound indirect frame (to a sleepy child) after receiving - * a data request command (data poll) from the child. + * The maximum number of backoffs the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * Equivalent to macMaxCSMABackoffs in IEEE 802.15.4-2006, default value is 4. * */ -#ifndef OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_PER_POLL -#define OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_PER_POLL 1 +#ifndef OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_INDIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_INDIRECT 4 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_DIRECT + * + * The maximum number of retries allowed after a transmission failure for direct transmissions. + * + * Equivalent to macMaxFrameRetries, default value is 3. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_DIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_DIRECT 3 +#endif + +/** + * @def OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_INDIRECT + * + * The maximum number of retries allowed after a transmission failure for indirect transmissions. + * + * Equivalent to macMaxFrameRetries, default value is 0. + * + */ +#ifndef OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_INDIRECT +#define OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_INDIRECT 0 #endif /** diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 150d5b2d2..f7dbd2673 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -65,7 +65,8 @@ MeshForwarder::MeshForwarder(Instance &aInstance) , mMessageNextOffset(0) , mSendMessage(NULL) , mSendMessageIsARetransmission(false) - , mSendMessageMaxMacTxAttempts(Mac::kDirectFrameMacTxAttempts) + , mSendMessageMaxCsmaBackoffs(Mac::kMaxCsmaBackoffsDirect) + , mSendMessageMaxFrameRetries(Mac::kMaxFrameRetriesDirect) , mMeshSource() , mMeshDest() , mAddMeshHeader(false) @@ -184,7 +185,8 @@ void MeshForwarder::ScheduleTransmissionTask(void) mSendMessage->SetTxSuccess(true); } - mSendMessageMaxMacTxAttempts = Mac::kDirectFrameMacTxAttempts; + mSendMessageMaxCsmaBackoffs = Mac::kMaxCsmaBackoffsDirect; + mSendMessageMaxFrameRetries = Mac::kMaxFrameRetriesDirect; GetNetif().GetMac().SendFrameRequest(mMacSender); ExitNow(); } @@ -469,7 +471,8 @@ otError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame) { SendEmptyFrame(aFrame, false); aFrame.SetIsARetransmission(false); - aFrame.SetMaxTxAttempts(Mac::kDirectFrameMacTxAttempts); + aFrame.SetMaxCsmaBackoffs(Mac::kMaxCsmaBackoffsDirect); + aFrame.SetMaxFrameRetries(Mac::kMaxFrameRetriesDirect); ExitNow(); } @@ -534,7 +537,8 @@ otError MeshForwarder::HandleFrameRequest(Mac::Frame &aFrame) assert(error == OT_ERROR_NONE); aFrame.SetIsARetransmission(mSendMessageIsARetransmission); - aFrame.SetMaxTxAttempts(mSendMessageMaxMacTxAttempts); + aFrame.SetMaxCsmaBackoffs(mSendMessageMaxCsmaBackoffs); + aFrame.SetMaxFrameRetries(mSendMessageMaxFrameRetries); #if OPENTHREAD_FTD @@ -990,11 +994,11 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError) HandleSentFrameToChild(aFrame, aError, macDest); - VerifyOrExit((mSendMessage != NULL) && ((aError == OT_ERROR_NONE) || (aError == OT_ERROR_NO_ACK))); + VerifyOrExit(mSendMessage != NULL); if (mSendMessage->GetDirectTransmission()) { - if (aError == OT_ERROR_NO_ACK) + if (aError != OT_ERROR_NONE) { // If the transmission of any fragment frame fails, // the overall message transmission is considered diff --git a/src/core/thread/mesh_forwarder.hpp b/src/core/thread/mesh_forwarder.hpp index f6728f55c..e6647b62f 100644 --- a/src/core/thread/mesh_forwarder.hpp +++ b/src/core/thread/mesh_forwarder.hpp @@ -400,7 +400,8 @@ private: Message *mSendMessage; bool mSendMessageIsARetransmission; - uint8_t mSendMessageMaxMacTxAttempts; + uint8_t mSendMessageMaxCsmaBackoffs; + uint8_t mSendMessageMaxFrameRetries; Mac::Address mMacSource; Mac::Address mMacDest; diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 497fdfe02..734148b1c 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -385,8 +385,9 @@ otError MeshForwarder::GetIndirectTransmission(void) continue; } - mSendMessage = child.GetIndirectMessage(); - mSendMessageMaxMacTxAttempts = Mac::kIndirectFrameMacTxAttempts; + mSendMessage = child.GetIndirectMessage(); + mSendMessageMaxCsmaBackoffs = Mac::kMaxCsmaBackoffsIndirect; + mSendMessageMaxFrameRetries = Mac::kMaxFrameRetriesIndirect; if (mSendMessage == NULL) { @@ -649,8 +650,6 @@ void MeshForwarder::HandleSentFrameToChild(const Mac::Frame &aFrame, otError aEr } } - VerifyOrExit((aError == OT_ERROR_NONE) || (aError == OT_ERROR_NO_ACK)); - if (mMessageNextOffset < mSendMessage->GetLength()) { if (mSendMessage == child->GetIndirectMessage()) diff --git a/src/ncp/ncp_base_radio.cpp b/src/ncp/ncp_base_radio.cpp index fd43f9bb1..d49399e4e 100644 --- a/src/ncp/ncp_base_radio.cpp +++ b/src/ncp/ncp_base_radio.cpp @@ -360,7 +360,8 @@ otError NcpBase::HandlePropertySet_SPINEL_PROP_STREAM_RAW(uint8_t aHeader) memcpy(frame->mPsdu, frameBuffer, frame->mLength); // TODO: This should be later added in the STREAM_RAW argument to allow user to directly specify it. - frame->mInfo.mTxInfo.mMaxTxAttempts = OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_DIRECT; + frame->mInfo.mTxInfo.mMaxCsmaBackoffs = OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT; + frame->mInfo.mTxInfo.mMaxFrameRetries = OPENTHREAD_CONFIG_MAC_MAX_FRAME_RETRIES_DIRECT; // Pass frame to the radio layer. Note, this fails if we // haven't enabled raw stream or are already transmitting.