[routing-manager] add RxRaTracker::Router::IsReachable() (#10379)

This commit adds the `IsReachable()` helper method to `Router` class,
which checks whether a router is considered reachable. It replaces
the previous comparisons of `mNsProbeCount` in the code, improving
readability. Neighbor Solicitation (NS) messages are used to
determine reachability if the router has not been heard from for some
time.
This commit is contained in:
Abtin Keshavarzian
2024-06-14 10:00:14 -07:00
committed by GitHub
parent fb24bec873
commit 3b589b3e1f
2 changed files with 15 additions and 13 deletions
+11 -10
View File
@@ -1459,15 +1459,15 @@ void RoutingManager::RxRaTracker::RemoveOrDeprecateOldEntries(TimeMilli aTimeThr
RemoveExpiredEntries();
}
void RoutingManager::RxRaTracker::RemoveOrDeprecateEntriesFromInactiveRouters(void)
void RoutingManager::RxRaTracker::RemoveOrDeprecateEntriesFromUnreachableRouters(void)
{
// Remove route prefix entries and deprecate on-link prefix entries
// in the table for routers that have reached the max NS probe
// attempts and considered as inactive.
// attempts and considered unreachable.
for (Router &router : mRouters)
{
if (router.mNsProbeCount <= Router::kMaxNsProbes)
if (router.IsReachable())
{
continue;
}
@@ -1522,7 +1522,7 @@ void RoutingManager::RxRaTracker::ScheduleAllTimers(void)
for (const Router &router : mRouters)
{
if ((router.mNsProbeCount <= Router::kMaxNsProbes) && !router.mIsLocalDevice)
if (router.IsReachable() && !router.mIsLocalDevice)
{
// Skip if router is this device or has failed all
// earlier NS probes.
@@ -1697,7 +1697,8 @@ void RoutingManager::RxRaTracker::UpdateRouterOnRx(Router &aRouter)
aRouter.mNsProbeCount = 0;
aRouter.mLastUpdateTime = TimerMilli::GetNow();
aRouter.mTimeout = aRouter.mLastUpdateTime + Random::NonCrypto::AddJitter(Router::kActiveTimeout, Router::kJitter);
aRouter.mTimeout =
aRouter.mLastUpdateTime + Random::NonCrypto::AddJitter(Router::kReachableTimeout, Router::kJitter);
mRouterTimer.FireAtIfEarlier(aRouter.mTimeout);
}
@@ -1707,7 +1708,7 @@ void RoutingManager::RxRaTracker::HandleRouterTimer(void)
for (Router &router : mRouters)
{
if (router.mNsProbeCount > Router::kMaxNsProbes)
if (!router.IsReachable())
{
continue;
}
@@ -1725,7 +1726,7 @@ void RoutingManager::RxRaTracker::HandleRouterTimer(void)
{
router.mNsProbeCount++;
if (router.mNsProbeCount > Router::kMaxNsProbes)
if (!router.IsReachable())
{
LogInfo("No response to all Neighbor Solicitations attempts from router %s",
router.mAddress.ToString().AsCString());
@@ -1739,7 +1740,7 @@ void RoutingManager::RxRaTracker::HandleRouterTimer(void)
}
}
RemoveOrDeprecateEntriesFromInactiveRouters();
RemoveOrDeprecateEntriesFromUnreachableRouters();
ScheduleAllTimers();
}
@@ -1782,7 +1783,7 @@ void RoutingManager::RxRaTracker::DetermineAndSetFlags(RouterAdvert::Header &aHe
continue;
}
if (router.mNsProbeCount > Router::kMaxNsProbes)
if (!router.IsReachable())
{
continue;
}
@@ -1952,7 +1953,7 @@ bool RoutingManager::RxRaTracker::Router::Matches(EmptyChecker aChecker) const
bool hasFlags = false;
if (mNsProbeCount <= kMaxNsProbes)
if (IsReachable())
{
hasFlags = (mManagedAddressConfigFlag || mOtherConfigFlag);
}
+4 -3
View File
@@ -811,9 +811,9 @@ private:
struct Router : public Clearable<Router>
{
// The timeout (in msec) for router staying in active state
// The timeout (in msec) for router to be considered reachable
// before starting the Neighbor Solicitation (NS) probes.
static constexpr uint32_t kActiveTimeout = OPENTHREAD_CONFIG_BORDER_ROUTING_ROUTER_ACTIVE_CHECK_TIMEOUT;
static constexpr uint32_t kReachableTimeout = OPENTHREAD_CONFIG_BORDER_ROUTING_ROUTER_ACTIVE_CHECK_TIMEOUT;
static constexpr uint8_t kMaxNsProbes = 5; // Max number of NS probe attempts.
static constexpr uint32_t kNsProbeRetryInterval = 1000; // In msec. Time between NS probe attempts.
@@ -827,6 +827,7 @@ private:
kContainsNoEntriesOrFlags
};
bool IsReachable(void) const { return mNsProbeCount <= kMaxNsProbes; }
bool Matches(const Ip6::Address &aAddress) const { return aAddress == mAddress; }
bool Matches(EmptyChecker aChecker) const;
void CopyInfoTo(RouterEntry &aEntry, TimeMilli aNow) const;
@@ -914,7 +915,7 @@ private:
void ProcessRouteInfoOption(const RouteInfoOption &aRio, Router &aRouter);
void ProcessRaFlagsExtOption(const RaFlagsExtOption &aFlagsOption, Router &aRouter);
bool ContainsOnLinkPrefix(OnLinkPrefix::UlaChecker aUlaChecker) const;
void RemoveOrDeprecateEntriesFromInactiveRouters(void);
void RemoveOrDeprecateEntriesFromUnreachableRouters(void);
void RemoveRoutersWithNoEntriesOrFlags(void);
void RemoveExpiredEntries(void);
void SignalTableChanged(void);