From 9137b82dbe70187407151069bec587e5d63556c3 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Sat, 16 May 2026 12:21:39 -0700 Subject: [PATCH] [bbr] handle role changes directly in `BackboneRouter::Local` (#13112) This commit updates `BackboneRouter::Local` to receive role change events directly from the `Notifier`. Previously, `Bbr::Local` was indirectly relying on `BackboneRouter::Leader` to emit events even when the PBBR configuration had not changed (e.g., during role transitions). The previous design was fragile and created an unnecessary dependency. `Bbr::Local` now independently tracks role changes to ensure it correctly evaluates its own status (e.g., deciding whether to register as the Primary BBR). --- src/core/backbone_router/bbr_local.cpp | 12 ++++++++++++ src/core/backbone_router/bbr_local.hpp | 4 ++++ src/core/common/notifier.cpp | 3 +++ 3 files changed, 19 insertions(+) diff --git a/src/core/backbone_router/bbr_local.cpp b/src/core/backbone_router/bbr_local.cpp index 3b73c5f5b..e341a4fd5 100644 --- a/src/core/backbone_router/bbr_local.cpp +++ b/src/core/backbone_router/bbr_local.cpp @@ -240,7 +240,19 @@ exit: void Local::HandleBackboneRouterPrimaryUpdate(PrimaryEvent aEvent) { OT_UNUSED_VARIABLE(aEvent); + UpdateState(); +} +void Local::HandleNotifierEvents(Events aEvents) +{ + if (aEvents.Contains(kEventThreadRoleChanged)) + { + UpdateState(); + } +} + +void Local::UpdateState(void) +{ VerifyOrExit(IsEnabled() && Get().IsAttached()); // Wait some jitter before trying to Register. diff --git a/src/core/backbone_router/bbr_local.hpp b/src/core/backbone_router/bbr_local.hpp index bcef1e4f4..f31dc43e3 100644 --- a/src/core/backbone_router/bbr_local.hpp +++ b/src/core/backbone_router/bbr_local.hpp @@ -59,6 +59,7 @@ #include "common/locator.hpp" #include "common/log.hpp" #include "common/non_copyable.hpp" +#include "common/notifier.hpp" #include "common/time_ticker.hpp" #include "net/netif.hpp" #include "thread/network_data.hpp" @@ -73,6 +74,7 @@ namespace BackboneRouter { class Local : public InstanceLocator, private NonCopyable { friend class ot::TimeTicker; + friend class ot::Notifier; public: typedef otBackboneRouterDomainPrefixCallback DomainPrefixCallback; ///< Domain Prefix callback. @@ -265,6 +267,8 @@ private: }; void SetState(State aState); + void HandleNotifierEvents(Events aEvents); + void UpdateState(void); void RemoveService(void); void HandleTimeTick(void); void AddDomainPrefixToNetworkData(void); diff --git a/src/core/common/notifier.cpp b/src/core/common/notifier.cpp index ab16f76e4..e5f945be3 100644 --- a/src/core/common/notifier.cpp +++ b/src/core/common/notifier.cpp @@ -104,6 +104,9 @@ void Notifier::EmitEvents(void) #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) Get().HandleNotifierEvents(events); #endif +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE + Get().HandleNotifierEvents(events); +#endif #if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE Get().HandleNotifierEvents(events); #endif