[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:
Abtin Keshavarzian
2024-05-24 20:18:37 -07:00
committed by GitHub
parent 0abc8d7a0d
commit a54f4c4850
3 changed files with 80 additions and 50 deletions
+35
View File
@@ -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