Move GetRouterId, GetChildId, GetRloc16, IsActiveRouter to static methods. (#262)

This commit is contained in:
Jonathan Hui
2016-07-12 13:16:42 -07:00
committed by GitHub
parent a36aea4935
commit dec03c3980
4 changed files with 47 additions and 51 deletions
+1 -1
View File
@@ -615,7 +615,7 @@ void Mac::SentFrame(bool aAcked)
if ((neighbor = mMle.GetNeighbor(destination)) != NULL) if ((neighbor = mMle.GetNeighbor(destination)) != NULL)
{ {
if (neighbor->mState == Neighbor::kStateValid && mMle.GetChildId(neighbor->mValid.mRloc16) != 0) if (neighbor->mState == Neighbor::kStateValid && !mMle.IsActiveRouter(neighbor->mValid.mRloc16))
{ {
mNetif.SetStateChangedFlags(OT_THREAD_CHILD_REMOVED); mNetif.SetStateChangedFlags(OT_THREAD_CHILD_REMOVED);
} }
+1 -16
View File
@@ -156,7 +156,7 @@ ThreadError Mle::Start(void)
{ {
BecomeChild(kMleAttachAnyPartition); BecomeChild(kMleAttachAnyPartition);
} }
else if (GetChildId(GetRloc16()) == 0) else if (IsActiveRouter(GetRloc16()))
{ {
mMleRouter.BecomeRouter(); mMleRouter.BecomeRouter();
} }
@@ -372,21 +372,6 @@ ThreadError Mle::SetMeshLocalPrefix(const uint8_t *aMeshLocalPrefix)
return kThreadError_None; return kThreadError_None;
} }
const uint8_t Mle::GetChildId(uint16_t aRloc16) const
{
return aRloc16 & kMaxChildId;
}
const uint8_t Mle::GetRouterId(uint16_t aRloc16) const
{
return aRloc16 >> kRouterIdOffset;
}
const uint16_t Mle::GetRloc16(uint8_t aRouterId) const
{
return static_cast<uint16_t>(aRouterId) << kRouterIdOffset;
}
const Ip6::Address *Mle::GetLinkLocalAllThreadNodesAddress(void) const const Ip6::Address *Mle::GetLinkLocalAllThreadNodesAddress(void) const
{ {
return &mLinkLocalAllThreadNodes.GetAddress(); return &mLinkLocalAllThreadNodes.GetAddress();
+41 -30
View File
@@ -406,36 +406,6 @@ public:
*/ */
ThreadError SetMeshLocalPrefix(const uint8_t *aPrefix); ThreadError SetMeshLocalPrefix(const uint8_t *aPrefix);
/**
* This method returns the Child ID portion of an RLOC16.
*
* @param[in] aRloc16 The RLOC16 value.
*
* @returns The Child ID portion of an RLOC16.
*
*/
const uint8_t GetChildId(uint16_t aRloc16) const;
/**
* This method returns the Router ID portion of an RLOC16.
*
* @param[in] aRloc16 The RLOC16 value.
*
* @returns The Router ID portion of an RLOC16.
*
*/
const uint8_t GetRouterId(uint16_t aRloc16) const;
/**
* This method returns the RLOC16 of a given Router ID.
*
* @param[in] aRouterId The Router ID value..
*
* @returns The RLOC16 of the given Router ID.
*
*/
const uint16_t GetRloc16(uint8_t aRouterId) const;
/** /**
* This method returns a pointer to the link-local all Thread nodes multicast address. * This method returns a pointer to the link-local all Thread nodes multicast address.
* *
@@ -551,6 +521,47 @@ public:
*/ */
ThreadError GetLeaderData(otLeaderData &aLeaderData); ThreadError GetLeaderData(otLeaderData &aLeaderData);
/**
* This method returns the Child ID portion of an RLOC16.
*
* @param[in] aRloc16 The RLOC16 value.
*
* @returns The Child ID portion of an RLOC16.
*
*/
static uint8_t GetChildId(uint16_t aRloc16) { return aRloc16 & kMaxChildId; }
/**
* This method returns the Router ID portion of an 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; }
/**
* This method returns the RLOC16 of a given Router ID.
*
* @param[in] aRouterId The Router ID value.
*
* @returns The RLOC16 of the given Router ID.
*
*/
static uint16_t GetRloc16(uint8_t aRouterId) { return static_cast<uint16_t>(aRouterId) << kRouterIdOffset; }
/**
* This method indicates whether or not @p aRloc16 refers to an active router.
*
* @param[in] aRloc16 The RLOC16 value.
*
* @retval TRUE If @p aRloc16 refers to an active router.
* @retval FALSE If @p aRloc16 does not refer to an active router.
*
*/
static bool IsActiveRouter(uint16_t aRloc16) { return GetChildId(aRloc16) == 0; }
protected: protected:
/** /**
* This method appends an MLE header to a message. * This method appends an MLE header to a message.
+4 -4
View File
@@ -609,7 +609,7 @@ ThreadError MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::Mes
neighbor = NULL; neighbor = NULL;
} }
if (GetChildId(rloc16) == 0) if (IsActiveRouter(rloc16))
{ {
// source is a router // source is a router
neighbor = &mRouters[GetRouterId(rloc16)]; neighbor = &mRouters[GetRouterId(rloc16)];
@@ -678,7 +678,7 @@ ThreadError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, Neig
linkMargin = LinkQualityInfo::ConvertRssToLinkMargin(threadMessageInfo->mRss); linkMargin = LinkQualityInfo::ConvertRssToLinkMargin(threadMessageInfo->mRss);
SuccessOrExit(error = AppendLinkMargin(*message, linkMargin)); SuccessOrExit(error = AppendLinkMargin(*message, linkMargin));
if (aNeighbor != NULL && GetChildId(aNeighbor->mValid.mRloc16) == 0) if (aNeighbor != NULL && IsActiveRouter(aNeighbor->mValid.mRloc16))
{ {
SuccessOrExit(error = AppendLeaderData(*message)); SuccessOrExit(error = AppendLeaderData(*message));
} }
@@ -1152,7 +1152,7 @@ ThreadError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::M
ExitNow(); ExitNow();
} }
VerifyOrExit(GetChildId(sourceAddress.GetRloc16()) == 0, ;); VerifyOrExit(IsActiveRouter(sourceAddress.GetRloc16()), ;);
// Route Data // Route Data
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kRoute, sizeof(route), route)); SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kRoute, sizeof(route), route));
@@ -2343,7 +2343,7 @@ ThreadError MleRouter::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterIn
{ {
ThreadError error = kThreadError_None; ThreadError error = kThreadError_None;
if (aRouterId > kMaxRouterId && GetChildId(aRouterId) == 0) if (aRouterId > kMaxRouterId && IsActiveRouter(aRouterId))
{ {
aRouterId = GetRouterId(aRouterId); aRouterId = GetRouterId(aRouterId);
} }