[mle] add GetLeaderRloc16() helper method (#10383)

This commit adds the `Mle::GetLeaderRloc16()` method, which returns
the RLOC16 of the Leader. This simplifies code that previously used
`GetLeaderId()` followed by a conversion to RLOC16.
This commit is contained in:
Abtin Keshavarzian
2024-06-14 10:04:45 -07:00
committed by GitHub
parent 18e635d2ee
commit 503bca022e
6 changed files with 13 additions and 8 deletions
+1 -1
View File
@@ -522,7 +522,7 @@ Error MeshForwarder::UpdateIp6RouteFtd(const Ip6::Header &aIp6Header, Message &a
if (aloc16 == Mle::kAloc16Leader)
{
mMeshDest = Mle::Rloc16FromRouterId(mle.GetLeaderId());
mMeshDest = mle.GetLeaderRloc16();
}
else if (aloc16 <= Mle::kAloc16DhcpAgentEnd)
{
+1 -1
View File
@@ -1004,7 +1004,7 @@ Error Mle::GetLeaderAddress(Ip6::Address &aAddress) const
VerifyOrExit(GetRloc16() != Mac::kShortAddrInvalid, error = kErrorDetached);
aAddress.SetToRoutingLocator(mMeshLocalPrefix, Rloc16FromRouterId(mLeaderData.GetLeaderRouterId()));
aAddress.SetToRoutingLocator(mMeshLocalPrefix, GetLeaderRloc16());
exit:
return error;
+8
View File
@@ -547,6 +547,14 @@ public:
*/
uint8_t GetLeaderId(void) const { return mLeaderData.GetLeaderRouterId(); }
/**
* Returns the RLOC16 of the Leader.
*
* @returns The RLOC16 of the Leader.
*
*/
uint16_t GetLeaderRloc16(void) const { return Rloc16FromRouterId(GetLeaderId()); }
/**
* Retrieves the Leader's RLOC.
*
+1 -1
View File
@@ -958,7 +958,7 @@ Error MleRouter::HandleLinkAccept(RxInfo &aRxInfo, bool aRequest)
router = mRouterTable.FindRouterById(routerId);
VerifyOrExit(router != nullptr);
if (mLeaderData.GetLeaderRouterId() == RouterIdFromRloc16(GetRloc16()))
if (GetLeaderRloc16() == GetRloc16())
{
SetStateLeader(GetRloc16(), kRestoringLeaderRoleAfterReset);
}
+1 -1
View File
@@ -152,7 +152,7 @@ bool Manager::IsBackboneRouterPreferredTo(const ServerTlv &aSer
const BackboneRouter::ServerData &aOtherServerData) const
{
bool isPreferred;
uint16_t leaderRloc16 = Mle::Rloc16FromRouterId(Get<Mle::MleRouter>().GetLeaderId());
uint16_t leaderRloc16 = Get<Mle::MleRouter>().GetLeaderRloc16();
VerifyOrExit(aServerTlv.GetServer16() != leaderRloc16, isPreferred = true);
VerifyOrExit(aOtherServerTlv.GetServer16() != leaderRloc16, isPreferred = false);
+1 -4
View File
@@ -396,10 +396,7 @@ uint8_t RouterTable::GetPathCost(uint16_t aDestRloc16) const
return pathCost;
}
uint8_t RouterTable::GetPathCostToLeader(void) const
{
return GetPathCost(Mle::Rloc16FromRouterId(Get<Mle::Mle>().GetLeaderId()));
}
uint8_t RouterTable::GetPathCostToLeader(void) const { return GetPathCost(Get<Mle::Mle>().GetLeaderRloc16()); }
void RouterTable::GetNextHopAndPathCost(uint16_t aDestRloc16, uint16_t &aNextHopRloc16, uint8_t &aPathCost) const
{