[border-router] send RA immediately when RA parameters are updated (#6565)

This commit is contained in:
kangping
2021-05-06 10:08:07 -07:00
committed by GitHub
parent 4b455ca72c
commit 217727ec62
5 changed files with 54 additions and 11 deletions
@@ -208,6 +208,12 @@ const RouterAdvMessage &RouterAdvMessage::operator=(const RouterAdvMessage &aOth
return *this;
}
bool RouterAdvMessage::operator==(const RouterAdvMessage &aOther) const
{
return memcmp(&mHeader.mData, &aOther.mHeader.mData, sizeof(mHeader.mData)) == 0 &&
mReachableTime == aOther.mReachableTime && mRetransTimer == aOther.mRetransTimer;
}
RouterSolicitMessage::RouterSolicitMessage(void)
{
mHeader.Clear();
@@ -447,6 +447,30 @@ public:
*/
const RouterAdvMessage &operator=(const RouterAdvMessage &aOther);
/**
* This method overloads operator `==` to evaluate whether or not
* two instances of `RouterAdvMessage` are equal.
*
* @param[in] aOther The other `RouterAdvMessage` instance to compare with.
*
* @retval TRUE If the two `RouterAdvMessage` instances are equal.
* @retval FALSE If the two `RouterAdvMessage` instances are not equal.
*
*/
bool operator==(const RouterAdvMessage &aOther) const;
/**
* This method overloads operator `!=` to evaluate whether or not
* two instances of `RouterAdvMessage` are equal.
*
* @param[in] aOther The other `RouterAdvMessage` instance to compare with.
*
* @retval TRUE If the two `RouterAdvMessage` instances are not equal.
* @retval FALSE If the two `RouterAdvMessage` instances are equal.
*
*/
bool operator!=(const RouterAdvMessage &aOther) const { return !(*this == aOther); }
private:
enum : uint8_t
{
+22 -10
View File
@@ -959,16 +959,7 @@ void RoutingManager::HandleRouterAdvertisement(const Ip6::Address &aSrcAddress,
// initiated from the infra interface.
if (otPlatInfraIfHasAddress(mInfraIfIndex, &aSrcAddress))
{
if (routerAdvMessage->GetRouterLifetime() == 0)
{
mRouterAdvMessage.SetToDefault();
}
else
{
mRouterAdvMessage = *routerAdvMessage;
// TODO: add a timer for invalidating the learned RA parameters
// for cases that the other RA daemon crashed or is force killed.
}
needReevaluate |= UpdateRouterAdvMessage(*routerAdvMessage);
}
if (needReevaluate)
@@ -1198,6 +1189,27 @@ bool RoutingManager::NetworkDataContainsOmrPrefix(const Ip6::Prefix &aPrefix) co
return contain;
}
// Update the `mRouterAdvMessage` with given Router Advertisement message.
// Returns a boolean which indicates whether there are changes of `mRouterAdvMessage`.
bool RoutingManager::UpdateRouterAdvMessage(const RouterAdv::RouterAdvMessage &aRouterAdvMessage)
{
RouterAdv::RouterAdvMessage oldRouterAdvMessage;
oldRouterAdvMessage = mRouterAdvMessage;
if (aRouterAdvMessage.GetRouterLifetime() == 0)
{
mRouterAdvMessage.SetToDefault();
}
else
{
mRouterAdvMessage = aRouterAdvMessage;
// TODO: add a timer for invalidating the learned RA parameters
// for cases that the other RA daemon crashed or is force killed.
}
return (mRouterAdvMessage != oldRouterAdvMessage);
}
} // namespace BorderRouter
} // namespace ot
@@ -232,6 +232,7 @@ private:
uint32_t aLifetime,
otRoutePreference aRoutePreference = OT_ROUTE_PREFERENCE_MED);
bool NetworkDataContainsOmrPrefix(const Ip6::Prefix &aPrefix) const;
bool UpdateRouterAdvMessage(const RouterAdv::RouterAdvMessage &aRouterAdvMessage);
static bool IsValidOmrPrefix(const NetworkData::OnMeshPrefixConfig &aOnMeshPrefixConfig);
static bool IsValidOmrPrefix(const Ip6::Prefix &aOmrPrefix);
@@ -114,7 +114,7 @@ class SingleBorderRouter(thread_cert.TestCase):
self.assertTrue(host.ping(router.get_ip6_address(config.ADDRESS_TYPE.OMR)[0], backbone=True))
# Stop the radvd service and wait for the Border Router
# to start adverting on-link prefix on its own.
# to reset the RA parameters.
br.stop_radvd_service()
self.simulator.go(15)