Add Leader ALOC feature support (#797)

* Add Leader ALOC feature support

* Avoid using leader aloc magic number
This commit is contained in:
Shu Chen
2016-10-13 08:45:34 -07:00
committed by Jonathan Hui
parent 04f13fef8b
commit 2153e51ce5
5 changed files with 131 additions and 5 deletions
+59 -1
View File
@@ -229,6 +229,12 @@ ThreadError Mle::Stop(void)
SetStateDetached();
mNetif.RemoveUnicastAddress(mLinkLocal16);
mNetif.RemoveUnicastAddress(mMeshLocal16);
if (mDeviceState == kDeviceStateLeader)
{
mNetif.RemoveUnicastAddress(mLeaderAloc);
}
mDeviceState = kDeviceStateDisabled;
return kThreadError_None;
}
@@ -354,6 +360,11 @@ ThreadError Mle::SetStateDetached(void)
mNetif.SetStateChangedFlags(OT_NET_ROLE);
}
if (mDeviceState == kDeviceStateLeader)
{
mNetif.RemoveUnicastAddress(mLeaderAloc);
}
mAddressResolver.Clear();
mDeviceState = kDeviceStateDetached;
mParentRequestState = kParentIdle;
@@ -373,6 +384,11 @@ ThreadError Mle::SetStateChild(uint16_t aRloc16)
mNetif.SetStateChangedFlags(OT_NET_ROLE);
}
if (mDeviceState == kDeviceStateLeader)
{
mNetif.RemoveUnicastAddress(mLeaderAloc);
}
SetRloc16(aRloc16);
mDeviceState = kDeviceStateChild;
mParentRequestState = kParentIdle;
@@ -506,6 +522,13 @@ ThreadError Mle::SetMeshLocalPrefix(const uint8_t *aMeshLocalPrefix)
mNetif.AddUnicastAddress(mMeshLocal16);
}
// update Leader ALOC
if (mDeviceState == kDeviceStateLeader)
{
mNetif.RemoveUnicastAddress(mLeaderAloc);
AddLeaderAloc();
}
// Changing the prefix also causes the mesh local address to be different.
mNetif.SetStateChangedFlags(OT_IP6_ML_ADDR_CHANGED);
@@ -596,6 +619,36 @@ exit:
return error;
}
ThreadError Mle::GetLeaderAloc(Ip6::Address &aAddress) const
{
ThreadError error = kThreadError_None;
VerifyOrExit(GetRloc16() != Mac::kShortAddrInvalid, error = kThreadError_Detached);
memcpy(&aAddress, &mMeshLocal16.GetAddress(), 8);
aAddress.mFields.m16[4] = HostSwap16(0x0000);
aAddress.mFields.m16[5] = HostSwap16(0x00ff);
aAddress.mFields.m16[6] = HostSwap16(0xfe00);
aAddress.mFields.m16[7] = HostSwap16(kAloc16Leader);
exit:
return error;
}
ThreadError Mle::AddLeaderAloc(void)
{
ThreadError error = kThreadError_None;
VerifyOrExit(mDeviceState == kDeviceStateLeader, error = kThreadError_InvalidState);
SuccessOrExit(error = GetLeaderAloc(mLeaderAloc.GetAddress()));
error = mNetif.AddUnicastAddress(mLeaderAloc);
exit:
return error;
}
const LeaderDataTlv &Mle::GetLeaderDataTlv(void)
{
mLeaderData.SetDataVersion(mNetworkData.GetVersion());
@@ -2677,7 +2730,12 @@ uint16_t Mle::GetNextHop(uint16_t aDestination) const
bool Mle::IsRoutingLocator(const Ip6::Address &aAddress) const
{
return memcmp(&mMeshLocal16, &aAddress, kRlocPrefixLength) == 0;
return memcmp(&mMeshLocal16, &aAddress, kRlocPrefixLength) == 0 && aAddress.mFields.m8[14] != kAloc16Mask;
}
bool Mle::IsAnycastLocator(const Ip6::Address &aAddress) const
{
return memcmp(&mMeshLocal16, &aAddress, kRlocPrefixLength) == 0 && aAddress.mFields.m8[14] == kAloc16Mask;
}
Router *Mle::GetParent()