Skip to content

Commit 9137b82

Browse files
abtinkjwhui
authored andcommitted
[bbr] handle role changes directly in BackboneRouter::Local (openthread#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).
1 parent c5efa40 commit 9137b82

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/core/backbone_router/bbr_local.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,19 @@ void Local::SetState(State aState)
240240
void Local::HandleBackboneRouterPrimaryUpdate(PrimaryEvent aEvent)
241241
{
242242
OT_UNUSED_VARIABLE(aEvent);
243+
UpdateState();
244+
}
243245

246+
void Local::HandleNotifierEvents(Events aEvents)
247+
{
248+
if (aEvents.Contains(kEventThreadRoleChanged))
249+
{
250+
UpdateState();
251+
}
252+
}
253+
254+
void Local::UpdateState(void)
255+
{
244256
VerifyOrExit(IsEnabled() && Get<Mle::Mle>().IsAttached());
245257

246258
// Wait some jitter before trying to Register.

src/core/backbone_router/bbr_local.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "common/locator.hpp"
6060
#include "common/log.hpp"
6161
#include "common/non_copyable.hpp"
62+
#include "common/notifier.hpp"
6263
#include "common/time_ticker.hpp"
6364
#include "net/netif.hpp"
6465
#include "thread/network_data.hpp"
@@ -73,6 +74,7 @@ namespace BackboneRouter {
7374
class Local : public InstanceLocator, private NonCopyable
7475
{
7576
friend class ot::TimeTicker;
77+
friend class ot::Notifier;
7678

7779
public:
7880
typedef otBackboneRouterDomainPrefixCallback DomainPrefixCallback; ///< Domain Prefix callback.
@@ -265,6 +267,8 @@ class Local : public InstanceLocator, private NonCopyable
265267
};
266268

267269
void SetState(State aState);
270+
void HandleNotifierEvents(Events aEvents);
271+
void UpdateState(void);
268272
void RemoveService(void);
269273
void HandleTimeTick(void);
270274
void AddDomainPrefixToNetworkData(void);

src/core/common/notifier.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ void Notifier::EmitEvents(void)
104104
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
105105
Get<BackboneRouter::Leader>().HandleNotifierEvents(events);
106106
#endif
107+
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
108+
Get<BackboneRouter::Local>().HandleNotifierEvents(events);
109+
#endif
107110
#if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
108111
Get<Dhcp6::Server>().HandleNotifierEvents(events);
109112
#endif

0 commit comments

Comments
 (0)