From c79a9055289af53a08f59827dda9feba766fe39a Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 23 Jun 2017 11:58:08 -0700 Subject: [PATCH] [mesh-forwarder] Drop a message if all tx attempts fail for one of its fragments (#1933) Existing code already enables this behavior for indirect message transmissions. This commits adds support for direct transmission and also introduces `OPENTHREAD_CONFIG_DROP_MESSAGE_ON_FRAGMENT_TX_FAILURE` as a new configuration option to control this feature. If enabled OpenThread will drop a message (and not send any remaining fragments of the message) if all transmit attempts fail for a fragment of the message. For a direct transmission, a failure occurs after all MAC transmission attempts for a given fragment are unsuccessful. For an indirect transmission, a failure occurs after all data poll triggered transmission attempts for a given fragment fail. If this feature is disabled, OpenThread will attempt to send subsequent fragments, whether or not all transmission attempts fail for a given fragment. Default setting enables this behavior. --- src/core/openthread-core-default-config.h | 16 ++++++++++++++ src/core/thread/mesh_forwarder.cpp | 26 +++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index 667279994..496e8a003 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -149,6 +149,22 @@ #define OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_POLLS 4 #endif // OPENTHREAD_CONFIG_MAX_TX_ATTEMPTS_INDIRECT_POLLS +/** + * @def OPENTHREAD_CONFIG_DROP_MESSAGE_ON_FRAGMENT_TX_FAILURE + * + * Define as 1 for OpenThread to drop a message (and not send any remaining fragments of the message) if all transmit + * attempts fail for a fragment of the message. For a direct transmission, a failure occurs after all MAC transmission + * attempts for a given fragment are unsuccessful. For an indirect transmission, a failure occurs after all data poll + * triggered transmission attempts for a given fragment fail. + * + * If set to zero (disabled), OpenThread will attempt to send subsequent fragments, whether or not all transmission + * attempts fail for a given fragment. + * + */ +#ifndef OPENTHREAD_CONFIG_DROP_MESSAGE_ON_FRAGMENT_TX_FAILURE +#define OPENTHREAD_CONFIG_DROP_MESSAGE_ON_FRAGMENT_TX_FAILURE 1 +#endif // OPENTHREAD_CONFIG_DROP_MESSAGE_ON_FRAGMENT_TX_FAILURE + /** * @def OPENTHREAD_CONFIG_ATTACH_DATA_POLL_PERIOD * diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 2369f0b41..b8df4ce75 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -1491,13 +1491,12 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError) if (mSendMessage == child->GetIndirectMessage()) { - switch (aError) + if (aError == OT_ERROR_NONE) { - case OT_ERROR_NONE: child->ResetIndirectTxAttempts(); - break; - - default: + } + else + { child->IncrementIndirectTxAttempts(); if (child->GetIndirectTxAttempts() < kMaxPollTriggeredTxAttempts) @@ -1526,13 +1525,13 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError) child->ResetIndirectTxAttempts(); +#if OPENTHREAD_CONFIG_DROP_MESSAGE_ON_FRAGMENT_TX_FAILURE // We set the NextOffset to end of message, since there is no need to // send any remaining fragments in the message to the child, if all tx // attempts of current frame already failed. mMessageNextOffset = mSendMessage->GetLength(); - - break; +#endif } } @@ -1581,6 +1580,19 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, otError aError) if (mSendMessage->GetDirectTransmission()) { + +#if OPENTHREAD_CONFIG_DROP_MESSAGE_ON_FRAGMENT_TX_FAILURE + + if (aError != OT_ERROR_NONE) + { + // We set the NextOffset to end of message to avoid sending + // any remaining fragments in the message. + + mMessageNextOffset = mSendMessage->GetLength(); + } + +#endif + if (mMessageNextOffset < mSendMessage->GetLength()) { mSendMessage->SetOffset(mMessageNextOffset);