[notifier] streamline event delivery to core modules (#11546)

This commit updates the `Notifier` to directly signal events to
`BackboneRouter::Leader`, `Dhcp6::Server`, `Dhcp6::Client`, and
`NeighborDiscovery::Agent`. These classes were previously notified
indirectly through `Mle::HandleNotifierEvent()`.
This commit is contained in:
Abtin Keshavarzian
2025-05-30 14:04:33 -07:00
committed by GitHub
parent cbe3654ce7
commit 2bc5eec091
10 changed files with 65 additions and 41 deletions
+6 -3
View File
@@ -143,10 +143,13 @@ const char *Leader::DomainPrefixEventToString(DomainPrefixEvent aEvent)
#endif // OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
void Leader::Update(void)
void Leader::HandleNotifierEvents(Events aEvents)
{
UpdateBackboneRouterPrimary();
UpdateDomainPrefixConfig();
if (aEvents.Contains(kEventThreadNetdataChanged))
{
UpdateBackboneRouterPrimary();
UpdateDomainPrefixConfig();
}
}
void Leader::UpdateBackboneRouterPrimary(void)
+4 -5
View File
@@ -47,6 +47,7 @@
#include "common/locator.hpp"
#include "common/log.hpp"
#include "common/non_copyable.hpp"
#include "common/notifier.hpp"
#include "net/ip6_address.hpp"
namespace ot {
@@ -83,6 +84,8 @@ enum DomainPrefixEvent : uint8_t
*/
class Leader : public InstanceLocator, private NonCopyable
{
friend class ot::Notifier;
public:
// Primary Backbone Router Service state or state change.
enum State : uint8_t
@@ -108,11 +111,6 @@ public:
*/
void Reset(void);
/**
* Updates the cached Primary Backbone Router if any when new network data is available.
*/
void Update(void);
/**
* Gets the Primary Backbone Router in the Thread Network.
*
@@ -177,6 +175,7 @@ public:
bool IsDomainUnicast(const Ip6::Address &aAddress) const;
private:
void HandleNotifierEvents(Events aEvents);
void UpdateBackboneRouterPrimary(void);
void UpdateDomainPrefixConfig(void);
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
+12
View File
@@ -98,6 +98,18 @@ void Notifier::EmitEvents(void)
// Emit events to core internal modules
Get<Mle::Mle>().HandleNotifierEvents(events);
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
Get<BackboneRouter::Leader>().HandleNotifierEvents(events);
#endif
#if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
Get<Dhcp6::Server>().HandleNotifierEvents(events);
#endif
#if OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE
Get<NeighborDiscovery::Agent>().HandleNotifierEvents(events);
#endif
#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
Get<Dhcp6::Client>().HandleNotifierEvents(events);
#endif
Get<EnergyScanServer>().HandleNotifierEvents(events);
#if OPENTHREAD_FTD
Get<MeshCoP::JoinerRouter>().HandleNotifierEvents(events);
+8
View File
@@ -52,6 +52,14 @@ Client::Client(Instance &aInstance)
ClearAllBytes(mIdentityAssociations);
}
void Client::HandleNotifierEvents(Events aEvents)
{
if (aEvents.Contains(kEventThreadNetdataChanged))
{
UpdateAddresses();
}
}
void Client::UpdateAddresses(void)
{
bool found = false;
+6 -5
View File
@@ -41,6 +41,7 @@
#include "common/locator.hpp"
#include "common/message.hpp"
#include "common/non_copyable.hpp"
#include "common/notifier.hpp"
#include "common/timer.hpp"
#include "common/trickle_timer.hpp"
#include "mac/mac.hpp"
@@ -67,6 +68,8 @@ namespace Dhcp6 {
*/
class Client : public InstanceLocator, private NonCopyable
{
friend class ot::Notifier;
public:
/**
* Initializes the object.
@@ -75,11 +78,6 @@ public:
*/
explicit Client(Instance &aInstance);
/**
* Update addresses that shall be automatically created using DHCP.
*/
void UpdateAddresses(void);
private:
static constexpr uint16_t kNumPrefixes = OPENTHREAD_CONFIG_DHCP6_CLIENT_NUM_PREFIXES;
static constexpr uint32_t kTrickleTimerImin = 1;
@@ -126,6 +124,9 @@ private:
Error ProcessStatusCodeOption(Message &aMessage, uint16_t aOffset);
Error ProcessIaAddressOption(Message &aMessage, uint16_t aOffset);
void HandleNotifierEvents(Events aEvents);
void UpdateAddresses(void);
static void HandleTrickleTimer(TrickleTimer &aTrickleTimer);
void HandleTrickleTimer(void);
+9 -3
View File
@@ -51,7 +51,15 @@ Server::Server(Instance &aInstance)
ClearAllBytes(mPrefixAgents);
}
Error Server::UpdateService(void)
void Server::HandleNotifierEvents(Events aEvents)
{
if (aEvents.Contains(kEventThreadNetdataChanged))
{
UpdateService();
}
}
void Server::UpdateService(void)
{
Error error = kErrorNone;
uint16_t rloc16 = Get<Mle::Mle>().GetRloc16();
@@ -122,8 +130,6 @@ Error Server::UpdateService(void)
{
Stop();
}
return error;
}
void Server::Start(void)
+6 -5
View File
@@ -40,6 +40,7 @@
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "common/notifier.hpp"
#include "mac/mac.hpp"
#include "mac/mac_types.hpp"
#include "net/dhcp6.hpp"
@@ -64,6 +65,8 @@ namespace Dhcp6 {
class Server : public InstanceLocator, private NonCopyable
{
friend class ot::Notifier;
public:
/**
* Initializes the object.
@@ -72,11 +75,6 @@ public:
*/
explicit Server(Instance &aInstance);
/**
* Updates DHCP Agents and DHCP ALOCs.
*/
Error UpdateService(void);
private:
class PrefixAgent
{
@@ -165,6 +163,9 @@ private:
static constexpr uint16_t kNumPrefixes = OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES;
void HandleNotifierEvents(Events aEvents);
void UpdateService(void);
void Start(void);
void Stop(void);
+8
View File
@@ -40,6 +40,14 @@
namespace ot {
namespace NeighborDiscovery {
void Agent::HandleNotifierEvents(Events aEvents)
{
if (aEvents.Contains(kEventThreadNetdataChanged))
{
UpdateService();
}
}
void Agent::UpdateService(void)
{
Error error;
+6 -5
View File
@@ -40,6 +40,7 @@
#include "common/locator.hpp"
#include "common/non_copyable.hpp"
#include "common/notifier.hpp"
#include "net/netif.hpp"
namespace ot {
@@ -47,6 +48,8 @@ namespace NeighborDiscovery {
class Agent : public InstanceLocator, private NonCopyable
{
friend class ot::Notifier;
public:
/**
* Initializes the object.
@@ -59,15 +62,13 @@ public:
FreeAloc();
}
/**
* Updates the Neighbor Discovery Agents using current Thread Network Data.
*/
void UpdateService(void);
private:
void FreeAloc(void) { mAloc.mNext = &mAloc; }
bool IsAlocInUse(void) const { return mAloc.mNext != &mAloc; }
void HandleNotifierEvents(Events aEvents);
void UpdateService(void);
Ip6::Netif::UnicastAddress mAloc;
};
-15
View File
@@ -1222,24 +1222,9 @@ void Mle::HandleNotifierEvents(Events aEvents)
}
}
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
Get<BackboneRouter::Leader>().Update();
#endif
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
UpdateServiceAlocs();
#endif
#if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
IgnoreError(Get<Dhcp6::Server>().UpdateService());
#endif
#if OPENTHREAD_CONFIG_NEIGHBOR_DISCOVERY_AGENT_ENABLE
Get<NeighborDiscovery::Agent>().UpdateService();
#endif
#if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
Get<Dhcp6::Client>().UpdateAddresses();
#endif
}
if (aEvents.ContainsAny(kEventThreadRoleChanged | kEventThreadKeySeqCounterChanged))