mirror of
https://github.com/espressif/openthread.git
synced 2026-09-01 23:09:53 +00:00
[bbr] (Un)Subscribe AllNetworkBBRs Multicast address (#4755)
This commit is contained in:
@@ -156,13 +156,13 @@ void Leader::Update(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Short Address of PBBR changes
|
||||
// Short Address of PBBR changes.
|
||||
state = kStateToTriggerRereg;
|
||||
}
|
||||
}
|
||||
else if (config.mServer16 == Mac::kShortAddrInvalid)
|
||||
{
|
||||
// If no primary all the time
|
||||
// If no Primary all the time.
|
||||
state = kStateNone;
|
||||
}
|
||||
else if (config.mSequenceNumber != mConfig.mSequenceNumber)
|
||||
|
||||
@@ -86,7 +86,7 @@ void Local::Reset(void)
|
||||
|
||||
if (mState == OT_BACKBONE_ROUTER_STATE_PRIMARY)
|
||||
{
|
||||
// Increase sequence number when changing from primary to secondary.
|
||||
// Increase sequence number when changing from Primary to Secondary.
|
||||
mSequenceNumber++;
|
||||
Get<Notifier>().Signal(OT_CHANGED_THREAD_BACKBONE_ROUTER_LOCAL);
|
||||
SetState(OT_BACKBONE_ROUTER_STATE_SECONDARY);
|
||||
|
||||
@@ -120,14 +120,23 @@ public:
|
||||
otError AddService(bool aForce = false);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the Backbone Router is primary.
|
||||
* This method indicates whether or not the Backbone Router is Primary.
|
||||
*
|
||||
* @retval True if the backbone router is primary.
|
||||
* @retval False if the backbone router is not primary.
|
||||
* @retval True if the Backbone Router is Primary.
|
||||
* @retval False if the Backbone Router is not Primary.
|
||||
*
|
||||
*/
|
||||
bool IsPrimary(void) const { return mState == OT_BACKBONE_ROUTER_STATE_PRIMARY; }
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the Backbone Router is enabled.
|
||||
*
|
||||
* @retval True if the Backbone Router is enabled.
|
||||
* @retval False if the Backbone Router is not enabled.
|
||||
*
|
||||
*/
|
||||
bool IsEnabled(void) const { return mState != OT_BACKBONE_ROUTER_STATE_DISABLED; }
|
||||
|
||||
/**
|
||||
* This method sets the Backbone Router registration jitter value.
|
||||
*
|
||||
@@ -145,10 +154,10 @@ public:
|
||||
uint8_t GetRegistrationJitter(void) const { return mRegistrationJitter; }
|
||||
|
||||
/**
|
||||
* This method notifies primary backbone router status.
|
||||
* This method notifies Primary Backbone Router status.
|
||||
*
|
||||
* @param[in] aState The state or state change of primary backbone router.
|
||||
* @param[in] aConfig The primary backbone router service.
|
||||
* @param[in] aState The state or state change of Primary Backbone Router.
|
||||
* @param[in] aConfig The Primary Backbone Router service.
|
||||
*
|
||||
*/
|
||||
void UpdateBackboneRouterPrimary(Leader::State aState, const BackboneRouterConfig &aConfig);
|
||||
@@ -164,8 +173,8 @@ private:
|
||||
uint8_t mRegistrationJitter;
|
||||
|
||||
// Indicates whether or not already add Backbone Router Service to local server data.
|
||||
// Used to check whether or not in restore stage after reset or whether to remove bbr
|
||||
// service for secondary bbr if it is added by force.
|
||||
// Used to check whether or not in restore stage after reset or whether to remove
|
||||
// Backbone Router service for Secondary Backbone Router if it was added by force.
|
||||
bool mIsServiceAdded;
|
||||
};
|
||||
|
||||
|
||||
+64
-22
@@ -160,7 +160,9 @@ Mle::Mle(Instance &aInstance)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
// Primary Backbone Router Aloc
|
||||
mBackboneRouterPrimaryAloc.Clear();
|
||||
|
||||
@@ -170,6 +172,16 @@ Mle::Mle(Instance &aInstance)
|
||||
mBackboneRouterPrimaryAloc.mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||
mBackboneRouterPrimaryAloc.mScopeOverrideValid = true;
|
||||
mBackboneRouterPrimaryAloc.GetAddress().SetLocator(kAloc16BackboneRouterPrimary);
|
||||
|
||||
// All Network Backbone Routers Multicast Address.
|
||||
mAllNetworkBackboneRouters.Clear();
|
||||
|
||||
mAllNetworkBackboneRouters.GetAddress().mFields.m8[0] = 0xff; // Multicast
|
||||
mAllNetworkBackboneRouters.GetAddress().mFields.m8[1] = 0x32; // Flags = 3, Scope = 2
|
||||
mAllNetworkBackboneRouters.GetAddress().mFields.m8[2] = 0; // Reserved
|
||||
mAllNetworkBackboneRouters.GetAddress().mFields.m8[3] = 64; // Prefix Length = 64
|
||||
mAllNetworkBackboneRouters.GetAddress().mFields.m8[15] = 3; // Group ID = 3
|
||||
|
||||
#endif
|
||||
|
||||
// initialize Mesh Local Prefix
|
||||
@@ -945,10 +957,17 @@ void Mle::SetMeshLocalPrefix(const MeshLocalPrefix &aMeshLocalPrefix)
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mRealmLocalAllThreadNodes);
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
if (Get<BackboneRouter::Local>().IsPrimary())
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
|
||||
if (Get<BackboneRouter::Local>().IsEnabled())
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -957,7 +976,7 @@ void Mle::SetMeshLocalPrefix(const MeshLocalPrefix &aMeshLocalPrefix)
|
||||
mLeaderAloc.GetAddress().SetPrefix(aMeshLocalPrefix);
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
mBackboneRouterPrimaryAloc.GetAddress().SetPrefix(GetMeshLocalPrefix());
|
||||
mBackboneRouterPrimaryAloc.GetAddress().SetPrefix(aMeshLocalPrefix);
|
||||
#endif
|
||||
|
||||
// Just keep mesh local prefix if network interface is down
|
||||
@@ -971,27 +990,6 @@ exit:
|
||||
|
||||
void Mle::ApplyMeshLocalPrefix(void)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)
|
||||
{
|
||||
if (mServiceAlocs[i].GetAddress().GetLocator() != Mac::kShortAddrInvalid)
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mServiceAlocs[i]);
|
||||
mServiceAlocs[i].GetAddress().SetPrefix(GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().AddUnicastAddress(mServiceAlocs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
if (Get<BackboneRouter::Local>().IsPrimary())
|
||||
{
|
||||
Get<ThreadNetif>().AddUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
#endif
|
||||
|
||||
mLinkLocalAllThreadNodes.GetAddress().mFields.m8[3] = 64;
|
||||
memcpy(mLinkLocalAllThreadNodes.GetAddress().mFields.m8 + 4, mMeshLocal64.GetAddress().mFields.m8, 8);
|
||||
|
||||
@@ -1016,6 +1014,37 @@ void Mle::ApplyMeshLocalPrefix(void)
|
||||
Get<ThreadNetif>().AddUnicastAddress(mLeaderAloc);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)
|
||||
{
|
||||
if (mServiceAlocs[i].GetAddress().GetLocator() != Mac::kShortAddrInvalid)
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mServiceAlocs[i]);
|
||||
mServiceAlocs[i].GetAddress().SetPrefix(GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().AddUnicastAddress(mServiceAlocs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
if (Get<BackboneRouter::Local>().IsPrimary())
|
||||
{
|
||||
Get<ThreadNetif>().AddUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
|
||||
memcpy(mAllNetworkBackboneRouters.GetAddress().mFields.m8 + 4, mMeshLocal64.GetAddress().mFields.m8, 8);
|
||||
|
||||
if (Get<BackboneRouter::Local>().IsEnabled())
|
||||
{
|
||||
// Subscribe All Network Backbone Routers Multicast Address for both Seconday and Primary state.
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
exit:
|
||||
// Changing the prefix also causes the mesh local address to be different.
|
||||
Get<Notifier>().Signal(OT_CHANGED_THREAD_ML_ADDR);
|
||||
@@ -1626,17 +1655,30 @@ void Mle::HandleStateChanged(otChangedFlags aFlags)
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
if (aFlags & OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE)
|
||||
{
|
||||
if (Get<BackboneRouter::Local>().IsPrimary())
|
||||
{
|
||||
// Add Primary Backbone Router Aloc for Primary Backbone Router.
|
||||
Get<ThreadNetif>().AddUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
else
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
|
||||
if (Get<BackboneRouter::Local>().IsEnabled())
|
||||
{
|
||||
// Subscribe All Network Backbone Routers Multicast Address for both Seconday and Primary state.
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
else
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
exit:
|
||||
|
||||
+15
-1
@@ -601,6 +601,19 @@ public:
|
||||
return mRealmLocalAllThreadNodes.GetAddress();
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
/**
|
||||
* This method returns a reference to the All Network Backbone Routers Multicast Address.
|
||||
*
|
||||
* @returns A reference to the All Network Backbone Routers Multicast Address.
|
||||
*
|
||||
*/
|
||||
const Ip6::Address &GetAllNetworkBackboneRoutersAddress(void) const
|
||||
{
|
||||
return mAllNetworkBackboneRouters.GetAddress();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method gets the parent when operating in End Device mode.
|
||||
*
|
||||
@@ -1771,7 +1784,8 @@ private:
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
Ip6::NetifUnicastAddress mBackboneRouterPrimaryAloc;
|
||||
Ip6::NetifUnicastAddress mBackboneRouterPrimaryAloc;
|
||||
Ip6::NetifMulticastAddress mAllNetworkBackboneRouters;
|
||||
#endif
|
||||
|
||||
otMleCounters mCounters;
|
||||
|
||||
@@ -206,7 +206,7 @@ class TestBackboneRouterService(thread_cert.TestCase):
|
||||
self.nodes[BBR_2].reset()
|
||||
self.nodes[LEADER_1_1].release_router_id(
|
||||
self.nodes[BBR_2].get_router_id())
|
||||
# Wait for the dissemination of Network Data without backbone router service
|
||||
# Wait for the dissemination of Network Data without Backbone Router service
|
||||
self.simulator.go(10)
|
||||
|
||||
# BBR_1 becomes Primary.
|
||||
|
||||
Reference in New Issue
Block a user