mirror of
https://github.com/espressif/openthread.git
synced 2026-08-25 11:49:51 +00:00
[routing-manager] track and log favored OMR prefix changes (#11236)
This commit enhances the `OmrPrefixManager` to track and log changes to the favored OMR prefix. The new log includes the old favored prefix (if any) along with the new one, and provides additional information such as its preference, whether it is a domain prefix, or whether it matches the local OMR prefix. This replaces and enhances the previous logs. This new mechanism can also be used to signal (to other modules) when the favored OMR prefix changes.
This commit is contained in:
@@ -2221,6 +2221,12 @@ bool RoutingManager::FavoredOmrPrefix::IsInfrastructureDerived(void) const
|
||||
return !IsEmpty() && (mPreference >= NetworkData::kRoutePreferenceMedium);
|
||||
}
|
||||
|
||||
bool RoutingManager::FavoredOmrPrefix::operator==(const FavoredOmrPrefix &aOther) const
|
||||
{
|
||||
return (mPreference == aOther.mPreference) && (mIsDomainPrefix == aOther.mIsDomainPrefix) &&
|
||||
(mPrefix == aOther.mPrefix);
|
||||
}
|
||||
|
||||
void RoutingManager::FavoredOmrPrefix::SetFrom(const NetworkData::OnMeshPrefixConfig &aOnMeshPrefixConfig)
|
||||
{
|
||||
mPrefix = aOnMeshPrefixConfig.GetPrefix();
|
||||
@@ -2273,22 +2279,41 @@ void RoutingManager::OmrPrefixManager::Init(const Ip6::Prefix &aBrUlaPrefix)
|
||||
LogInfo("Generated local OMR prefix: %s", mGeneratedPrefix.ToString().AsCString());
|
||||
}
|
||||
|
||||
void RoutingManager::OmrPrefixManager::Start(void) { DetermineFavoredPrefix(); }
|
||||
void RoutingManager::OmrPrefixManager::Start(void)
|
||||
{
|
||||
FavoredOmrPrefix favoredPrefix;
|
||||
|
||||
DetermineFavoredPrefixInNetData(favoredPrefix);
|
||||
SetFavordPrefix(favoredPrefix);
|
||||
}
|
||||
|
||||
void RoutingManager::OmrPrefixManager::Stop(void)
|
||||
{
|
||||
RemoveLocalFromNetData();
|
||||
mFavoredPrefix.Clear();
|
||||
ClearFavoredPrefix();
|
||||
}
|
||||
|
||||
void RoutingManager::OmrPrefixManager::DetermineFavoredPrefix(void)
|
||||
void RoutingManager::OmrPrefixManager::SetFavordPrefix(const OmrPrefix &aOmrPrefix)
|
||||
{
|
||||
FavoredOmrPrefix oldFavoredPrefix = mFavoredPrefix;
|
||||
|
||||
mFavoredPrefix.SetFrom(aOmrPrefix);
|
||||
|
||||
if (oldFavoredPrefix != mFavoredPrefix)
|
||||
{
|
||||
LogInfo("Favored OMR prefix: %s -> %s", FavoredToString(oldFavoredPrefix).AsCString(),
|
||||
FavoredToString(mFavoredPrefix).AsCString());
|
||||
}
|
||||
}
|
||||
|
||||
void RoutingManager::OmrPrefixManager::DetermineFavoredPrefixInNetData(FavoredOmrPrefix &aFavoredPrefix)
|
||||
{
|
||||
// Determine the favored OMR prefix present in Network Data.
|
||||
|
||||
NetworkData::Iterator iterator = NetworkData::kIteratorInit;
|
||||
NetworkData::OnMeshPrefixConfig prefixConfig;
|
||||
|
||||
mFavoredPrefix.Clear();
|
||||
aFavoredPrefix.Clear();
|
||||
|
||||
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, prefixConfig) == kErrorNone)
|
||||
{
|
||||
@@ -2297,18 +2322,20 @@ void RoutingManager::OmrPrefixManager::DetermineFavoredPrefix(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mFavoredPrefix.IsEmpty() || !mFavoredPrefix.IsFavoredOver(prefixConfig))
|
||||
if (aFavoredPrefix.IsEmpty() || !aFavoredPrefix.IsFavoredOver(prefixConfig))
|
||||
{
|
||||
mFavoredPrefix.SetFrom(prefixConfig);
|
||||
aFavoredPrefix.SetFrom(prefixConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RoutingManager::OmrPrefixManager::Evaluate(void)
|
||||
{
|
||||
FavoredOmrPrefix favoredPrefix;
|
||||
|
||||
OT_ASSERT(Get<RoutingManager>().IsRunning());
|
||||
|
||||
DetermineFavoredPrefix();
|
||||
DetermineFavoredPrefixInNetData(favoredPrefix);
|
||||
|
||||
// Determine the local prefix and remove outdated prefix published by us.
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE
|
||||
@@ -2335,33 +2362,22 @@ void RoutingManager::OmrPrefixManager::Evaluate(void)
|
||||
}
|
||||
|
||||
// Decide if we need to add or remove our local OMR prefix.
|
||||
if (mFavoredPrefix.IsEmpty() || mFavoredPrefix.GetPreference() < mLocalPrefix.GetPreference())
|
||||
|
||||
if (favoredPrefix.IsEmpty() || favoredPrefix.GetPreference() < mLocalPrefix.GetPreference())
|
||||
{
|
||||
if (mFavoredPrefix.IsEmpty())
|
||||
{
|
||||
LogInfo("No favored OMR prefix found in Thread network.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogInfo("Replacing favored OMR prefix %s with higher preference local prefix %s.",
|
||||
mFavoredPrefix.GetPrefix().ToString().AsCString(), mLocalPrefix.GetPrefix().ToString().AsCString());
|
||||
}
|
||||
|
||||
// The `mFavoredPrefix` remains empty if we fail to publish
|
||||
// the local OMR prefix.
|
||||
SuccessOrExit(AddLocalToNetData());
|
||||
|
||||
mFavoredPrefix.SetFrom(mLocalPrefix);
|
||||
SetFavordPrefix(mLocalPrefix);
|
||||
ExitNow();
|
||||
}
|
||||
else if (mFavoredPrefix.GetPrefix() == mLocalPrefix.GetPrefix())
|
||||
|
||||
SetFavordPrefix(favoredPrefix);
|
||||
|
||||
if (favoredPrefix.GetPrefix() == mLocalPrefix.GetPrefix())
|
||||
{
|
||||
IgnoreError(AddLocalToNetData());
|
||||
}
|
||||
else if (mIsLocalAddedInNetData)
|
||||
{
|
||||
LogInfo("There is already a favored OMR prefix %s in the Thread network",
|
||||
mFavoredPrefix.GetPrefix().ToString().AsCString());
|
||||
|
||||
RemoveLocalFromNetData();
|
||||
}
|
||||
|
||||
@@ -2477,6 +2493,36 @@ RoutingManager::OmrPrefixManager::InfoString RoutingManager::OmrPrefixManager::L
|
||||
return string;
|
||||
}
|
||||
|
||||
RoutingManager::OmrPrefixManager::InfoString RoutingManager::OmrPrefixManager::FavoredToString(
|
||||
const FavoredOmrPrefix &aFavoredPrefix) const
|
||||
{
|
||||
InfoString string;
|
||||
|
||||
if (aFavoredPrefix.IsEmpty())
|
||||
{
|
||||
string.Append("(none)");
|
||||
}
|
||||
else
|
||||
{
|
||||
string.Append("%s (prf:%s", aFavoredPrefix.GetPrefix().ToString().AsCString(),
|
||||
RoutePreferenceToString(aFavoredPrefix.GetPreference()));
|
||||
|
||||
if (aFavoredPrefix.IsDomainPrefix())
|
||||
{
|
||||
string.Append(", domain");
|
||||
}
|
||||
|
||||
if (aFavoredPrefix.GetPrefix() == mLocalPrefix.GetPrefix())
|
||||
{
|
||||
string.Append(", local");
|
||||
}
|
||||
|
||||
string.Append(")");
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// OnLinkPrefixManager
|
||||
|
||||
|
||||
@@ -1094,12 +1094,13 @@ private:
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
class FavoredOmrPrefix : public OmrPrefix
|
||||
class FavoredOmrPrefix : public OmrPrefix, public Unequatable<FavoredOmrPrefix>
|
||||
{
|
||||
friend class OmrPrefixManager;
|
||||
|
||||
public:
|
||||
bool IsInfrastructureDerived(void) const;
|
||||
bool operator==(const FavoredOmrPrefix &aOther) const;
|
||||
|
||||
private:
|
||||
void SetFrom(const NetworkData::OnMeshPrefixConfig &aOnMeshPrefixConfig);
|
||||
@@ -1129,11 +1130,14 @@ private:
|
||||
|
||||
typedef String<kInfoStringSize> InfoString;
|
||||
|
||||
void DetermineFavoredPrefix(void);
|
||||
void SetFavordPrefix(const OmrPrefix &aOmrPrefix);
|
||||
void ClearFavoredPrefix(void) { SetFavordPrefix(OmrPrefix()); }
|
||||
void DetermineFavoredPrefixInNetData(FavoredOmrPrefix &aFavoredPrefix);
|
||||
Error AddLocalToNetData(void);
|
||||
Error AddOrUpdateLocalInNetData(void);
|
||||
void RemoveLocalFromNetData(void);
|
||||
InfoString LocalToString(void) const;
|
||||
InfoString FavoredToString(const FavoredOmrPrefix &aFavoredPrefix) const;
|
||||
|
||||
OmrPrefix mLocalPrefix;
|
||||
Ip6::Prefix mGeneratedPrefix;
|
||||
|
||||
Reference in New Issue
Block a user