[dataset] remove mType from Dataset (#6831)

This commit is contained in:
Yakun Xu
2021-07-19 22:44:12 -07:00
committed by GitHub
parent 71e00eb20f
commit 2cc89cbfcb
9 changed files with 54 additions and 54 deletions
+1 -1
View File
@@ -876,7 +876,7 @@ otError Dataset::ProcessSet(Arg aArgs[])
} }
{ {
MeshCoP::Dataset dataset(datasetType); MeshCoP::Dataset dataset;
MeshCoP::Dataset::Info datasetInfo; MeshCoP::Dataset::Info datasetInfo;
uint16_t tlvsLength = MeshCoP::Dataset::kMaxSize; uint16_t tlvsLength = MeshCoP::Dataset::kMaxSize;
+11 -13
View File
@@ -150,10 +150,9 @@ exit:
return isSubset; return isSubset;
} }
Dataset::Dataset(Type aType) Dataset::Dataset(void)
: mUpdateTime(0) : mUpdateTime(0)
, mLength(0) , mLength(0)
, mType(aType)
{ {
memset(mTlvs, 0, sizeof(mTlvs)); memset(mTlvs, 0, sizeof(mTlvs));
} }
@@ -263,12 +262,12 @@ void Dataset::ConvertTo(otOperationalDatasetTlvs &aDataset) const
aDataset.mLength = static_cast<uint8_t>(mLength); aDataset.mLength = static_cast<uint8_t>(mLength);
} }
void Dataset::Set(const Dataset &aDataset) void Dataset::Set(Type aType, const Dataset &aDataset)
{ {
memcpy(mTlvs, aDataset.mTlvs, aDataset.mLength); memcpy(mTlvs, aDataset.mTlvs, aDataset.mLength);
mLength = aDataset.mLength; mLength = aDataset.mLength;
if (mType == kActive) if (aType == kActive)
{ {
RemoveTlv(Tlv::kPendingTimestamp); RemoveTlv(Tlv::kPendingTimestamp);
RemoveTlv(Tlv::kDelayTimer); RemoveTlv(Tlv::kDelayTimer);
@@ -372,11 +371,11 @@ Error Dataset::SetFrom(const Info &aDatasetInfo)
return error; return error;
} }
const Timestamp *Dataset::GetTimestamp(void) const const Timestamp *Dataset::GetTimestamp(Type aType) const
{ {
const Timestamp *timestamp = nullptr; const Timestamp *timestamp = nullptr;
if (mType == kActive) if (aType == kActive)
{ {
const ActiveTimestampTlv *tlv = GetTlv<ActiveTimestampTlv>(); const ActiveTimestampTlv *tlv = GetTlv<ActiveTimestampTlv>();
VerifyOrExit(tlv != nullptr); VerifyOrExit(tlv != nullptr);
@@ -393,9 +392,9 @@ exit:
return timestamp; return timestamp;
} }
void Dataset::SetTimestamp(const Timestamp &aTimestamp) void Dataset::SetTimestamp(Type aType, const Timestamp &aTimestamp)
{ {
IgnoreError(SetTlv((mType == kActive) ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp, aTimestamp)); IgnoreError(SetTlv((aType == kActive) ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp, aTimestamp));
} }
Error Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength) Error Dataset::SetTlv(Tlv::Type aType, const void *aValue, uint8_t aLength)
@@ -461,7 +460,7 @@ exit:
return; return;
} }
Error Dataset::AppendMleDatasetTlv(Message &aMessage) const Error Dataset::AppendMleDatasetTlv(Type aType, Message &aMessage) const
{ {
Error error = kErrorNone; Error error = kErrorNone;
Mle::Tlv tlv; Mle::Tlv tlv;
@@ -469,7 +468,7 @@ Error Dataset::AppendMleDatasetTlv(Message &aMessage) const
VerifyOrExit(mLength > 0); VerifyOrExit(mLength > 0);
type = (mType == kActive ? Mle::Tlv::kActiveDataset : Mle::Tlv::kPendingDataset); type = (aType == kActive ? Mle::Tlv::kActiveDataset : Mle::Tlv::kPendingDataset);
tlv.SetType(type); tlv.SetType(type);
tlv.SetLength(static_cast<uint8_t>(mLength) - sizeof(Tlv) - sizeof(Timestamp)); tlv.SetLength(static_cast<uint8_t>(mLength) - sizeof(Tlv) - sizeof(Timestamp));
@@ -477,8 +476,8 @@ Error Dataset::AppendMleDatasetTlv(Message &aMessage) const
for (const Tlv *cur = GetTlvsStart(); cur < GetTlvsEnd(); cur = cur->GetNext()) for (const Tlv *cur = GetTlvsStart(); cur < GetTlvsEnd(); cur = cur->GetNext())
{ {
if (((mType == kActive) && (cur->GetType() == Tlv::kActiveTimestamp)) || if (((aType == kActive) && (cur->GetType() == Tlv::kActiveTimestamp)) ||
((mType == kPending) && (cur->GetType() == Tlv::kPendingTimestamp))) ((aType == kPending) && (cur->GetType() == Tlv::kPendingTimestamp)))
{ {
; // skip Active or Pending Timestamp TLV ; // skip Active or Pending Timestamp TLV
} }
@@ -608,7 +607,6 @@ void Dataset::ConvertToActive(void)
{ {
RemoveTlv(Tlv::kPendingTimestamp); RemoveTlv(Tlv::kPendingTimestamp);
RemoveTlv(Tlv::kDelayTimer); RemoveTlv(Tlv::kDelayTimer);
mType = kActive;
} }
const char *Dataset::TypeToString(Type aType) const char *Dataset::TypeToString(Type aType)
+10 -8
View File
@@ -615,10 +615,8 @@ public:
/** /**
* This constructor initializes the object. * This constructor initializes the object.
* *
* @param[in] aType The type of the dataset, active or pending.
*
*/ */
explicit Dataset(Type aType); Dataset(void);
/** /**
* This method clears the Dataset. * This method clears the Dataset.
@@ -735,18 +733,21 @@ public:
/** /**
* This method returns a reference to the Timestamp. * This method returns a reference to the Timestamp.
* *
* @param[in] aType The type of the dataset, active or pending.
*
* @returns A pointer to the Timestamp. * @returns A pointer to the Timestamp.
* *
*/ */
const Timestamp *GetTimestamp(void) const; const Timestamp *GetTimestamp(Type aType) const;
/** /**
* This method sets the Timestamp value. * This method sets the Timestamp value.
* *
* @param[in] aType The type of the dataset, active or pending.
* @param[in] aTimestamp A Timestamp. * @param[in] aTimestamp A Timestamp.
* *
*/ */
void SetTimestamp(const Timestamp &aTimestamp); void SetTimestamp(Type aType, const Timestamp &aTimestamp);
/** /**
* This method sets a TLV in the Dataset. * This method sets a TLV in the Dataset.
@@ -810,10 +811,11 @@ public:
* If this Dataset is an Active Dataset, any Pending Timestamp and Delay Timer TLVs will be omitted in the copy * If this Dataset is an Active Dataset, any Pending Timestamp and Delay Timer TLVs will be omitted in the copy
* from @p aDataset. * from @p aDataset.
* *
* @param[in] aType The type of the dataset, active or pending.
* @param[in] aDataset The input Dataset. * @param[in] aDataset The input Dataset.
* *
*/ */
void Set(const Dataset &aDataset); void Set(Type aType, const Dataset &aDataset);
/** /**
* This method sets the Dataset from a given structure representation. * This method sets the Dataset from a given structure representation.
@@ -845,13 +847,14 @@ public:
/** /**
* This method appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV. * This method appends the MLE Dataset TLV but excluding MeshCoP Sub Timestamp TLV.
* *
* @param[in] aType The type of the dataset, active or pending.
* @param[in] aMessage A message to append to. * @param[in] aMessage A message to append to.
* *
* @retval kErrorNone Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV. * @retval kErrorNone Successfully append MLE Dataset TLV without MeshCoP Sub Timestamp TLV.
* @retval kErrorNoBufs Insufficient available buffers to append the message with MLE Dataset TLV. * @retval kErrorNoBufs Insufficient available buffers to append the message with MLE Dataset TLV.
* *
*/ */
Error AppendMleDatasetTlv(Message &aMessage) const; Error AppendMleDatasetTlv(Type aType, Message &aMessage) const;
/** /**
* This method applies the Active or Pending Dataset to the Thread interface. * This method applies the Active or Pending Dataset to the Thread interface.
@@ -923,7 +926,6 @@ private:
uint8_t mTlvs[kMaxSize]; ///< The Dataset buffer uint8_t mTlvs[kMaxSize]; ///< The Dataset buffer
TimeMilli mUpdateTime; ///< Local time last updated TimeMilli mUpdateTime; ///< Local time last updated
uint16_t mLength; ///< The number of valid bytes in @var mTlvs uint16_t mLength; ///< The number of valid bytes in @var mTlvs
Type mType; ///< Active or Pending
}; };
/** /**
+6 -6
View File
@@ -77,7 +77,7 @@ Error DatasetLocal::Restore(Dataset &aDataset)
SuccessOrExit(error); SuccessOrExit(error);
mSaved = true; mSaved = true;
timestamp = aDataset.GetTimestamp(); timestamp = aDataset.GetTimestamp(mType);
if (timestamp != nullptr) if (timestamp != nullptr)
{ {
@@ -128,7 +128,7 @@ exit:
Error DatasetLocal::Read(Dataset::Info &aDatasetInfo) const Error DatasetLocal::Read(Dataset::Info &aDatasetInfo) const
{ {
Dataset dataset(mType); Dataset dataset;
Error error; Error error;
aDatasetInfo.Clear(); aDatasetInfo.Clear();
@@ -142,7 +142,7 @@ exit:
Error DatasetLocal::Read(otOperationalDatasetTlvs &aDataset) const Error DatasetLocal::Read(otOperationalDatasetTlvs &aDataset) const
{ {
Dataset dataset(mType); Dataset dataset;
Error error; Error error;
memset(&aDataset, 0, sizeof(aDataset)); memset(&aDataset, 0, sizeof(aDataset));
@@ -157,7 +157,7 @@ exit:
Error DatasetLocal::Save(const Dataset::Info &aDatasetInfo) Error DatasetLocal::Save(const Dataset::Info &aDatasetInfo)
{ {
Error error; Error error;
Dataset dataset(mType); Dataset dataset;
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo)); SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
SuccessOrExit(error = Save(dataset)); SuccessOrExit(error = Save(dataset));
@@ -168,7 +168,7 @@ exit:
Error DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset) Error DatasetLocal::Save(const otOperationalDatasetTlvs &aDataset)
{ {
Dataset dataset(mType); Dataset dataset;
dataset.SetFrom(aDataset); dataset.SetFrom(aDataset);
@@ -194,7 +194,7 @@ Error DatasetLocal::Save(const Dataset &aDataset)
otLogInfoMeshCoP("%s dataset set", Dataset::TypeToString(mType)); otLogInfoMeshCoP("%s dataset set", Dataset::TypeToString(mType));
} }
timestamp = aDataset.GetTimestamp(); timestamp = aDataset.GetTimestamp(mType);
if (timestamp != nullptr) if (timestamp != nullptr)
{ {
+16 -16
View File
@@ -81,7 +81,7 @@ int DatasetManager::Compare(const Timestamp &aTimestamp) const
Error DatasetManager::Restore(void) Error DatasetManager::Restore(void)
{ {
Error error; Error error;
Dataset dataset(GetType()); Dataset dataset;
const Timestamp *timestamp; const Timestamp *timestamp;
mTimer.Stop(); mTimer.Stop();
@@ -90,7 +90,7 @@ Error DatasetManager::Restore(void)
SuccessOrExit(error = mLocal.Restore(dataset)); SuccessOrExit(error = mLocal.Restore(dataset));
timestamp = dataset.GetTimestamp(); timestamp = dataset.GetTimestamp(GetType());
if (timestamp != nullptr) if (timestamp != nullptr)
{ {
@@ -112,7 +112,7 @@ exit:
Error DatasetManager::ApplyConfiguration(void) const Error DatasetManager::ApplyConfiguration(void) const
{ {
Error error; Error error;
Dataset dataset(GetType()); Dataset dataset;
SuccessOrExit(error = Read(dataset)); SuccessOrExit(error = Read(dataset));
SuccessOrExit(error = dataset.ApplyConfiguration(GetInstance())); SuccessOrExit(error = dataset.ApplyConfiguration(GetInstance()));
@@ -142,7 +142,7 @@ Error DatasetManager::Save(const Dataset &aDataset)
int compare; int compare;
bool isNetworkkeyUpdated = false; bool isNetworkkeyUpdated = false;
timestamp = aDataset.GetTimestamp(); timestamp = aDataset.GetTimestamp(GetType());
if (timestamp != nullptr) if (timestamp != nullptr)
{ {
@@ -249,7 +249,7 @@ Error DatasetManager::GetChannelMask(Mac::ChannelMask &aChannelMask) const
Error error; Error error;
const MeshCoP::ChannelMaskTlv *channelMaskTlv; const MeshCoP::ChannelMaskTlv *channelMaskTlv;
uint32_t mask; uint32_t mask;
Dataset dataset(GetType()); Dataset dataset;
SuccessOrExit(error = Read(dataset)); SuccessOrExit(error = Read(dataset));
@@ -275,7 +275,7 @@ void DatasetManager::SendSet(void)
Error error; Error error;
Coap::Message * message = nullptr; Coap::Message * message = nullptr;
Ip6::MessageInfo messageInfo; Ip6::MessageInfo messageInfo;
Dataset dataset(GetType()); Dataset dataset;
VerifyOrExit(!mCoapPending, error = kErrorBusy); VerifyOrExit(!mCoapPending, error = kErrorBusy);
VerifyOrExit(Get<Mle::MleRouter>().IsChild() || Get<Mle::MleRouter>().IsRouter(), error = kErrorInvalidState); VerifyOrExit(Get<Mle::MleRouter>().IsChild() || Get<Mle::MleRouter>().IsRouter(), error = kErrorInvalidState);
@@ -283,7 +283,7 @@ void DatasetManager::SendSet(void)
if (IsActiveDataset()) if (IsActiveDataset())
{ {
Dataset pendingDataset(Dataset::kPending); Dataset pendingDataset;
IgnoreError(Get<PendingDataset>().Read(pendingDataset)); IgnoreError(Get<PendingDataset>().Read(pendingDataset));
const ActiveTimestampTlv *tlv = pendingDataset.GetTlv<ActiveTimestampTlv>(); const ActiveTimestampTlv *tlv = pendingDataset.GetTlv<ActiveTimestampTlv>();
@@ -402,7 +402,7 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
{ {
Error error = kErrorNone; Error error = kErrorNone;
Coap::Message *message; Coap::Message *message;
Dataset dataset(GetType()); Dataset dataset;
IgnoreError(Read(dataset)); IgnoreError(Read(dataset));
@@ -451,7 +451,7 @@ exit:
Error DatasetManager::AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const Error DatasetManager::AppendDatasetToMessage(const Dataset::Info &aDatasetInfo, Message &aMessage) const
{ {
Error error; Error error;
Dataset dataset(GetType()); Dataset dataset;
SuccessOrExit(error = dataset.SetFrom(aDatasetInfo)); SuccessOrExit(error = dataset.SetFrom(aDatasetInfo));
error = aMessage.AppendBytes(dataset.GetBytes(), dataset.GetSize()); error = aMessage.AppendBytes(dataset.GetBytes(), dataset.GetSize());
@@ -670,10 +670,10 @@ exit:
Error ActiveDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength) Error ActiveDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
{ {
Error error = kErrorNone; Error error = kErrorNone;
Dataset dataset(GetType()); Dataset dataset;
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength)); SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
dataset.SetTimestamp(aTimestamp); dataset.SetTimestamp(Dataset::kActive, aTimestamp);
IgnoreError(DatasetManager::Save(dataset)); IgnoreError(DatasetManager::Save(dataset));
exit: exit:
@@ -715,7 +715,7 @@ void PendingDataset::Clear(void)
void PendingDataset::ClearNetwork(void) void PendingDataset::ClearNetwork(void)
{ {
Dataset dataset(GetType()); Dataset dataset;
mTimestamp.Init(); mTimestamp.Init();
mTimestampValid = false; mTimestampValid = false;
@@ -758,10 +758,10 @@ exit:
Error PendingDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength) Error PendingDataset::Save(const Timestamp &aTimestamp, const Message &aMessage, uint16_t aOffset, uint8_t aLength)
{ {
Error error = kErrorNone; Error error = kErrorNone;
Dataset dataset(GetType()); Dataset dataset;
SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength)); SuccessOrExit(error = dataset.Set(aMessage, aOffset, aLength));
dataset.SetTimestamp(aTimestamp); dataset.SetTimestamp(Dataset::kPending, aTimestamp);
IgnoreError(DatasetManager::Save(dataset)); IgnoreError(DatasetManager::Save(dataset));
StartDelayTimer(); StartDelayTimer();
@@ -772,7 +772,7 @@ exit:
void PendingDataset::StartDelayTimer(void) void PendingDataset::StartDelayTimer(void)
{ {
DelayTimerTlv *delayTimer; DelayTimerTlv *delayTimer;
Dataset dataset(GetType()); Dataset dataset;
IgnoreError(Read(dataset)); IgnoreError(Read(dataset));
@@ -801,7 +801,7 @@ void PendingDataset::HandleDelayTimer(Timer &aTimer)
void PendingDataset::HandleDelayTimer(void) void PendingDataset::HandleDelayTimer(void)
{ {
DelayTimerTlv *delayTimer; DelayTimerTlv *delayTimer;
Dataset dataset(GetType()); Dataset dataset;
IgnoreError(Read(dataset)); IgnoreError(Read(dataset));
+6 -6
View File
@@ -61,11 +61,11 @@ namespace MeshCoP {
Error DatasetManager::AppendMleDatasetTlv(Message &aMessage) const Error DatasetManager::AppendMleDatasetTlv(Message &aMessage) const
{ {
Dataset dataset(GetType()); Dataset dataset;
IgnoreError(Read(dataset)); IgnoreError(Read(dataset));
return dataset.AppendMleDatasetTlv(aMessage); return dataset.AppendMleDatasetTlv(GetType(), aMessage);
} }
Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
@@ -79,7 +79,7 @@ Error DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInfo
bool doesAffectNetworkKey = false; bool doesAffectNetworkKey = false;
bool hasNetworkKey = false; bool hasNetworkKey = false;
StateTlv::State state = StateTlv::kReject; StateTlv::State state = StateTlv::kReject;
Dataset dataset(GetType()); Dataset dataset;
ActiveTimestampTlv activeTimestamp; ActiveTimestampTlv activeTimestamp;
PendingTimestampTlv pendingTimestamp; PendingTimestampTlv pendingTimestamp;
@@ -309,7 +309,7 @@ exit:
Error ActiveDataset::GenerateLocal(void) Error ActiveDataset::GenerateLocal(void)
{ {
Error error = kErrorNone; Error error = kErrorNone;
Dataset dataset(GetType()); Dataset dataset;
VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = kErrorInvalidState); VerifyOrExit(Get<Mle::MleRouter>().IsAttached(), error = kErrorInvalidState);
VerifyOrExit(!mLocal.IsTimestampPresent(), error = kErrorAlready); VerifyOrExit(!mLocal.IsTimestampPresent(), error = kErrorAlready);
@@ -457,7 +457,7 @@ exit:
void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Coap::Message &aMessage) void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Coap::Message &aMessage)
{ {
uint16_t offset = aMessage.GetOffset(); uint16_t offset = aMessage.GetOffset();
Dataset dataset(GetType()); Dataset dataset;
VerifyOrExit(Get<Mle::MleRouter>().IsAttached()); VerifyOrExit(Get<Mle::MleRouter>().IsAttached());
@@ -474,7 +474,7 @@ void PendingDataset::ApplyActiveDataset(const Timestamp &aTimestamp, Coap::Messa
IgnoreError(dataset.SetTlv(Tlv::kDelayTimer, Get<Leader>().GetDelayTimerMinimal())); IgnoreError(dataset.SetTlv(Tlv::kDelayTimer, Get<Leader>().GetDelayTimerMinimal()));
// add pending timestamp tlv // add pending timestamp tlv
dataset.SetTimestamp(aTimestamp); dataset.SetTimestamp(Dataset::kPending, aTimestamp);
IgnoreError(DatasetManager::Save(dataset)); IgnoreError(DatasetManager::Save(dataset));
// reset delay timer // reset delay timer
+2 -2
View File
@@ -105,7 +105,7 @@ void DatasetUpdater::HandleTimer(void)
void DatasetUpdater::PreparePendingDataset(void) void DatasetUpdater::PreparePendingDataset(void)
{ {
Dataset dataset(Dataset::kPending); Dataset dataset;
MeshCoP::Dataset::Info requestedDataset; MeshCoP::Dataset::Info requestedDataset;
Error error; Error error;
@@ -145,7 +145,7 @@ void DatasetUpdater::PreparePendingDataset(void)
} }
timestamp.AdvanceRandomTicks(); timestamp.AdvanceRandomTicks();
dataset.SetTimestamp(timestamp); dataset.SetTimestamp(Dataset::kPending, timestamp);
} }
{ {
+1 -1
View File
@@ -314,7 +314,7 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void)
{ {
Error error; Error error;
Coap::Message *message = nullptr; Coap::Message *message = nullptr;
Dataset dataset(Dataset::kActive); Dataset dataset;
NetworkNameTlv networkName; NetworkNameTlv networkName;
const Tlv * tlv; const Tlv * tlv;
+1 -1
View File
@@ -601,7 +601,7 @@ otError RadioSpinel<InterfaceType, ProcessContextType>::ThreadDatasetHandler(con
otOperationalDataset opDataset; otOperationalDataset opDataset;
bool isActive = ((mWaitingKey == SPINEL_PROP_THREAD_ACTIVE_DATASET) ? true : false); bool isActive = ((mWaitingKey == SPINEL_PROP_THREAD_ACTIVE_DATASET) ? true : false);
Spinel::Decoder decoder; Spinel::Decoder decoder;
MeshCoP::Dataset dataset(isActive ? MeshCoP::Dataset::kActive : MeshCoP::Dataset::kPending); MeshCoP::Dataset dataset;
memset(&opDataset, 0, sizeof(otOperationalDataset)); memset(&opDataset, 0, sizeof(otOperationalDataset));
decoder.Init(aBuffer, aLength); decoder.Init(aBuffer, aLength);