From 6a0acacaf742665bee1bcc36197b8f7157a971d6 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 29 Jan 2021 01:24:11 -0800 Subject: [PATCH] [bbr-local] simplify 'Add/RemoveService()' (#6130) This commit updates `AddServcie()` and `RemoveService()` in `BackboneRouter::Local` class such that the methods themselves after adding/removing the service entry in local network data inform `NetworkData::Notifier` to send the update to leader. This helps simplify their use. --- src/core/api/backbone_router_ftd_api.cpp | 9 +-------- src/core/backbone_router/bbr_local.cpp | 19 ++++++------------- src/core/backbone_router/bbr_local.hpp | 8 ++++---- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/core/api/backbone_router_ftd_api.cpp b/src/core/api/backbone_router_ftd_api.cpp index 82bd37654..79ccdf500 100644 --- a/src/core/api/backbone_router_ftd_api.cpp +++ b/src/core/api/backbone_router_ftd_api.cpp @@ -75,16 +75,9 @@ otError otBackboneRouterSetConfig(otInstance *aInstance, const otBackboneRouterC otError otBackboneRouterRegister(otInstance *aInstance) { - otError error = OT_ERROR_NONE; - Instance &instance = *static_cast(aInstance); - SuccessOrExit(error = instance.Get().AddService(true /* Force registration */)); - - instance.Get().HandleServerDataUpdated(); - -exit: - return error; + return instance.Get().AddService(true /* Force registration */); } uint8_t otBackboneRouterGetRegistrationJitter(otInstance *aInstance) diff --git a/src/core/backbone_router/bbr_local.cpp b/src/core/backbone_router/bbr_local.cpp index 19a3a2f98..ca306aff4 100644 --- a/src/core/backbone_router/bbr_local.cpp +++ b/src/core/backbone_router/bbr_local.cpp @@ -92,12 +92,10 @@ void Local::SetEnabled(bool aEnable) else { RemoveDomainPrefixFromNetworkData(); - IgnoreError(RemoveService()); + RemoveService(); SetState(OT_BACKBONE_ROUTER_STATE_DISABLED); } - Get().HandleServerDataUpdated(); - exit: return; } @@ -106,10 +104,7 @@ void Local::Reset(void) { VerifyOrExit(mState != OT_BACKBONE_ROUTER_STATE_DISABLED); - if (RemoveService() == OT_ERROR_NONE) - { - Get().HandleServerDataUpdated(); - } + RemoveService(); if (mState == OT_BACKBONE_ROUTER_STATE_PRIMARY) { @@ -166,10 +161,7 @@ otError Local::SetConfig(const BackboneRouterConfig &aConfig) { Get().Signal(kEventThreadBackboneRouterLocalChanged); - if (AddService() == OT_ERROR_NONE) - { - Get().HandleServerDataUpdated(); - } + IgnoreError(AddService()); } exit: @@ -200,13 +192,14 @@ otError Local::AddService(bool aForce) reinterpret_cast(&serverData), sizeof(serverData))); mIsServiceAdded = true; + Get().HandleServerDataUpdated(); exit: LogBackboneRouterService("Add", error); return error; } -otError Local::RemoveService(void) +void Local::RemoveService(void) { otError error; uint8_t serviceData = NetworkData::ServiceTlv::kServiceDataBackboneRouter; @@ -215,10 +208,10 @@ otError Local::RemoveService(void) &serviceData, sizeof(serviceData))); mIsServiceAdded = false; + Get().HandleServerDataUpdated(); exit: LogBackboneRouterService("Remove", error); - return error; } void Local::SetState(BackboneRouterState aState) diff --git a/src/core/backbone_router/bbr_local.hpp b/src/core/backbone_router/bbr_local.hpp index 7d1b82853..e51e17ffa 100644 --- a/src/core/backbone_router/bbr_local.hpp +++ b/src/core/backbone_router/bbr_local.hpp @@ -239,10 +239,10 @@ public: void SetDomainPrefixCallback(otBackboneRouterDomainPrefixCallback aCallback, void *aContext); private: - void SetState(BackboneRouterState aState); - otError RemoveService(void); - void AddDomainPrefixToNetworkData(void); - void RemoveDomainPrefixFromNetworkData(void); + void SetState(BackboneRouterState aState); + void RemoveService(void); + void AddDomainPrefixToNetworkData(void); + void RemoveDomainPrefixFromNetworkData(void); #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_BBR == 1) void LogBackboneRouterService(const char *aAction, otError aError); void LogDomainPrefix(const char *aAction, otError aError);