From 05747e7670db228f4f62e12279dc5eae67a4ba16 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 17 Jan 2020 11:25:54 -0800 Subject: [PATCH] [mle] rename static method to Rloc16FromRouterId() from GetRloc16() (#4486) This commit renames the static `Mle` method which derives RLOC16 from a given Router ID to `Rloc16FromRouterId()` from `GetRloc16()`. This helps distinguish this method from other `GetRloc16()` methods. --- src/core/thread/mesh_forwarder_ftd.cpp | 6 +++--- src/core/thread/mle.cpp | 4 ++-- src/core/thread/mle.hpp | 9 ++++++--- src/core/thread/mle_router.cpp | 14 +++++++------- src/core/thread/router_table.cpp | 8 ++++---- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 8e85cd773..bf402ae14 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -389,7 +389,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header) if (aloc16 == Mle::kAloc16Leader) { - mMeshDest = Mle::Mle::GetRloc16(mle.GetLeaderId()); + mMeshDest = Mle::Mle::Rloc16FromRouterId(mle.GetLeaderId()); } else if ((aloc16 >= Mle::kAloc16CommissionerStart) && (aloc16 <= Mle::kAloc16CommissionerEnd)) { @@ -406,14 +406,14 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header) routerId = Mle::Mle::GetRouterId(agentRloc16); // if agent is active router or the child of the device - if ((Mle::Mle::IsActiveRouter(agentRloc16)) || (Mle::Mle::GetRloc16(routerId) == mle.GetRloc16())) + if ((Mle::Mle::IsActiveRouter(agentRloc16)) || (Mle::Mle::Rloc16FromRouterId(routerId) == mle.GetRloc16())) { mMeshDest = agentRloc16; } else { // use the parent of the ED Agent as Dest - mMeshDest = Mle::Mle::GetRloc16(routerId); + mMeshDest = Mle::Mle::Rloc16FromRouterId(routerId); } } else if ((aloc16 >= Mle::kAloc16ServiceStart) && (aloc16 <= Mle::kAloc16ServiceEnd)) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index e2983de3f..49bdbacc5 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -423,7 +423,7 @@ otError Mle::Restore(void) mParent.SetExtAddress(*static_cast(&parentInfo.mExtAddress)); mParent.SetDeviceMode(DeviceMode(DeviceMode::kModeFullThreadDevice | DeviceMode::kModeRxOnWhenIdle | DeviceMode::kModeFullNetworkData | DeviceMode::kModeSecureDataRequest)); - mParent.SetRloc16(GetRloc16(GetRouterId(networkInfo.mRloc16))); + mParent.SetRloc16(Rloc16FromRouterId(GetRouterId(networkInfo.mRloc16))); mParent.SetState(Neighbor::kStateRestored); #if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH @@ -1013,7 +1013,7 @@ otError Mle::GetLeaderAddress(Ip6::Address &aAddress) const aAddress.mFields.m16[4] = HostSwap16(0x0000); aAddress.mFields.m16[5] = HostSwap16(0x00ff); aAddress.mFields.m16[6] = HostSwap16(0xfe00); - aAddress.mFields.m16[7] = HostSwap16(GetRloc16(mLeaderData.GetLeaderRouterId())); + aAddress.mFields.m16[7] = HostSwap16(Rloc16FromRouterId(mLeaderData.GetLeaderRouterId())); exit: return error; diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 2910b4010..74fe217e1 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -989,14 +989,17 @@ public: } /** - * This method returns the RLOC16 of a given Router ID. + * This method derives RLOC16 from a given Router ID. * * @param[in] aRouterId The Router ID value. * - * @returns The RLOC16 of the given Router ID. + * @returns The RLOC16 corresponding to the given Router ID. * */ - static uint16_t GetRloc16(uint8_t aRouterId) { return static_cast(aRouterId << kRouterIdOffset); } + static uint16_t Rloc16FromRouterId(uint8_t aRouterId) + { + return static_cast(aRouterId << kRouterIdOffset); + } /** * This method indicates whether or not @p aRloc16 refers to an active router. diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index d4357772d..d42ceb7eb 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -197,7 +197,7 @@ otError MleRouter::BecomeLeader(void) Get().Reset(); Get().SetEmptyCommissionerData(); - SetStateLeader(GetRloc16(leaderId)); + SetStateLeader(Rloc16FromRouterId(leaderId)); exit: return error; @@ -1529,7 +1529,7 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) Router &router = *iter.GetRouter(); otLogInfoMle(" %04x -> %04x, cost:%d %d, lqin:%d, lqout:%d, link:%s", router.GetRloc16(), - (router.GetNextHop() == kInvalidRouterId) ? 0xffff : GetRloc16(router.GetNextHop()), + (router.GetNextHop() == kInvalidRouterId) ? 0xffff : Rloc16FromRouterId(router.GetNextHop()), router.GetCost(), mRouterTable.GetLinkCost(router), router.GetLinkInfo().GetLinkQuality(), router.GetLinkQualityOut(), router.GetRloc16() == GetRloc16() ? "device" : (router.IsStateValid() ? "yes" : "no")); @@ -3429,11 +3429,11 @@ uint16_t MleRouter::GetNextHop(uint16_t aDestination) nextHop = mRouterTable.GetRouter(router->GetNextHop()); VerifyOrExit(nextHop != NULL && !nextHop->IsStateInvalid()); - rval = GetRloc16(router->GetNextHop()); + rval = Rloc16FromRouterId(router->GetNextHop()); } else if (linkCost < kMaxRouteCost) { - rval = GetRloc16(destinationId); + rval = Rloc16FromRouterId(destinationId); } exit: @@ -3846,7 +3846,7 @@ otError MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus) if (IsRouterIdValid(mPreviousRouterId)) { rlocTlv.Init(); - rlocTlv.SetRloc16(GetRloc16(mPreviousRouterId)); + rlocTlv.SetRloc16(Rloc16FromRouterId(mPreviousRouterId)); SuccessOrExit(error = rlocTlv.AppendTo(*message)); } @@ -3892,7 +3892,7 @@ otError MleRouter::SendAddressRelease(void) SuccessOrExit(error = message->SetPayloadMarker()); rlocTlv.Init(); - rlocTlv.SetRloc16(GetRloc16(mRouterId)); + rlocTlv.SetRloc16(Rloc16FromRouterId(mRouterId)); SuccessOrExit(error = rlocTlv.AppendTo(*message)); macAddr64Tlv.Init(); @@ -3974,7 +3974,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage, // assign short address SetRouterId(routerId); - SetStateRouter(GetRloc16(mRouterId)); + SetStateRouter(Rloc16FromRouterId(mRouterId)); mRouterTable.Clear(); mRouterTable.ProcessTlv(routerMaskTlv); diff --git a/src/core/thread/router_table.cpp b/src/core/thread/router_table.cpp index 08517edc4..cfa1a2731 100644 --- a/src/core/thread/router_table.cpp +++ b/src/core/thread/router_table.cpp @@ -184,7 +184,7 @@ void RouterTable::UpdateAllocation(void) if (router.GetRouterId() != routerId) { router.Clear(); - router.SetRloc16(Mle::Mle::GetRloc16(routerId)); + router.SetRloc16(Mle::Mle::Rloc16FromRouterId(routerId)); router.SetNextHop(Mle::kInvalidRouterId); } } @@ -267,7 +267,7 @@ exit: otError RouterTable::Release(uint8_t aRouterId) { otError error = OT_ERROR_NONE; - uint16_t rloc16 = Mle::Mle::GetRloc16(aRouterId); + uint16_t rloc16 = Mle::Mle::Rloc16FromRouterId(aRouterId); assert(aRouterId <= Mle::kMaxRouterId); @@ -383,7 +383,7 @@ exit: const Router *RouterTable::GetRouter(uint8_t aRouterId) const { const Router *router = NULL; - uint16_t rloc16 = Mle::Mle::GetRloc16(aRouterId); + uint16_t rloc16 = Mle::Mle::Rloc16FromRouterId(aRouterId); for (router = GetFirstEntry(); router != NULL; router = GetNextEntry(router)) { @@ -433,7 +433,7 @@ otError RouterTable::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo memset(&aRouterInfo, 0, sizeof(aRouterInfo)); aRouterInfo.mRouterId = routerId; - aRouterInfo.mRloc16 = Mle::Mle::GetRloc16(routerId); + aRouterInfo.mRloc16 = Mle::Mle::Rloc16FromRouterId(routerId); aRouterInfo.mExtAddress = router->GetExtAddress(); aRouterInfo.mAllocated = true; aRouterInfo.mNextHop = router->GetNextHop();