mirror of
https://github.com/espressif/openthread.git
synced 2026-08-23 18:59:51 +00:00
[dataset] simplify IsSubsetOf() (#10292)
This commit adds a method `Dataset::IsSubsetOf()` to check whether one dataset is a subset of another. A dataset is considered a subset if all its TLVs, excluding Active/Pending Timestamp and Delay Timer TLVs, are present in the other dataset with exactly matching values. This new method simplifies `Dataset::Info::IsSubsetOf()`. The unit test `test_dataset` is updated to validate the `IsSubsetOf()()` method.
This commit is contained in:
@@ -224,6 +224,41 @@ void TestDataset(void)
|
||||
VerifyOrQuit(memcmp(dataset.GetBytes() + sizeof(kTlvBytes), kTlvBytes, sizeof(kTlvBytes)) == 0);
|
||||
|
||||
VerifyOrQuit(dataset.ValidateTlvs() == kErrorParse);
|
||||
|
||||
// Validate `IsSubsetOf()`
|
||||
|
||||
SuccessOrQuit(dataset.SetFrom(kTlvBytes, sizeof(kTlvBytes)));
|
||||
|
||||
datasetInfo.Clear();
|
||||
datasetInfo.mComponents.mIsPanIdPresent = true;
|
||||
datasetInfo.mComponents.mIsNetworkKeyPresent = true;
|
||||
datasetInfo.mPanId = 0xface;
|
||||
datasetInfo.mNetworkKey = kNetworkKey;
|
||||
|
||||
dataset2.SetFrom(datasetInfo);
|
||||
|
||||
SuccessOrQuit(dataset2.ValidateTlvs());
|
||||
SuccessOrQuit(dataset.ValidateTlvs());
|
||||
|
||||
VerifyOrQuit(dataset2.IsSubsetOf(dataset));
|
||||
VerifyOrQuit(!dataset.IsSubsetOf(dataset2));
|
||||
|
||||
datasetInfo.mComponents.mIsActiveTimestampPresent = true;
|
||||
datasetInfo.mComponents.mIsPendingTimestampPresent = true;
|
||||
datasetInfo.mComponents.mIsDelayPresent = true;
|
||||
datasetInfo.mActiveTimestamp.mSeconds = 0xffff;
|
||||
datasetInfo.mPendingTimestamp.mSeconds = 0x1000;
|
||||
datasetInfo.mDelay = 5000;
|
||||
dataset2.SetFrom(datasetInfo);
|
||||
|
||||
VerifyOrQuit(dataset2.IsSubsetOf(dataset));
|
||||
VerifyOrQuit(!dataset.IsSubsetOf(dataset2));
|
||||
|
||||
datasetInfo.mPanId = 0xcafe;
|
||||
dataset2.SetFrom(datasetInfo);
|
||||
|
||||
VerifyOrQuit(!dataset2.IsSubsetOf(dataset));
|
||||
VerifyOrQuit(!dataset.IsSubsetOf(dataset2));
|
||||
}
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
Reference in New Issue
Block a user