From c9066b650695494917a87cc9e560a30dc397d3b8 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Thu, 13 Jan 2022 18:59:30 +0100 Subject: [PATCH] [bbr] add `bbr skipseqnuminc` command for reference device (#7283) Add a command to allow skipping the increase of Sequence Number when recovering the BBR Dataset from Network Data. --- include/openthread/backbone_router_ftd.h | 13 +++++++++++++ include/openthread/instance.h | 2 +- src/cli/README.md | 11 +++++++++++ src/cli/cli.cpp | 8 +++++++- src/core/api/backbone_router_ftd_api.cpp | 6 ++++++ src/core/backbone_router/bbr_local.cpp | 19 +++++++++++++++++++ src/core/backbone_router/bbr_local.hpp | 18 ++++++++++++++++++ tools/harness-thci/OpenThread.py | 13 +++++++++++++ 8 files changed, 88 insertions(+), 2 deletions(-) diff --git a/include/openthread/backbone_router_ftd.h b/include/openthread/backbone_router_ftd.h index 017c71b1f..746d59927 100644 --- a/include/openthread/backbone_router_ftd.h +++ b/include/openthread/backbone_router_ftd.h @@ -273,6 +273,19 @@ void otBackboneRouterMulticastListenerClear(otInstance *aInstance); */ otError otBackboneRouterMulticastListenerAdd(otInstance *aInstance, const otIp6Address *aAddress, uint32_t aTimeout); +/** + * This method configures the ability to increase or not the BBR Dataset Sequence Number when a + * BBR recovers its BBR Dataset from the Leader's Network Data. + * + * Note: available only when `OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE` is enabled. + * Only used for certification. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aSkip Whether to skip the increase of Sequence Number or not. + * + */ +void otBackboneRouterConfigSkipSeqNumIncrease(otInstance *aInstance, bool aSkip); + #define OT_BACKBONE_ROUTER_MULTICAST_LISTENER_ITERATOR_INIT \ 0 ///< Initializer for otBackboneRouterMulticastListenerIterator diff --git a/include/openthread/instance.h b/include/openthread/instance.h index c9aaf0b4b..175c65a87 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (182) +#define OPENTHREAD_API_VERSION (183) /** * @addtogroup api-instance diff --git a/src/cli/README.md b/src/cli/README.md index 82a0401ad..d86506f8c 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -324,6 +324,17 @@ Set jitter (in seconds) for Backbone Router registration for Thread 1.2 FTD. Done ``` +### bbr skipseqnuminc + +Skip increase of Sequence Number when updating the local BBR Dataset from the Network Data. + +Only for testing/reference device. + +```bash +> bbr skipseqnuminc +Done +``` + ### ba Show current Border Agent information. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index c4cdebebe..f0934919c 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -564,7 +564,13 @@ otError Interpreter::ProcessBackboneRouter(Arg aArgs[]) } #endif } - +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + else if (aArgs[0] == "skipseqnuminc") + { + otBackboneRouterConfigSkipSeqNumIncrease(GetInstancePtr(), true); + ExitNow(); + } +#endif SuccessOrExit(error = ProcessBackboneRouterLocal(aArgs)); } diff --git a/src/core/api/backbone_router_ftd_api.cpp b/src/core/api/backbone_router_ftd_api.cpp index 16380be1c..b7e38e360 100644 --- a/src/core/api/backbone_router_ftd_api.cpp +++ b/src/core/api/backbone_router_ftd_api.cpp @@ -176,6 +176,12 @@ otError otBackboneRouterMulticastListenerAdd(otInstance *aInstance, const otIp6A TimerMilli::GetNow() + aTimeout); } #endif // OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE + +void otBackboneRouterConfigSkipSeqNumIncrease(otInstance *aInstance, bool aSkip) +{ + AsCoreType(aInstance).Get().ConfigSkipSeqNumIncrease(aSkip); +} + #endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE #endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE diff --git a/src/core/backbone_router/bbr_local.cpp b/src/core/backbone_router/bbr_local.cpp index fffa56506..9952583b2 100644 --- a/src/core/backbone_router/bbr_local.cpp +++ b/src/core/backbone_router/bbr_local.cpp @@ -57,6 +57,9 @@ Local::Local(Instance &aInstance) , mIsServiceAdded(false) , mDomainPrefixCallback(nullptr) , mDomainPrefixCallbackContext(nullptr) +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + , mSkipSeqNumIncrease(false) +#endif { mDomainPrefixConfig.GetPrefix().SetLength(0); @@ -270,6 +273,15 @@ void Local::HandleBackboneRouterPrimaryUpdate(Leader::State aState, const Backbo mSequenceNumber = aConfig.mSequenceNumber + 1; mReregistrationDelay = aConfig.mReregistrationDelay; mMlrTimeout = aConfig.mMlrTimeout; + +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + if (mSkipSeqNumIncrease) + { + // BBR-TC-02 forces Sequence Number for the reference device with raw UDP API + mSequenceNumber = aConfig.mSequenceNumber; + } +#endif + Get().Signal(kEventThreadBackboneRouterLocalChanged); if (AddService(true /* Force registration to refresh and restore Primary state */) == kErrorNone) { @@ -444,6 +456,13 @@ void Local::SetDomainPrefixCallback(otBackboneRouterDomainPrefixCallback aCallba mDomainPrefixCallbackContext = aContext; } +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE +void Local::ConfigSkipSeqNumIncrease(bool aSkip) +{ + mSkipSeqNumIncrease = aSkip; +} +#endif + } // namespace BackboneRouter } // namespace ot diff --git a/src/core/backbone_router/bbr_local.hpp b/src/core/backbone_router/bbr_local.hpp index 95879694d..f4878eab1 100644 --- a/src/core/backbone_router/bbr_local.hpp +++ b/src/core/backbone_router/bbr_local.hpp @@ -254,6 +254,20 @@ public: */ void SetDomainPrefixCallback(otBackboneRouterDomainPrefixCallback aCallback, void *aContext); +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + /** + * This method configures the ability to increase or not the BBR Dataset Sequence Number when a + * BBR recovers its BBR Dataset from the Leader's Network Data. + * + * Note: available only when `OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE` is enabled. + * Only used for certification. + * + * @param[in] aSkip Whether to skip the increase of Sequence Number or not. + * + */ + void ConfigSkipSeqNumIncrease(bool aSkip); +#endif + private: void SetState(BackboneRouterState aState); void RemoveService(void); @@ -285,6 +299,10 @@ private: Ip6::Address mAllDomainBackboneRouters; otBackboneRouterDomainPrefixCallback mDomainPrefixCallback; void * mDomainPrefixCallbackContext; + +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + bool mSkipSeqNumIncrease : 1; +#endif }; } // namespace BackboneRouter diff --git a/tools/harness-thci/OpenThread.py b/tools/harness-thci/OpenThread.py index 335a79f14..5d425fa49 100644 --- a/tools/harness-thci/OpenThread.py +++ b/tools/harness-thci/OpenThread.py @@ -551,6 +551,17 @@ class OpenThreadTHCI(object): except Exception as e: ModuleHelper.WriteIntoDebugLogger('__setAddressFilterMode() Error: ' + str(e)) + def __skipSeqNoIncrease(self): + """skip sequence number increase when recovering BBR Dataset from Network Data + + Returns: + True: successful to set the behavior. + False: fail to set the behavior. + """ + print('call __skipSeqNoIncrease()') + cmd = 'bbr skipseqnuminc' + return self.__executeCommand(cmd)[-1] == 'Done' + def __startOpenThread(self): """start OpenThread stack @@ -1231,6 +1242,8 @@ class OpenThreadTHCI(object): if self.AutoDUTEnable is False: # set ROUTER_DOWNGRADE_THRESHOLD self.__setRouterDowngradeThreshold(33) + # skip increase of Sequence Number for BBR-TC-02 + self.__skipSeqNoIncrease() elif eRoleId == Thread_Device_Role.SED: print('join as sleepy end device') mode = '-'