[mle] rename static method to RouterIdFromRloc16() from GetRouterId() (#4486)

This commit is contained in:
Abtin Keshavarzian
2020-01-22 20:52:09 -08:00
committed by Jonathan Hui
parent 05747e7670
commit e2403f6066
8 changed files with 31 additions and 30 deletions
+1 -1
View File
@@ -315,7 +315,7 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo)
aParentInfo->mExtAddress = parent->GetExtAddress();
aParentInfo->mRloc16 = parent->GetRloc16();
aParentInfo->mRouterId = Mle::Mle::GetRouterId(parent->GetRloc16());
aParentInfo->mRouterId = Mle::Mle::RouterIdFromRloc16(parent->GetRloc16());
aParentInfo->mNextHop = parent->GetNextHop();
aParentInfo->mPathCost = parent->GetCost();
aParentInfo->mLinkQualityIn = parent->GetLinkInfo().GetLinkQuality();
+1 -1
View File
@@ -97,7 +97,7 @@ void AddressResolver::Remove(uint8_t aRouterId)
{
for (int i = 0; i < kCacheEntries; i++)
{
if (Mle::Mle::GetRouterId(mCache[i].mRloc16) == aRouterId)
if (Mle::Mle::RouterIdFromRloc16(mCache[i].mRloc16) == aRouterId)
{
InvalidateCacheEntry(mCache[i], kReasonRemovingRouterId);
}
+2 -2
View File
@@ -658,12 +658,12 @@ start:
if (hopsLeft != Mle::kMaxRouteCost)
{
hopsLeft += mle.GetLinkCost(Mle::Mle::GetRouterId(mle.GetNextHop(aMeshDest)));
hopsLeft += mle.GetLinkCost(Mle::Mle::RouterIdFromRloc16(mle.GetNextHop(aMeshDest)));
}
else
{
// In case there is no route to the destination router (only link).
hopsLeft = mle.GetLinkCost(Mle::Mle::GetRouterId(aMeshDest));
hopsLeft = mle.GetLinkCost(Mle::Mle::RouterIdFromRloc16(aMeshDest));
}
}
+4 -3
View File
@@ -380,7 +380,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header)
if (mle.IsRoutingLocator(ip6Header.GetDestination()))
{
uint16_t rloc16 = HostSwap16(ip6Header.GetDestination().mFields.m16[7]);
VerifyOrExit(mle.IsRouterIdValid(mle.GetRouterId(rloc16)), error = OT_ERROR_DROP);
VerifyOrExit(mle.IsRouterIdValid(Mle::Mle::RouterIdFromRloc16(rloc16)), error = OT_ERROR_DROP);
mMeshDest = rloc16;
}
else if (mle.IsAnycastLocator(ip6Header.GetDestination()))
@@ -403,7 +403,7 @@ otError MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header)
static_cast<uint8_t>(aloc16 & Mle::kAloc16DhcpAgentMask), agentRloc16) == OT_ERROR_NONE),
error = OT_ERROR_DROP);
routerId = Mle::Mle::GetRouterId(agentRloc16);
routerId = Mle::Mle::RouterIdFromRloc16(agentRloc16);
// if agent is active router or the child of the device
if ((Mle::Mle::IsActiveRouter(agentRloc16)) || (Mle::Mle::Rloc16FromRouterId(routerId) == mle.GetRloc16()))
@@ -614,7 +614,8 @@ void MeshForwarder::UpdateRoutes(uint8_t * aFrame,
neighbor = Get<Mle::MleRouter>().GetNeighbor(ip6Header.GetSource());
VerifyOrExit(neighbor != NULL && !neighbor->IsFullThreadDevice());
if (Mle::Mle::GetRouterId(aMeshSource.GetShort()) != Mle::Mle::GetRouterId(Get<Mac::Mac>().GetShortAddress()))
if (Mle::Mle::RouterIdFromRloc16(aMeshSource.GetShort()) !=
Mle::Mle::RouterIdFromRloc16(Get<Mac::Mac>().GetShortAddress()))
{
Get<Mle::MleRouter>().RemoveNeighbor(*neighbor);
}
+3 -3
View File
@@ -423,7 +423,7 @@ otError Mle::Restore(void)
mParent.SetExtAddress(*static_cast<Mac::ExtAddress *>(&parentInfo.mExtAddress));
mParent.SetDeviceMode(DeviceMode(DeviceMode::kModeFullThreadDevice | DeviceMode::kModeRxOnWhenIdle |
DeviceMode::kModeFullNetworkData | DeviceMode::kModeSecureDataRequest));
mParent.SetRloc16(Rloc16FromRouterId(GetRouterId(networkInfo.mRloc16)));
mParent.SetRloc16(Rloc16FromRouterId(RouterIdFromRloc16(networkInfo.mRloc16)));
mParent.SetState(Neighbor::kStateRestored);
#if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH
@@ -432,7 +432,7 @@ otError Mle::Restore(void)
}
else
{
Get<MleRouter>().SetRouterId(GetRouterId(GetRloc16()));
Get<MleRouter>().SetRouterId(RouterIdFromRloc16(GetRloc16()));
Get<MleRouter>().SetPreviousPartitionId(networkInfo.mPreviousPartitionId);
Get<MleRouter>().RestoreChildren();
}
@@ -3642,7 +3642,7 @@ otError Mle::HandleChildUpdateResponse(const Message & aMessage,
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kSourceAddress, sizeof(sourceAddress), sourceAddress));
VerifyOrExit(sourceAddress.IsValid(), error = OT_ERROR_PARSE);
if (GetRouterId(sourceAddress.GetRloc16()) != GetRouterId(GetRloc16()))
if (RouterIdFromRloc16(sourceAddress.GetRloc16()) != RouterIdFromRloc16(GetRloc16()))
{
BecomeDetached();
ExitNow();
+2 -2
View File
@@ -926,14 +926,14 @@ public:
static uint16_t GetChildId(uint16_t aRloc16) { return aRloc16 & kMaxChildId; }
/**
* This method returns the Router ID portion of an RLOC16.
* This method derives the Router ID portion from a given RLOC16.
*
* @param[in] aRloc16 The RLOC16 value.
*
* @returns The Router ID portion of an RLOC16.
*
*/
static uint8_t GetRouterId(uint16_t aRloc16) { return aRloc16 >> kRouterIdOffset; }
static uint8_t RouterIdFromRloc16(uint16_t aRloc16) { return aRloc16 >> kRouterIdOffset; }
/**
* This method returns whether the two RLOC16 have the same Router ID.
+17 -17
View File
@@ -321,7 +321,7 @@ void MleRouter::SetStateRouter(uint16_t aRloc16)
// remove children that do not have matching RLOC16
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
{
if (GetRouterId(iter.GetChild()->GetRloc16()) != mRouterId)
if (RouterIdFromRloc16(iter.GetChild()->GetRloc16()) != mRouterId)
{
RemoveNeighbor(*iter.GetChild());
}
@@ -358,7 +358,7 @@ void MleRouter::SetStateLeader(uint16_t aRloc16)
// remove children that do not have matching RLOC16
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValidOrRestoring); !iter.IsDone(); iter++)
{
if (GetRouterId(iter.GetChild()->GetRloc16()) != mRouterId)
if (RouterIdFromRloc16(iter.GetChild()->GetRloc16()) != mRouterId)
{
RemoveNeighbor(*iter.GetChild());
}
@@ -605,7 +605,7 @@ otError MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::Message
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);
neighbor = mRouterTable.GetRouter(GetRouterId(rloc16));
neighbor = mRouterTable.GetRouter(RouterIdFromRloc16(rloc16));
VerifyOrExit(neighbor != NULL, error = OT_ERROR_PARSE);
VerifyOrExit(!neighbor->IsStateLinkRequest(), error = OT_ERROR_ALREADY);
@@ -828,7 +828,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
VerifyOrExit(IsActiveRouter(sourceAddress.GetRloc16()), error = OT_ERROR_PARSE);
routerId = GetRouterId(sourceAddress.GetRloc16());
routerId = RouterIdFromRloc16(sourceAddress.GetRloc16());
router = mRouterTable.GetRouter(routerId);
neighborState = (router != NULL) ? router->GetState() : Neighbor::kStateInvalid;
@@ -918,7 +918,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
router = mRouterTable.GetRouter(routerId);
VerifyOrExit(router != NULL);
if (mLeaderData.GetLeaderRouterId() == GetRouterId(GetRloc16()))
if (mLeaderData.GetLeaderRouterId() == RouterIdFromRloc16(GetRloc16()))
{
SetStateLeader(GetRloc16());
}
@@ -1236,7 +1236,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
}
VerifyOrExit(IsActiveRouter(sourceAddress.GetRloc16()) && route.IsValid());
routerId = GetRouterId(sourceAddress.GetRloc16());
routerId = RouterIdFromRloc16(sourceAddress.GetRloc16());
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
Get<TimeSync>().HandleTimeSyncMessage(aMessage);
@@ -1552,7 +1552,7 @@ bool MleRouter::UpdateLinkQualityOut(const RouteTlv &aRoute, Router &aNeighbor,
uint8_t oldLinkCost;
Router *nextHop;
myRouterId = GetRouterId(GetRloc16());
myRouterId = RouterIdFromRloc16(GetRloc16());
VerifyOrExit(aRoute.IsRouterIdSet(myRouterId));
myRouteCount = 0;
@@ -3178,7 +3178,7 @@ bool MleRouter::IsMinimalChild(uint16_t aRloc16)
{
bool rval = false;
if (GetRouterId(aRloc16) == GetRouterId(Get<Mac::Mac>().GetShortAddress()))
if (RouterIdFromRloc16(aRloc16) == RouterIdFromRloc16(Get<Mac::Mac>().GetShortAddress()))
{
Neighbor *neighbor;
@@ -3400,7 +3400,7 @@ exit:
uint16_t MleRouter::GetNextHop(uint16_t aDestination)
{
uint8_t destinationId = GetRouterId(aDestination);
uint8_t destinationId = RouterIdFromRloc16(aDestination);
uint8_t routeCost;
uint8_t linkCost;
uint16_t rval = Mac::kShortAddrInvalid;
@@ -3442,7 +3442,7 @@ exit:
uint8_t MleRouter::GetCost(uint16_t aRloc16)
{
uint8_t routerId = GetRouterId(aRloc16);
uint8_t routerId = RouterIdFromRloc16(aRloc16);
uint8_t cost = GetLinkCost(routerId);
Router *router = mRouterTable.GetRouter(routerId);
uint8_t routeCost;
@@ -3465,7 +3465,7 @@ uint8_t MleRouter::GetRouteCost(uint16_t aRloc16) const
uint8_t rval = kMaxRouteCost;
const Router *router;
router = mRouterTable.GetRouter(GetRouterId(aRloc16));
router = mRouterTable.GetRouter(RouterIdFromRloc16(aRloc16));
VerifyOrExit(router != NULL && mRouterTable.GetRouter(router->GetNextHop()) != NULL);
rval = router->GetCost();
@@ -3761,7 +3761,7 @@ void MleRouter::ResolveRoutingLoops(uint16_t aSourceMac, uint16_t aDestRloc16)
}
// loop exists
router = mRouterTable.GetRouter(GetRouterId(aDestRloc16));
router = mRouterTable.GetRouter(RouterIdFromRloc16(aDestRloc16));
VerifyOrExit(router != NULL);
// invalidate next hop
@@ -3797,7 +3797,7 @@ otError MleRouter::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, I
ExitNow();
}
}
else if (GetRouterId(aMeshDest) == mRouterId)
else if (RouterIdFromRloc16(aMeshDest) == mRouterId)
{
// mesh destination is a child of this device
if (mChildTable.FindChild(aMeshDest, Child::kInStateValidOrRestoring))
@@ -3966,7 +3966,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage,
SuccessOrExit(ThreadTlv::GetTlv(*aMessage, ThreadTlv::kRloc16, sizeof(rlocTlv), rlocTlv));
VerifyOrExit(rlocTlv.IsValid());
routerId = GetRouterId(rlocTlv.GetRloc16());
routerId = RouterIdFromRloc16(rlocTlv.GetRloc16());
SuccessOrExit(ThreadTlv::GetTlv(*aMessage, ThreadTlv::kRouterMask, sizeof(routerMaskTlv), routerMaskTlv));
VerifyOrExit(routerMaskTlv.IsValid());
@@ -3999,7 +3999,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Message * aMessage,
{
// Keep route path to the Leader reported by the parent before it is updated.
leader->SetCost(mParentLeaderCost);
leader->SetNextHop(GetRouterId(mParent.GetRloc16()));
leader->SetNextHop(RouterIdFromRloc16(mParent.GetRloc16()));
}
// send link request
@@ -4081,7 +4081,7 @@ void MleRouter::HandleAddressSolicit(Coap::Message &aMessage, const Ip6::Message
if (ThreadTlv::GetTlv(aMessage, ThreadTlv::kRloc16, sizeof(rlocTlv), rlocTlv) == OT_ERROR_NONE)
{
VerifyOrExit(rlocTlv.IsValid(), error = OT_ERROR_PARSE);
router = mRouterTable.Allocate(GetRouterId(rlocTlv.GetRloc16()));
router = mRouterTable.Allocate(RouterIdFromRloc16(rlocTlv.GetRloc16()));
}
// allocate new router id
@@ -4186,7 +4186,7 @@ void MleRouter::HandleAddressRelease(Coap::Message &aMessage, const Ip6::Message
SuccessOrExit(ThreadTlv::GetTlv(aMessage, ThreadTlv::kExtMacAddress, sizeof(macAddr64Tlv), macAddr64Tlv));
VerifyOrExit(macAddr64Tlv.IsValid());
routerId = GetRouterId(rlocTlv.GetRloc16());
routerId = RouterIdFromRloc16(rlocTlv.GetRloc16());
router = mRouterTable.GetRouter(routerId);
VerifyOrExit(router != NULL && router->GetExtAddress() == macAddr64Tlv.GetMacAddr());
+1 -1
View File
@@ -424,7 +424,7 @@ otError RouterTable::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo
else
{
VerifyOrExit(Mle::Mle::IsActiveRouter(aRouterId), error = OT_ERROR_INVALID_ARGS);
routerId = Mle::Mle::GetRouterId(aRouterId);
routerId = Mle::Mle::RouterIdFromRloc16(aRouterId);
VerifyOrExit(routerId <= Mle::kMaxRouterId, error = OT_ERROR_INVALID_ARGS);
}