mirror of
https://github.com/espressif/openthread.git
synced 2026-08-12 13:47:47 +00:00
[backbone-router] use TimeTicker directly to delay registration (#9483)
This commit update `BackboneRouter::Local` to be a `TimeTicker` receiver directly instead of using the `MleRouter for this. The `TimeTicker` callback is used to delay registration by counting down `mRegistrationTimeout`.
This commit is contained in:
@@ -54,6 +54,7 @@ Local::Local(Instance &aInstance)
|
||||
, mState(kStateDisabled)
|
||||
, mMlrTimeout(kDefaultMlrTimeout)
|
||||
, mReregistrationDelay(kDefaultRegistrationDelay)
|
||||
, mRegistrationTimeout(0)
|
||||
, mSequenceNumber(Random::NonCrypto::GetUint8() % 127)
|
||||
, mRegistrationJitter(kDefaultRegistrationJitter)
|
||||
, mIsServiceAdded(false)
|
||||
@@ -252,16 +253,15 @@ void Local::HandleBackboneRouterPrimaryUpdate(Leader::State aState, const Config
|
||||
// Wait some jitter before trying to Register.
|
||||
if (aConfig.mServer16 == Mac::kShortAddrInvalid)
|
||||
{
|
||||
uint8_t delay = 1;
|
||||
mRegistrationTimeout = 1;
|
||||
|
||||
if (!Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
delay += Random::NonCrypto::GetUint8InRange(0, mRegistrationJitter < 255 ? mRegistrationJitter + 1
|
||||
: mRegistrationJitter);
|
||||
mRegistrationTimeout +=
|
||||
Random::NonCrypto::GetUint16InRange(0, static_cast<uint16_t>(mRegistrationJitter) + 1);
|
||||
}
|
||||
|
||||
// Here uses the timer resource in Mle.
|
||||
Get<Mle::MleRouter>().SetBackboneRouterRegistrationDelay(delay);
|
||||
Get<TimeTicker>().RegisterReceiver(TimeTicker::kBbrLocal);
|
||||
}
|
||||
else if (aConfig.mServer16 != Get<Mle::MleRouter>().GetRloc16())
|
||||
{
|
||||
@@ -287,6 +287,29 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Local::HandleTimeTick(void)
|
||||
{
|
||||
// Delay registration when `GetRouterSelectionJitterTimeout()` is non-zero,
|
||||
// which indicates device may soon switch its role (e.g., REED to router).
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRouterSelectionJitterTimeout() == 0);
|
||||
|
||||
if (mRegistrationTimeout > 0)
|
||||
{
|
||||
mRegistrationTimeout--;
|
||||
|
||||
if (mRegistrationTimeout == 0)
|
||||
{
|
||||
IgnoreError(AddService(kDecideBasedOnState));
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
if (mRegistrationTimeout == 0)
|
||||
{
|
||||
Get<TimeTicker>().UnregisterReceiver(TimeTicker::kBbrLocal);
|
||||
}
|
||||
}
|
||||
|
||||
Error Local::GetDomainPrefix(NetworkData::OnMeshPrefixConfig &aConfig)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "common/locator.hpp"
|
||||
#include "common/log.hpp"
|
||||
#include "common/non_copyable.hpp"
|
||||
#include "common/time_ticker.hpp"
|
||||
#include "net/netif.hpp"
|
||||
#include "thread/network_data.hpp"
|
||||
|
||||
@@ -72,6 +73,8 @@ namespace BackboneRouter {
|
||||
*/
|
||||
class Local : public InstanceLocator, private NonCopyable
|
||||
{
|
||||
friend class ot::TimeTicker;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Represents Backbone Router state.
|
||||
@@ -278,6 +281,7 @@ public:
|
||||
private:
|
||||
void SetState(State aState);
|
||||
void RemoveService(void);
|
||||
void HandleTimeTick(void);
|
||||
void AddDomainPrefixToNetworkData(void);
|
||||
void RemoveDomainPrefixFromNetworkData(void);
|
||||
void SequenceNumberIncrease(void);
|
||||
@@ -292,6 +296,7 @@ private:
|
||||
State mState;
|
||||
uint32_t mMlrTimeout;
|
||||
uint16_t mReregistrationDelay;
|
||||
uint16_t mRegistrationTimeout;
|
||||
uint8_t mSequenceNumber;
|
||||
uint8_t mRegistrationJitter;
|
||||
|
||||
|
||||
@@ -127,6 +127,13 @@ void TimeTicker::HandleTimer(void)
|
||||
{
|
||||
Get<Ip6::Mpl>().HandleTimeTick();
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
if (mReceivers & Mask(kBbrLocal))
|
||||
{
|
||||
Get<BackboneRouter::Local>().HandleTimeTick();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -73,6 +73,7 @@ public:
|
||||
kMlrManager, ///< `MlrManager`
|
||||
kNetworkDataNotifier, ///< `NetworkData::Notifier`
|
||||
kIp6Mpl, ///< `Ip6::Mpl`
|
||||
kBbrLocal, ///< `BackboneRouter::Local`
|
||||
|
||||
kNumReceivers, ///< Number of receivers.
|
||||
};
|
||||
|
||||
@@ -86,9 +86,6 @@ MleRouter::MleRouter(Instance &aInstance)
|
||||
, mRouterSelectionJitterTimeout(0)
|
||||
, mChildRouterLinks(kChildRouterLinks)
|
||||
, mParentPriority(kParentPriorityUnspecified)
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
, mBackboneRouterRegistrationDelay(0)
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
, mMaxChildIpAddresses(0)
|
||||
#endif
|
||||
@@ -1541,19 +1538,6 @@ void MleRouter::HandleTimeTick(void)
|
||||
routerStateUpdate = true;
|
||||
}
|
||||
}
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
// Delay register only when `mRouterSelectionJitterTimeout` is 0,
|
||||
// that is, when the device has decided to stay as REED or Router.
|
||||
else if (mBackboneRouterRegistrationDelay > 0)
|
||||
{
|
||||
mBackboneRouterRegistrationDelay--;
|
||||
|
||||
if (mBackboneRouterRegistrationDelay == 0)
|
||||
{
|
||||
IgnoreError(Get<BackboneRouter::Local>().AddService(BackboneRouter::Local::kDecideBasedOnState));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
|
||||
@@ -522,16 +522,6 @@ public:
|
||||
Error SendTimeSync(void);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
/**
|
||||
* Sets the delay before registering Backbone Router service.
|
||||
*
|
||||
* @param[in] aDelay The delay before registering Backbone Router service.
|
||||
*
|
||||
*/
|
||||
void SetBackboneRouterRegistrationDelay(uint8_t aDelay) { mBackboneRouterRegistrationDelay = aDelay; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Gets the maximum number of IP addresses that each MTD child may register with this device as parent.
|
||||
*
|
||||
@@ -743,9 +733,6 @@ private:
|
||||
uint8_t mChildRouterLinks;
|
||||
|
||||
int8_t mParentPriority; ///< The assigned parent priority value, -2 means not assigned.
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
uint8_t mBackboneRouterRegistrationDelay; ///< Delay before registering Backbone Router service.
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
uint8_t mMaxChildIpAddresses;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user