Skip to content

Commit

Permalink
[routing-manager] fix lifetime management of PD prefix (openthread#10310
Browse files Browse the repository at this point in the history
)

This commit updates `PdPrefixManager` to use the newly added
`GetDeprecationTime()` method for managing the lifetime of a DHCPv6
PD prefix. This method calculates the deprecation time using the
prefix preferred lifetime directly, instead of relying on the RA
stale time constant  `GetStaleTime()`.

While the PD prefix may be determined by processing RA messages
received on the Thread interface, the RA stale time is not relevant
in this context. The RA stale time is only applicable to RA messages
received over infra-if. It specifies the time that can pass after the
last RA from a particular router on infra-if before assuming the
router might be unavailable and triggering Router Solicitation
(RS) messages.
  • Loading branch information
abtink authored May 30, 2024
1 parent bef804c commit d2e74dc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
19 changes: 5 additions & 14 deletions src/core/border_router/routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,21 +858,18 @@ void RoutingManager::OnLinkPrefix::SetFrom(const PrefixTableEntry &aPrefixTableE
mLastUpdateTime = TimerMilli::GetNow();
}

bool RoutingManager::OnLinkPrefix::IsDeprecated(void) const
bool RoutingManager::OnLinkPrefix::IsDeprecated(void) const { return GetDeprecationTime() <= TimerMilli::GetNow(); }

TimeMilli RoutingManager::OnLinkPrefix::GetDeprecationTime(void) const
{
return CalculateExpirationTime(mPreferredLifetime) <= TimerMilli::GetNow();
return CalculateExpirationTime(mPreferredLifetime);
}

TimeMilli RoutingManager::OnLinkPrefix::GetStaleTime(void) const
{
return CalculateExpirationTime(Min(kRtrAdvStaleTime, mPreferredLifetime));
}

TimeMilli RoutingManager::OnLinkPrefix::GetStaleTimeFromPreferredLifetime(void) const
{
return CalculateExpirationTime(mPreferredLifetime);
}

void RoutingManager::OnLinkPrefix::AdoptValidAndPreferredLifetimesFrom(const OnLinkPrefix &aPrefix)
{
constexpr uint32_t kTwoHoursInSeconds = 2 * 3600;
Expand Down Expand Up @@ -3728,13 +3725,7 @@ void RoutingManager::PdPrefixManager::Process(const RouterAdvert::Icmp6Packet *a

if (HasPrefix() && currentPrefixUpdated)
{
// If the prefix is obtained from an RA message, use
// `GetStaleTime()` to apply the minimum `RA_STABLE_TIME`.
// Otherwise, calculate it directly from the prefix's
// preferred lifetime.

mTimer.FireAt((aPrefixTableEntry != nullptr) ? mPrefix.GetStaleTimeFromPreferredLifetime()
: mPrefix.GetStaleTime());
mTimer.FireAt(mPrefix.GetDeprecationTime());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/border_router/routing_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ class RoutingManager : public InstanceLocator
uint32_t GetPreferredLifetime(void) const { return mPreferredLifetime; }
void ClearPreferredLifetime(void) { mPreferredLifetime = 0; }
bool IsDeprecated(void) const;
TimeMilli GetDeprecationTime(void) const;
TimeMilli GetStaleTime(void) const;
TimeMilli GetStaleTimeFromPreferredLifetime(void) const;
void AdoptValidAndPreferredLifetimesFrom(const OnLinkPrefix &aPrefix);
void CopyInfoTo(PrefixTableEntry &aEntry, TimeMilli aNow) const;

Expand Down
27 changes: 26 additions & 1 deletion tests/unit/test_routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3977,7 +3977,7 @@ void TestBorderRoutingProcessPlatfromGeneratedNd(void)
}

// 4. Short prefix will be extended to /64.
Log("Short prefix");
Log("4. Short prefix");
{
// The prefix will be padded to a /64 prefix.
Ip6::Prefix raPrefix = PrefixFromString("2001:db8:cafe:0::", 64);
Expand All @@ -4004,6 +4004,31 @@ void TestBorderRoutingProcessPlatfromGeneratedNd(void)
VerifyOmrPrefixInNetData(localOmr, /* aDefaultRoute */ false);
}

// 5. Publish a prefix with long lifetime, and wait until it expired.
Log("5. RA message with long prefix lifetime");
{
Ip6::Prefix raPrefix = PrefixFromString("2001:db8:dead:beef::", 64);

SendRouterAdvertToBorderRoutingProcessIcmp6Ra({Pio(raPrefix, 5000, 5000)});

sExpectedRios.Add(raPrefix);
AdvanceTime(10 * 1000);

VerifyPdOmrPrefix(raPrefix);
VerifyOrQuit(sExpectedRios.SawAll());
VerifyOmrPrefixInNetData(raPrefix, /* aDefaultRoute */ false);

AdvanceTime(4900 * 1000);
sExpectedRios.Clear();
VerifyPdOmrPrefix(raPrefix);
VerifyOmrPrefixInNetData(raPrefix, /* aDefaultRoute */ false);

AdvanceTime(200 * 1000);
// Deprecated prefixes will be removed.
VerifyNoPdOmrPrefix();
VerifyOmrPrefixInNetData(localOmr, /* aDefaultRoute */ false);
}

SuccessOrQuit(otBorderRoutingSetEnabled(sInstance, false));
VerifyOrQuit(sHeapAllocatedPtrs.GetLength() <= heapAllocations);

Expand Down

0 comments on commit d2e74dc

Please sign in to comment.