[mesh-local-prefix] remove coupling to Extended PAN ID (#7686)

Deriving the Mesh Local Prefix from the Extended PAN ID was carried
forward from legacy implementations. Removing this coupling to conform
to the existing Thread Specification.
This commit is contained in:
Jonathan Hui
2022-05-11 18:21:09 -07:00
committed by GitHub
parent fcf40d7087
commit c2dd7eb66d
12 changed files with 37 additions and 66 deletions
-4
View File
@@ -63,15 +63,11 @@ otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *a
Error error = kErrorNone;
Instance & instance = AsCoreType(aInstance);
const MeshCoP::ExtendedPanId &extPanId = AsCoreType(aExtendedPanId);
Mle::MeshLocalPrefix prefix;
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
instance.Get<MeshCoP::ExtendedPanIdManager>().SetExtPanId(extPanId);
prefix.SetFromExtendedPanId(extPanId);
instance.Get<Mle::MleRouter>().SetMeshLocalPrefix(prefix);
instance.Get<MeshCoP::ActiveDatasetManager>().Clear();
instance.Get<MeshCoP::PendingDatasetManager>().Clear();
+5 -2
View File
@@ -370,7 +370,10 @@ public:
* @returns The Mesh Local Prefix in the Dataset.
*
*/
const Mle::MeshLocalPrefix &GetMeshLocalPrefix(void) const { return AsCoreType(&mMeshLocalPrefix); }
const Ip6::NetworkPrefix &GetMeshLocalPrefix(void) const
{
return static_cast<const Ip6::NetworkPrefix &>(mMeshLocalPrefix);
}
/**
* This method sets the Mesh Local Prefix in the Dataset.
@@ -378,7 +381,7 @@ public:
* @param[in] aMeshLocalPrefix A Mesh Local Prefix.
*
*/
void SetMeshLocalPrefix(const Mle::MeshLocalPrefix &aMeshLocalPrefix)
void SetMeshLocalPrefix(const Ip6::NetworkPrefix &aMeshLocalPrefix)
{
mMeshLocalPrefix = aMeshLocalPrefix;
mComponents.mIsMeshLocalPrefixPresent = true;
+14 -14
View File
@@ -73,20 +73,20 @@ Error DatasetManager::AppendMleDatasetTlv(Message &aMessage) const
Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
Tlv tlv;
uint16_t offset = aMessage.GetOffset();
bool isUpdateFromCommissioner = false;
bool doesAffectConnectivity = false;
bool doesAffectNetworkKey = false;
bool hasNetworkKey = false;
StateTlv::State state = StateTlv::kReject;
Dataset dataset;
Timestamp activeTimestamp;
ChannelTlv channel;
uint16_t sessionId;
Mle::MeshLocalPrefix meshLocalPrefix;
NetworkKey networkKey;
uint16_t panId;
Tlv tlv;
uint16_t offset = aMessage.GetOffset();
bool isUpdateFromCommissioner = false;
bool doesAffectConnectivity = false;
bool doesAffectNetworkKey = false;
bool hasNetworkKey = false;
StateTlv::State state = StateTlv::kReject;
Dataset dataset;
Timestamp activeTimestamp;
ChannelTlv channel;
uint16_t sessionId;
Ip6::NetworkPrefix meshLocalPrefix;
NetworkKey networkKey;
uint16_t panId;
VerifyOrExit(Get<Mle::MleRouter>().IsLeader());
+4 -4
View File
@@ -682,7 +682,7 @@ private:
*
*/
OT_TOOL_PACKED_BEGIN
class MeshLocalPrefixTlv : public Tlv, public SimpleTlvInfo<Tlv::kMeshLocalPrefix, Mle::MeshLocalPrefix>
class MeshLocalPrefixTlv : public Tlv, public SimpleTlvInfo<Tlv::kMeshLocalPrefix, Ip6::NetworkPrefix>
{
public:
/**
@@ -718,7 +718,7 @@ public:
* @returns The Mesh Local Prefix value.
*
*/
const Mle::MeshLocalPrefix &GetMeshLocalPrefix(void) const { return mMeshLocalPrefix; }
const Ip6::NetworkPrefix &GetMeshLocalPrefix(void) const { return mMeshLocalPrefix; }
/**
* This method sets the Mesh Local Prefix value.
@@ -726,10 +726,10 @@ public:
* @param[in] aMeshLocalPrefix A pointer to the Mesh Local Prefix value.
*
*/
void SetMeshLocalPrefix(const Mle::MeshLocalPrefix &aMeshLocalPrefix) { mMeshLocalPrefix = aMeshLocalPrefix; }
void SetMeshLocalPrefix(const Ip6::NetworkPrefix &aMeshLocalPrefix) { mMeshLocalPrefix = aMeshLocalPrefix; }
private:
Mle::MeshLocalPrefix mMeshLocalPrefix;
Ip6::NetworkPrefix mMeshLocalPrefix;
} OT_TOOL_PACKED_END;
class SteeringData;
+1 -1
View File
@@ -167,7 +167,7 @@ private:
* @param[in] aContextId The 6LoWPAN Context ID.
*
*/
void Set(const Ip6::Prefix &aPrefix, const Mle::MeshLocalPrefix &aMeshLocalPrefix, uint8_t aContextId)
void Set(const Ip6::Prefix &aPrefix, const Ip6::NetworkPrefix &aMeshLocalPrefix, uint8_t aContextId)
{
mPrefix = aPrefix;
+1
View File
@@ -1009,6 +1009,7 @@ private:
} // namespace Ip6
DefineCoreType(otIp6NetworkPrefix, Ip6::NetworkPrefix);
DefineCoreType(otIp6Prefix, Ip6::Prefix);
DefineCoreType(otIp6InterfaceIdentifier, Ip6::InterfaceIdentifier);
DefineCoreType(otIp6Address, Ip6::Address);
+6 -6
View File
@@ -64,6 +64,10 @@ namespace Mle {
RegisterLogModule("Mle");
const otMeshLocalPrefix Mle::sMeshLocalPrefixInit = {
{0xfd, 0xde, 0xad, 0x00, 0xbe, 0xef, 0x00, 0x00},
};
Mle::Mle(Instance &aInstance)
: InstanceLocator(aInstance)
, mRetrieveNewNetworkData(false)
@@ -114,8 +118,6 @@ Mle::Mle(Instance &aInstance)
, mParentResponseCb(nullptr)
, mParentResponseCbContext(nullptr)
{
MeshLocalPrefix meshLocalPrefix;
mParent.Init(aInstance);
mParentCandidate.Init(aInstance);
@@ -130,8 +132,6 @@ Mle::Mle(Instance &aInstance)
mLeaderAloc.InitAsThreadOriginRealmLocalScope();
meshLocalPrefix.SetFromExtendedPanId(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
mMeshLocal64.InitAsThreadOriginRealmLocalScope();
mMeshLocal64.GetAddress().GetIid().GenerateRandom();
@@ -150,7 +150,7 @@ Mle::Mle(Instance &aInstance)
mRealmLocalAllThreadNodes.GetAddress().mFields.m16[0] = HostSwap16(0xff33);
mRealmLocalAllThreadNodes.GetAddress().mFields.m16[7] = HostSwap16(0x0001);
SetMeshLocalPrefix(meshLocalPrefix);
SetMeshLocalPrefix(AsCoreType(&sMeshLocalPrefixInit));
// `SetMeshLocalPrefix()` also adds the Mesh-Local EID and subscribes
// to the Link- and Realm-Local All Thread Nodes multicast addresses.
@@ -823,7 +823,7 @@ void Mle::UpdateLinkLocalAddress(void)
Get<Notifier>().Signal(kEventThreadLinkLocalAddrChanged);
}
void Mle::SetMeshLocalPrefix(const MeshLocalPrefix &aMeshLocalPrefix)
void Mle::SetMeshLocalPrefix(const Ip6::NetworkPrefix &aMeshLocalPrefix)
{
VerifyOrExit(GetMeshLocalPrefix() != aMeshLocalPrefix,
Get<Notifier>().SignalIfFirst(kEventThreadMeshLocalAddrChanged));
+5 -6
View File
@@ -327,10 +327,7 @@ public:
* @returns A reference to the Mesh Local Prefix.
*
*/
const MeshLocalPrefix &GetMeshLocalPrefix(void) const
{
return static_cast<const MeshLocalPrefix &>(mMeshLocal16.GetAddress().GetPrefix());
}
const Ip6::NetworkPrefix &GetMeshLocalPrefix(void) const { return mMeshLocal16.GetAddress().GetPrefix(); }
/**
* This method sets the Mesh Local Prefix.
@@ -338,7 +335,7 @@ public:
* @param[in] aMeshLocalPrefix A reference to the Mesh Local Prefix.
*
*/
void SetMeshLocalPrefix(const MeshLocalPrefix &aMeshLocalPrefix);
void SetMeshLocalPrefix(const Ip6::NetworkPrefix &aMeshLocalPrefix);
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
/**
@@ -1755,7 +1752,7 @@ private:
void MarkAsNotInUse(void) { SetAloc16(kNotInUse); }
uint16_t GetAloc16(void) const { return GetAddress().GetIid().GetLocator(); }
void SetAloc16(uint16_t aAloc16) { GetAddress().GetIid().SetLocator(aAloc16); }
void ApplyMeshLocalPrefix(const MeshLocalPrefix &aPrefix) { GetAddress().SetPrefix(aPrefix); }
void ApplyMeshLocalPrefix(const Ip6::NetworkPrefix &aPrefix) { GetAddress().SetPrefix(aPrefix); }
};
#endif
@@ -1902,6 +1899,8 @@ private:
otMleCounters mCounters;
static const otMeshLocalPrefix sMeshLocalPrefixInit;
Ip6::Netif::UnicastAddress mLinkLocal64;
Ip6::Netif::UnicastAddress mMeshLocal64;
Ip6::Netif::UnicastAddress mMeshLocal16;
-8
View File
@@ -63,13 +63,5 @@ DeviceMode::InfoString DeviceMode::ToString(void) const
return string;
}
void MeshLocalPrefix::SetFromExtendedPanId(const MeshCoP::ExtendedPanId &aExtendedPanId)
{
m8[0] = 0xfd;
memcpy(&m8[1], aExtendedPanId.m8, 5);
m8[6] = 0x00;
m8[7] = 0x00;
}
} // namespace Mle
} // namespace ot
-19
View File
@@ -415,24 +415,6 @@ private:
uint8_t mMode;
};
/**
* This class represents a Mesh Local Prefix.
*
*/
OT_TOOL_PACKED_BEGIN
class MeshLocalPrefix : public Ip6::NetworkPrefix
{
public:
/**
* This method derives and sets the Mesh Local Prefix from an Extended PAN ID.
*
* @param[in] aExtendedPanId An Extended PAN ID.
*
*/
void SetFromExtendedPanId(const MeshCoP::ExtendedPanId &aExtendedPanId);
} OT_TOOL_PACKED_END;
/**
* This class represents the Thread Leader Data.
*
@@ -578,7 +560,6 @@ typedef Mac::Key Key;
} // namespace Mle
DefineCoreType(otMeshLocalPrefix, Mle::MeshLocalPrefix);
DefineCoreType(otLeaderData, Mle::LeaderData);
DefineMapEnum(otDeviceRole, Mle::DeviceRole);
-1
View File
@@ -44,7 +44,6 @@ import simulator
import sniffer
from tlvs_parsing import SubTlvsFactory
# This extended address will generate the MESH_LOCAL_PREFIX
MESH_LOCAL_PREFIX = 'fd00:db8::/64'
MESH_LOCAL_PREFIX_REGEX_PATTERN = '^fd00:0?db8:0{0,4}:0{0,4}'
ROUTING_LOCATOR = '64/:0:ff:fe00:/16'
+1 -1
View File
@@ -106,7 +106,7 @@ static void Init(void)
{
otMeshLocalPrefix meshLocalPrefix = {{0xfd, 0x00, 0xca, 0xfe, 0xfa, 0xce, 0x12, 0x34}};
sInstance->Get<Mle::MleRouter>().SetMeshLocalPrefix(static_cast<Mle::MeshLocalPrefix &>(meshLocalPrefix));
sInstance->Get<Mle::MleRouter>().SetMeshLocalPrefix(static_cast<Ip6::NetworkPrefix &>(meshLocalPrefix));
// Emulate global prefixes with contextes.
uint8_t mockNetworkData[] = {