From 60f0412cf3279846bb6e9f4658498063b29e9730 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 15 Jul 2019 13:51:27 -0700 Subject: [PATCH] [config] parent search (#4020) --- include/openthread/thread.h | 2 +- src/core/Makefile.am | 1 + .../config/openthread-core-default-config.h | 58 ----------- src/core/config/parent_search.h | 96 +++++++++++++++++++ src/core/openthread-core-config.h | 1 + src/core/thread/mle.cpp | 12 +-- src/core/thread/mle.hpp | 4 +- 7 files changed, 107 insertions(+), 67 deletions(-) create mode 100644 src/core/config/parent_search.h diff --git a/include/openthread/thread.h b/include/openthread/thread.h index d97ec0990..4aa200aae 100644 --- a/include/openthread/thread.h +++ b/include/openthread/thread.h @@ -177,7 +177,7 @@ typedef struct otMleCounters * * A parent change can happen if device detaches from its current parent and attaches to a different one, or even * while device is attached when the periodic parent search feature is enabled (please see option - * OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH). + * OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE). * */ uint16_t mParentChanges; diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 892274199..f77221539 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -338,6 +338,7 @@ HEADERS_COMMON = \ config/mle.h \ config/openthread-core-config-check.h \ config/openthread-core-default-config.h \ + config/parent_search.h \ crypto/aes_ccm.hpp \ crypto/aes_ecb.hpp \ crypto/ecdsa.hpp \ diff --git a/src/core/config/openthread-core-default-config.h b/src/core/config/openthread-core-default-config.h index 51ac731e5..15c273555 100644 --- a/src/core/config/openthread-core-default-config.h +++ b/src/core/config/openthread-core-default-config.h @@ -372,64 +372,6 @@ #define OPENTHREAD_CONFIG_DTLS_APPLICATION_DATA_MAX_LENGTH 1400 #endif -/** - * @def OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH - * - * Define as 1 to enable periodic parent search feature. - * - * When this feature is enabled an end-device/child (while staying attached) will periodically search for a possible - * better parent and will switch parent if a better one is found. - * - * The child will periodically check the average RSS value for the current parent, and only if it is below a specific - * threshold, a parent search is performed. The `OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL` specifies the - * check interval (in seconds) and `OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD` gives the RSS threshold. - * - * Since the parent search process can be power consuming (child needs to stays in RX mode to collect parent response) - * and to limit its impact on battery-powered devices, after a parent search is triggered, the child will not trigger - * another one before a specified backoff interval specified by `OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL`. - * - */ -#ifndef OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH -#define OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH 0 -#endif - -/** - * @def OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL - * - * Specifies the interval in seconds for a child to check the trigger condition to perform a parent search. - * - * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH`). - * - */ -#ifndef OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL -#define OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL (9 * 60) -#endif - -/** - * @def OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL - * - * Specifies the backoff interval in seconds for a child to not perform a parent search after triggering one. - * - * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH`). - * - * - */ -#ifndef OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL -#define OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL (10 * 60 * 60) -#endif - -/** - * @def OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD - * - * Specifies the RSS threshold used to trigger a parent search. - * - * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH`). - * - */ -#ifndef OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD -#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD -65 -#endif - /** * @def OPENTHREAD_CONFIG_ENABLE_DEBUG_UART * diff --git a/src/core/config/parent_search.h b/src/core/config/parent_search.h new file mode 100644 index 000000000..9c78bc026 --- /dev/null +++ b/src/core/config/parent_search.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2019, 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 + * This file includes compile-time configurations for Parent Search. + * + */ + +#ifndef CONFIG_PARENT_SEARCH_H_ +#define CONFIG_PARENT_SEARCH_H_ + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE + * + * Define as 1 to enable periodic parent search feature. + * + * When this feature is enabled an end-device/child (while staying attached) will periodically search for a possible + * better parent and will switch parent if a better one is found. + * + * The child will periodically check the average RSS value for the current parent, and only if it is below a specific + * threshold, a parent search is performed. The `OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL` specifies the + * check interval (in seconds) and `OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD` gives the RSS threshold. + * + * Since the parent search process can be power consuming (child needs to stays in RX mode to collect parent response) + * and to limit its impact on battery-powered devices, after a parent search is triggered, the child will not trigger + * another one before a specified backoff interval specified by `OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL`. + * + */ +#ifndef OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE +#define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL + * + * Specifies the interval in seconds for a child to check the trigger condition to perform a parent search. + * + * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE`). + * + */ +#ifndef OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL +#define OPENTHREAD_CONFIG_PARENT_SEARCH_CHECK_INTERVAL (9 * 60) +#endif + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL + * + * Specifies the backoff interval in seconds for a child to not perform a parent search after triggering one. + * + * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE`). + * + * + */ +#ifndef OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL +#define OPENTHREAD_CONFIG_PARENT_SEARCH_BACKOFF_INTERVAL (10 * 60 * 60) +#endif + +/** + * @def OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD + * + * Specifies the RSS threshold used to trigger a parent search. + * + * Applicable only if periodic parent search feature is enabled (see `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE`). + * + */ +#ifndef OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD +#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD -65 +#endif + +#endif // CONFIG_PARENT_SEARCH_H_ diff --git a/src/core/openthread-core-config.h b/src/core/openthread-core-config.h index adc478500..3651a63b2 100644 --- a/src/core/openthread-core-config.h +++ b/src/core/openthread-core-config.h @@ -62,6 +62,7 @@ #include "config/logging.h" #include "config/mac.h" #include "config/mle.h" +#include "config/parent_search.h" #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || \ OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || OPENTHREAD_CONFIG_JOINER_ENABLE diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 199b58c69..d1e714d14 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -98,7 +98,7 @@ Mle::Mle(Instance &aInstance) #if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH , mPreviousParentRloc(Mac::kShortAddrInvalid) #endif -#if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE , mParentSearchIsInBackoff(false) , mParentSearchBackoffWasCanceled(false) , mParentSearchRecentlyDetached(false) @@ -204,7 +204,7 @@ Mle::Mle(Instance &aInstance) // `SetMeshLocalPrefix()` also adds the Mesh-Local EID and subscribes // to the Link- and Realm-Local All Thread Nodes multicast addresses. -#if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE StartParentSearchTimer(); #endif } @@ -595,7 +595,7 @@ otError Mle::BecomeDetached(void) Get().HandleDetach(); } -#if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE mParentSearchRecentlyDetached = true; #endif @@ -769,7 +769,7 @@ void Mle::SetStateChild(uint16_t aRloc16) // send announce after attached if needed InformPreviousChannel(); -#if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE UpdateParentSearchState(); #endif @@ -4030,7 +4030,7 @@ exit: } #endif // OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH -#if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE void Mle::HandleParentSearchTimer(Timer &aTimer) { aTimer.GetOwner().HandleParentSearchTimer(); @@ -4135,7 +4135,7 @@ void Mle::UpdateParentSearchState(void) StartParentSearchTimer(); } } -#endif // OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#endif // OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE void Mle::LogMleMessage(const char *aLogString, const Ip6::Address &aAddress) const { diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 17cda7908..51a9f452b 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1741,7 +1741,7 @@ private: otError InformPreviousParent(void); #endif -#if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE static void HandleParentSearchTimer(Timer &aTimer); void HandleParentSearchTimer(void); void StartParentSearchTimer(void); @@ -1795,7 +1795,7 @@ private: uint16_t mPreviousParentRloc; #endif -#if OPENTHREAD_CONFIG_ENABLE_PERIODIC_PARENT_SEARCH +#if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE bool mParentSearchIsInBackoff : 1; bool mParentSearchBackoffWasCanceled : 1; bool mParentSearchRecentlyDetached : 1;