mirror of
https://github.com/espressif/openthread.git
synced 2026-09-25 18:37:40 +00:00
[bbr] move bbr relative addresses to BackboneRouter::Local (#4893)
This commit is contained in:
@@ -280,7 +280,7 @@ void Leader::UpdateDomainPrefixConfig(void)
|
||||
LogDomainPrefix(state, mDomainPrefix);
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
Get<Mle::Mle>().UpdateAllDomainBackboneRouters(state);
|
||||
Get<Local>().UpdateAllDomainBackboneRouters(state);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,32 @@ Local::Local(Instance &aInstance)
|
||||
, mIsServiceAdded(false)
|
||||
{
|
||||
mDomainPrefixConfig.mPrefix.mLength = 0;
|
||||
|
||||
// Primary Backbone Router Aloc
|
||||
mBackboneRouterPrimaryAloc.Clear();
|
||||
|
||||
mBackboneRouterPrimaryAloc.mPrefixLength = Mle::MeshLocalPrefix::kLength;
|
||||
mBackboneRouterPrimaryAloc.mPreferred = true;
|
||||
mBackboneRouterPrimaryAloc.mValid = true;
|
||||
mBackboneRouterPrimaryAloc.mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||
mBackboneRouterPrimaryAloc.mScopeOverrideValid = true;
|
||||
mBackboneRouterPrimaryAloc.GetAddress().SetLocator(Mle::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[15] = 3; // Group ID = 3
|
||||
|
||||
// All Domain Backbone Routers Multicast Address.
|
||||
mAllDomainBackboneRouters.Clear();
|
||||
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[0] = 0xff; // Multicast
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[1] = 0x32; // Flags = 3, Scope = 2
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[2] = 0; // Reserved
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[15] = 3; // Group ID = 3
|
||||
}
|
||||
|
||||
void Local::SetEnabled(bool aEnable)
|
||||
@@ -194,7 +220,30 @@ void Local::SetState(BackboneRouterState aState)
|
||||
{
|
||||
VerifyOrExit(mState != aState, OT_NOOP);
|
||||
|
||||
if (mState == OT_BACKBONE_ROUTER_STATE_DISABLED)
|
||||
{
|
||||
// Subscribe All Network Backbone Routers Multicast Address for both Secondary and Primary state.
|
||||
mAllNetworkBackboneRouters.GetAddress().SetMulticastNetworkPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
else if (aState == OT_BACKBONE_ROUTER_STATE_DISABLED)
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
|
||||
if (mState == OT_BACKBONE_ROUTER_STATE_PRIMARY)
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
else if (aState == OT_BACKBONE_ROUTER_STATE_PRIMARY)
|
||||
{
|
||||
// Add Primary Backbone Router Aloc for Primary Backbone Router.
|
||||
mBackboneRouterPrimaryAloc.GetAddress().SetPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().AddUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
|
||||
mState = aState;
|
||||
|
||||
Get<Notifier>().Signal(OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE);
|
||||
|
||||
exit:
|
||||
@@ -298,6 +347,48 @@ void Local::SetDomainPrefix(const NetworkData::OnMeshPrefixConfig &aConfig)
|
||||
}
|
||||
}
|
||||
|
||||
void Local::ApplyMeshLocalPrefix(void)
|
||||
{
|
||||
VerifyOrExit(IsEnabled(), OT_NOOP);
|
||||
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
mAllNetworkBackboneRouters.GetAddress().SetMulticastNetworkPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
|
||||
if (IsPrimary())
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
mBackboneRouterPrimaryAloc.GetAddress().SetPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().AddUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Local::UpdateAllDomainBackboneRouters(Leader::DomainPrefixState aState)
|
||||
{
|
||||
if (!IsEnabled())
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllDomainBackboneRouters);
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (aState == Leader::kDomainPrefixRemoved || aState == Leader::kDomainPrefixRefreshed)
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllDomainBackboneRouters);
|
||||
}
|
||||
|
||||
if (aState == Leader::kDomainPrefixAdded || aState == Leader::kDomainPrefixRefreshed)
|
||||
{
|
||||
mAllDomainBackboneRouters.GetAddress().SetMulticastNetworkPrefix(*Get<Leader>().GetDomainPrefix());
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllDomainBackboneRouters);
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Local::RemoveDomainPrefixFromNetworkData(void)
|
||||
{
|
||||
otError error = OT_ERROR_NOT_FOUND; // only used for logging.
|
||||
|
||||
@@ -195,6 +195,42 @@ public:
|
||||
*/
|
||||
void SetDomainPrefix(const NetworkData::OnMeshPrefixConfig &aConfig);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a reference to the All Domain Backbone Routers Multicast Address.
|
||||
*
|
||||
* @returns A reference to the All Domain Backbone Routers Multicast Address.
|
||||
*
|
||||
*/
|
||||
const Ip6::Address &GetAllDomainBackboneRoutersAddress(void) const
|
||||
{
|
||||
return mAllDomainBackboneRouters.GetAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method applies the Mesh Local Prefix.
|
||||
*
|
||||
*/
|
||||
void ApplyMeshLocalPrefix(void);
|
||||
|
||||
/**
|
||||
* This method updates the subscription of All Domain Backbone Routers Multicast Address.
|
||||
*
|
||||
* @param[in] aState The Domain Prefix state or state change.
|
||||
*
|
||||
*/
|
||||
void UpdateAllDomainBackboneRouters(Leader::DomainPrefixState aState);
|
||||
|
||||
private:
|
||||
void SetState(BackboneRouterState aState);
|
||||
otError RemoveService(void);
|
||||
@@ -220,6 +256,10 @@ private:
|
||||
bool mIsServiceAdded;
|
||||
|
||||
NetworkData::OnMeshPrefixConfig mDomainPrefixConfig;
|
||||
|
||||
Ip6::NetifUnicastAddress mBackboneRouterPrimaryAloc;
|
||||
Ip6::NetifMulticastAddress mAllNetworkBackboneRouters;
|
||||
Ip6::NetifMulticastAddress mAllDomainBackboneRouters;
|
||||
};
|
||||
|
||||
} // namespace BackboneRouter
|
||||
|
||||
+1
-116
@@ -156,35 +156,6 @@ Mle::Mle(Instance &aInstance)
|
||||
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
// Primary Backbone Router Aloc
|
||||
mBackboneRouterPrimaryAloc.Clear();
|
||||
|
||||
mBackboneRouterPrimaryAloc.mPrefixLength = MeshLocalPrefix::kLength;
|
||||
mBackboneRouterPrimaryAloc.mPreferred = true;
|
||||
mBackboneRouterPrimaryAloc.mValid = true;
|
||||
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[15] = 3; // Group ID = 3
|
||||
|
||||
// All Domain Backbone Routers Multicast Address.
|
||||
mAllDomainBackboneRouters.Clear();
|
||||
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[0] = 0xff; // Multicast
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[1] = 0x32; // Flags = 3, Scope = 2
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[2] = 0; // Reserved
|
||||
mAllDomainBackboneRouters.GetAddress().mFields.m8[15] = 3; // Group ID = 3
|
||||
#endif
|
||||
|
||||
// initialize Mesh Local Prefix
|
||||
meshLocalPrefix.SetFromExtendedPanId(Get<Mac::Mac>().GetExtendedPanId());
|
||||
|
||||
@@ -944,30 +915,12 @@ void Mle::SetMeshLocalPrefix(const MeshLocalPrefix &aMeshLocalPrefix)
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mMeshLocal16);
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mLinkLocalAllThreadNodes);
|
||||
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
|
||||
}
|
||||
|
||||
mMeshLocal64.GetAddress().SetPrefix(aMeshLocalPrefix);
|
||||
mMeshLocal16.GetAddress().SetPrefix(aMeshLocalPrefix);
|
||||
mLeaderAloc.GetAddress().SetPrefix(aMeshLocalPrefix);
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
mBackboneRouterPrimaryAloc.GetAddress().SetPrefix(aMeshLocalPrefix);
|
||||
#endif
|
||||
|
||||
// Just keep mesh local prefix if network interface is down
|
||||
VerifyOrExit(Get<ThreadNetif>().IsUp(), OT_NOOP);
|
||||
|
||||
@@ -1015,20 +968,7 @@ void Mle::ApplyMeshLocalPrefix(void)
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
if (Get<BackboneRouter::Local>().IsPrimary())
|
||||
{
|
||||
Get<ThreadNetif>().AddUnicastAddress(mBackboneRouterPrimaryAloc);
|
||||
}
|
||||
|
||||
mAllNetworkBackboneRouters.GetAddress().SetMulticastNetworkPrefix(GetMeshLocalPrefix());
|
||||
|
||||
if (Get<BackboneRouter::Local>().IsEnabled())
|
||||
{
|
||||
// Subscribe All Network Backbone Routers Multicast Address for both Secondary and Primary state.
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
|
||||
Get<BackboneRouter::Local>().ApplyMeshLocalPrefix();
|
||||
#endif
|
||||
|
||||
exit:
|
||||
@@ -1651,33 +1591,6 @@ void Mle::HandleStateChanged(otChangedFlags aFlags)
|
||||
Get<Ip6::Filter>().AllowNativeCommissioner(Get<KeyManager>().IsNativeCommissioningAllowed());
|
||||
}
|
||||
|
||||
#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 Secondary and Primary state.
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
else
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllNetworkBackboneRouters);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
@@ -4442,33 +4355,5 @@ void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const
|
||||
OT_UNUSED_VARIABLE(error);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
void Mle::UpdateAllDomainBackboneRouters(BackboneRouter::Leader::DomainPrefixState aState)
|
||||
{
|
||||
if (!Get<BackboneRouter::Local>().IsEnabled())
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllDomainBackboneRouters);
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
if (aState == BackboneRouter::Leader::kDomainPrefixRemoved ||
|
||||
aState == BackboneRouter::Leader::kDomainPrefixRefreshed)
|
||||
{
|
||||
Get<ThreadNetif>().UnsubscribeMulticast(mAllDomainBackboneRouters);
|
||||
}
|
||||
|
||||
if (aState == BackboneRouter::Leader::kDomainPrefixAdded ||
|
||||
aState == BackboneRouter::Leader::kDomainPrefixRefreshed)
|
||||
{
|
||||
mAllDomainBackboneRouters.GetAddress().SetMulticastNetworkPrefix(
|
||||
*Get<BackboneRouter::Leader>().GetDomainPrefix());
|
||||
Get<ThreadNetif>().SubscribeMulticast(mAllDomainBackboneRouters);
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
} // namespace Mle
|
||||
} // namespace ot
|
||||
|
||||
@@ -45,9 +45,6 @@
|
||||
#include "thread/mle_tlvs.hpp"
|
||||
#include "thread/mle_types.hpp"
|
||||
#include "thread/topology.hpp"
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
#include "backbone_router/leader.hpp"
|
||||
#endif
|
||||
|
||||
namespace ot {
|
||||
|
||||
@@ -616,8 +613,6 @@ public:
|
||||
/**
|
||||
* This method applies the Mesh Local Prefix.
|
||||
*
|
||||
* @param[in] aPrefix A reference to the Mesh Local Prefix.
|
||||
*
|
||||
*/
|
||||
void ApplyMeshLocalPrefix(void);
|
||||
|
||||
@@ -658,39 +653,6 @@ 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a reference to the All Domain Backbone Routers Multicast Address.
|
||||
*
|
||||
* @returns A reference to the All Domain Backbone Routers Multicast Address.
|
||||
*
|
||||
*/
|
||||
const Ip6::Address &GetAllDomainBackboneRoutersAddress(void) const
|
||||
{
|
||||
return mAllDomainBackboneRouters.GetAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method updates the subscription of All Domain Backbone Routers Multicast Address.
|
||||
*
|
||||
* @param[in] aState The Domain Prefix state or state change.
|
||||
*
|
||||
*/
|
||||
void UpdateAllDomainBackboneRouters(BackboneRouter::Leader::DomainPrefixState aState);
|
||||
|
||||
#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
|
||||
/**
|
||||
* This method gets the parent when operating in End Device mode.
|
||||
*
|
||||
@@ -1870,12 +1832,6 @@ private:
|
||||
Ip6::NetifUnicastAddress mServiceAlocs[kMaxServiceAlocs];
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
Ip6::NetifUnicastAddress mBackboneRouterPrimaryAloc;
|
||||
Ip6::NetifMulticastAddress mAllNetworkBackboneRouters;
|
||||
Ip6::NetifMulticastAddress mAllDomainBackboneRouters;
|
||||
#endif
|
||||
|
||||
otMleCounters mCounters;
|
||||
|
||||
Ip6::NetifUnicastAddress mLinkLocal64;
|
||||
|
||||
Reference in New Issue
Block a user