[netdata] add version number to DNS/SRP service entries (#10752)

This commit adds a version field (`uint8_t`) to DNS/SRP Anycast and
Unicast Service entries in `NetworkData::Service::Manager`.

For Unicast entries, the version the version field is placed after
the existing fields, specifically after the IPv6 address and port number fields.
For Anycast entries it is added as the in server data as part of the
Server TLV.

When processing Network Data service entries, the version field is
optional and if absent, version number zero is assumed.

The `NetworkData::Publisher` now considers entries with the same or
higher version number when deciding whether to add or remove its own
entry, preferring those with a higher version.

In SRP client, when `AutoStart` mode is used and if there are multiple
Unicast, Service entries, the client prefers the one with larger
version number.

When selecting an anycast entry, the existing rules regarding sequence
numbers are still used. If multiple entries with the same sequence
number exist, the client will assume the minimum version number among
all such entries.

This commit also updates the `test_network_data` unit test, validating
the new format and related methods.

`test_netdata_publisher.py` is also updated to check service entries
with different version numbers.
This commit is contained in:
Abtin Keshavarzian
2024-12-23 18:59:06 -08:00
committed by GitHub
parent 588e93cd15
commit 4c378f798d
16 changed files with 611 additions and 241 deletions
+147 -76
View File
@@ -635,6 +635,7 @@ void TestNetworkDataDsnSrpServices(void)
{
uint16_t mAloc16;
uint8_t mSequenceNumber;
uint8_t mVersion;
uint16_t mRloc16;
bool Matches(Service::DnsSrpAnycastInfo aInfo) const
@@ -642,7 +643,8 @@ void TestNetworkDataDsnSrpServices(void)
VerifyOrQuit(aInfo.mAnycastAddress.GetIid().IsAnycastServiceLocator());
return (aInfo.mAnycastAddress.GetIid().GetLocator() == mAloc16) &&
(aInfo.mSequenceNumber == mSequenceNumber) && (aInfo.mRloc16 == mRloc16);
(aInfo.mSequenceNumber == mSequenceNumber) && (aInfo.mVersion == mVersion) &&
(aInfo.mRloc16 == mRloc16);
}
};
@@ -650,6 +652,7 @@ void TestNetworkDataDsnSrpServices(void)
{
const char *mAddress;
uint16_t mPort;
uint8_t mVersion;
uint16_t mRloc16;
bool Matches(const Service::DnsSrpUnicastInfo &aInfo) const
@@ -659,38 +662,50 @@ void TestNetworkDataDsnSrpServices(void)
SuccessOrQuit(sockAddr.GetAddress().FromString(mAddress));
sockAddr.SetPort(mPort);
return (aInfo.mSockAddr == sockAddr) && (aInfo.mRloc16 == mRloc16);
return (aInfo.mSockAddr == sockAddr) && (aInfo.mVersion == mVersion) && (aInfo.mRloc16 == mRloc16);
}
};
const uint8_t kNetworkData[] = {
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x28, 0x00, 0x0b, 0x08, 0x81, 0x02, 0x5c, 0xff, 0x0d,
0x02, 0x6c, 0x00, 0x0b, 0x09, 0x82, 0x02, 0x5c, 0x03, 0x0d, 0x03, 0x4c, 0x00, 0xaa, 0x0b, 0x35, 0x83,
0x13, 0x5d, 0xfd, 0xde, 0xad, 0x00, 0xbe, 0xef, 0x00, 0x00, 0x2d, 0x0e, 0xc6, 0x27, 0x55, 0x56, 0x18,
0xd9, 0x12, 0x34, 0x0d, 0x02, 0x00, 0x00, 0x0d, 0x14, 0x6c, 0x00, 0xfd, 0x00, 0xaa, 0xbb, 0xcc, 0xdd,
0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xab, 0xcd, 0x0d, 0x04, 0x28, 0x00, 0x56,
0x78, 0x0b, 0x23, 0x84, 0x01, 0x5d, 0x0d, 0x02, 0x00, 0x00, 0x0d, 0x14, 0x4c, 0x00, 0xfd, 0x00, 0x12,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0x00, 0x0e, 0x0d, 0x04,
0x6c, 0x00, 0xcd, 0x12, 0x0b, 0x08, 0x84, 0x01, 0x5c, 0x0d, 0x02, 0x14, 0x01, 0x0d, 0x0b, 0x10, 0x83,
0x02, 0x5c, 0xfe, 0x0d, 0x02, 0x12, 0x00, 0x0d, 0x02, 0x12, 0x01, 0x0d, 0x02, 0x16, 0x00,
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x28, 0x00,
0x0b, 0x09, 0x81, 0x02, 0x5c, 0xff, 0x0d, 0x03, 0x6c, 0x00, 0x05,
0x0b, 0x09, 0x82, 0x03, 0x5c, 0x03, 0xaa, 0x0d, 0x02, 0x4c, 0x00,
0x0b, 0x36, 0x83, 0x14, 0x5d, 0xfd, 0xde, 0xad, 0x00, 0xbe, 0xef, 0x00, 0x00, 0x2d,
0x0e, 0xc6, 0x27, 0x55, 0x56, 0x18, 0xd9, 0x12, 0x34, 0x03, 0x0d, 0x02, 0x00, 0x00,
0x0d, 0x14, 0x6c, 0x00, 0xfd, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11,
0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xab, 0xcd, 0x0d, 0x04, 0x28, 0x00, 0x56, 0x78,
0x0b, 0x24, 0x84, 0x01, 0x5d, 0x0d, 0x02, 0x00, 0x00, 0x0d, 0x15, 0x4c, 0x00, 0xfd,
0x00, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x01, 0x23, 0x45, 0x67, 0x89,
0xab, 0x00, 0x0e, 0x01, 0x0d, 0x04, 0x6c, 0x00, 0xcd, 0x12,
0x0b, 0x08, 0x84, 0x01, 0x5c, 0x0d, 0x02, 0x14, 0x01, 0x0d,
0x0b, 0x07, 0x83, 0x01, 0x5c, 0x0d, 0x02, 0x28, 0x00,
0x0b, 0x13, 0x83, 0x02, 0x5c, 0xfe, 0x0d, 0x03, 0x12, 0x00, 0x07, 0x0d, 0x03, 0x12,
0x01, 0x06, 0x0d, 0x03, 0x16, 0x00, 0x07,
};
const AnycastEntry kAnycastEntries[] = {
{0xfc10, 0x02, 0x2800}, {0xfc11, 0xff, 0x6c00}, {0xfc12, 0x03, 0x4c00},
{0xfc13, 0xfe, 0x1200}, {0xfc13, 0xfe, 0x1201}, {0xfc13, 0xfe, 0x1600},
{0xfc10, 0x02, 0, 0x2800}, {0xfc11, 0xff, 5, 0x6c00}, {0xfc12, 0x03, 0, 0x4c00},
{0xfc13, 0xfe, 7, 0x1200}, {0xfc13, 0xfe, 6, 0x1201}, {0xfc13, 0xfe, 7, 0x1600},
};
const UnicastEntry kUnicastEntriesFromServerData[] = {
{"fd00:aabb:ccdd:eeff:11:2233:4455:6677", 0xabcd, 0x6c00},
{"fdde:ad00:beef:0:0:ff:fe00:2800", 0x5678, 0x2800},
{"fd00:1234:5678:9abc:def0:123:4567:89ab", 0x0e, 0x4c00},
{"fdde:ad00:beef:0:0:ff:fe00:6c00", 0xcd12, 0x6c00},
{"fd00:aabb:ccdd:eeff:11:2233:4455:6677", 0xabcd, 0, 0x6c00},
{"fdde:ad00:beef:0:0:ff:fe00:2800", 0x5678, 0, 0x2800},
{"fd00:1234:5678:9abc:def0:123:4567:89ab", 0x0e, 1, 0x4c00},
{"fdde:ad00:beef:0:0:ff:fe00:6c00", 0xcd12, 0, 0x6c00},
};
const UnicastEntry kUnicastEntriesFromServiceData[] = {
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, 0x0000},
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, 0x6c00},
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, 0x2800},
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, 3, 0x0000},
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, 3, 0x6c00},
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, 3, 0x2800},
};
const uint16_t kExpectedRlocs[] = {0x6c00, 0x2800, 0x4c00, 0x0000, 0x1200, 0x1201, 0x1600, 0x1401};
@@ -733,8 +748,9 @@ void TestNetworkDataDsnSrpServices(void)
{
SuccessOrQuit(manager.GetNextDnsSrpAnycastInfo(iterator, anycastInfo));
printf("\nanycastInfo { %s, seq:%d, rlco16:%04x }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber, anycastInfo.mRloc16);
printf("\nanycastInfo { %s, seq:%d, rlco16:%04x, version:%u }",
anycastInfo.mAnycastAddress.ToString().AsCString(), anycastInfo.mSequenceNumber, anycastInfo.mRloc16,
anycastInfo.mVersion);
VerifyOrQuit(entry.Matches(anycastInfo), "GetNextDnsSrpAnycastInfo() returned incorrect info");
}
@@ -746,8 +762,8 @@ void TestNetworkDataDsnSrpServices(void)
SuccessOrQuit(manager.FindPreferredDnsSrpAnycastInfo(anycastInfo));
printf("\n\nPreferred anycastInfo { %s, seq:%d }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber);
printf("\n\nPreferred anycastInfo { %s, seq:%d, version:%u }",
anycastInfo.mAnycastAddress.ToString().AsCString(), anycastInfo.mSequenceNumber, anycastInfo.mVersion);
VerifyOrQuit(kAnycastEntries[kPreferredAnycastEntryIndex].Matches(anycastInfo),
"FindPreferredDnsSrpAnycastInfo() returned invalid info");
@@ -813,6 +829,7 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
const uint8_t *mSeqNumbers;
uint8_t mSeqNumbersLength;
uint8_t mPreferredSeqNum;
uint8_t mPreferredVersion;
};
Instance *instance;
@@ -824,90 +841,99 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
VerifyOrQuit(instance != nullptr);
const uint8_t kNetworkData1[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x81, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x81, 0x0d, 0x02, 0x50, 0x01, // Service TLV
};
const uint8_t kSeqNumbers1[] = {1, 129};
const uint8_t kPreferredSeqNum1 = 129;
const uint8_t kPreferredVer1 = 0;
const uint8_t kNetworkData2[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x85, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x05, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x85, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x05, 0x0d, 0x02, 0x50, 0x01, // Service TLV
};
const uint8_t kSeqNumbers2[] = {133, 5};
const uint8_t kPreferredSeqNum2 = 133;
const uint8_t kPreferredVer2 = 0;
const uint8_t kNetworkData3[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xff, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Service TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xff, 0x0d, 0x02, 0x50, 0x02, // Service TLV
};
const uint8_t kSeqNumbers3[] = {1, 2, 255};
const uint8_t kPreferredSeqNum3 = 2;
const uint8_t kPreferredVer3 = 0;
const uint8_t kNetworkData4[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x82, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x82, 0x0d, 0x02, 0x50, 0x01, // Service TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x02, // Service TLV
};
const uint8_t kSeqNumbers4[] = {10, 130, 250};
const uint8_t kPreferredSeqNum4 = 250;
const uint8_t kPreferredVer4 = 0;
const uint8_t kNetworkData5[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x82, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x82, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x01, // Service TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x02, // Service TLV
};
const uint8_t kSeqNumbers5[] = {130, 250, 10};
const uint8_t kPreferredSeqNum5 = 250;
const uint8_t kPreferredVer5 = 0;
const uint8_t kNetworkData6[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x82, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x01, // Service TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x82, 0x0d, 0x02, 0x50, 0x02, // Service TLV
};
const uint8_t kSeqNumbers6[] = {250, 10, 130};
const uint8_t kPreferredSeqNum6 = 250;
const uint8_t kPreferredVer6 = 0;
const uint8_t kNetworkData7[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x8A, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0xfa, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x0a, 0x0d, 0x02, 0x50, 0x01, // Service TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x8A, 0x0d, 0x02, 0x50, 0x02, // Service TLV
};
const uint8_t kSeqNumbers7[] = {250, 10, 138};
const uint8_t kPreferredSeqNum7 = 250;
const uint8_t kPreferredVer7 = 0;
const uint8_t kNetworkData8[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xff, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x0b, 0x08, 0x83, 0x02, 0x5c, 0xfe, 0x0d, 0x02, 0x50, 0x03, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Service TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xff, 0x0d, 0x02, 0x50, 0x02, // Service TLV
0x0b, 0x08, 0x83, 0x02, 0x5c, 0xfe, 0x0d, 0x02, 0x50, 0x03, // Service TLV
};
const uint8_t kSeqNumbers8[] = {1, 2, 255, 254};
const uint8_t kPreferredSeqNum8 = 2;
const uint8_t kPreferredVer8 = 0;
const uint8_t kNetworkData9[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xff, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x0b, 0x08, 0x83, 0x02, 0x5c, 0xfe, 0x0d, 0x02, 0x50, 0x03, // Server sub-TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Service TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0xff, 0x0d, 0x02, 0x50, 0x02, // Service TLV
0x0b, 0x08, 0x83, 0x02, 0x5c, 0xfe, 0x0d, 0x02, 0x50, 0x03, // Service TLV
};
const uint8_t kSeqNumbers9[] = {1, 2, 255, 254};
const uint8_t kPreferredSeqNum9 = 2;
const uint8_t kPreferredVer9 = 0;
const uint8_t kNetworkData10[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0xfe, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x78, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
@@ -916,9 +942,10 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
};
const uint8_t kSeqNumbers10[] = {254, 2, 120, 1};
const uint8_t kPreferredSeqNum10 = 120;
const uint8_t kPreferredVer10 = 0;
const uint8_t kNetworkData11[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Service TLV
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0xf0, 0x0d, 0x02, 0x50, 0x00, // Server sub-TLV
0x0b, 0x08, 0x81, 0x02, 0x5c, 0x02, 0x0d, 0x02, 0x50, 0x01, // Server sub-TLV
0x0b, 0x08, 0x82, 0x02, 0x5c, 0x78, 0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
@@ -927,19 +954,61 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
};
const uint8_t kSeqNumbers11[] = {240, 2, 120, 1};
const uint8_t kPreferredSeqNum11 = 240;
const uint8_t kPreferredVer11 = 0;
const uint8_t kNetworkData12[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x09, 0x81, 0x02, 0x5c, 0x81, 0x0d, 0x03, 0x50, 0x01, 0x01, // Service TLV
};
const uint8_t kSeqNumbers12[] = {1, 129};
const uint8_t kPreferredSeqNum12 = 129;
const uint8_t kPreferredVer12 = 1;
const uint8_t kNetworkData13[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x08, 0x80, 0x02, 0x5c, 0x01, 0x0d, 0x02, 0x50, 0x00, // Service TLV
0x0b, 0x0e, 0x81, 0x02, 0x5c, 0x81, // Service TLV
0x0d, 0x03, 0x50, 0x01, 0x02, // Server sub-TLV
0x0d, 0x03, 0x50, 0x02, 0x02, // Server sub-TLV
};
const uint8_t kSeqNumbers13[] = {1, 129, 129};
const uint8_t kPreferredSeqNum13 = 129;
const uint8_t kPreferredVer13 = 2;
const uint8_t kNetworkData14[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x13, 0x81, 0x02, 0x5c, 0x07, // Service TLV
0x0d, 0x03, 0x50, 0x00, 0x01, // Server sub-TLV
0x0d, 0x03, 0x50, 0x01, 0x02, // Server sub-TLV
0x0d, 0x03, 0x50, 0x02, 0x03, // Server sub-TLV
};
const uint8_t kSeqNumbers14[] = {7, 7, 7};
const uint8_t kPreferredSeqNum14 = 7;
const uint8_t kPreferredVer14 = 1;
const uint8_t kNetworkData15[] = {
0x08, 0x04, 0x0b, 0x02, 0x50, 0xb0, // Commissioning Data TLV
0x0b, 0x17, 0x81, 0x02, 0x5c, 0x03, // Service TLV
0x0d, 0x03, 0x50, 0x00, 0x01, // Server sub-TLV
0x0d, 0x03, 0x50, 0x01, 0x02, // Server sub-TLV
0x0d, 0x02, 0x50, 0x02, // Server sub-TLV
0x0d, 0x03, 0x50, 0x03, 0x01, // Server sub-TLV
};
const uint8_t kSeqNumbers15[] = {3, 3, 3, 3};
const uint8_t kPreferredSeqNum15 = 3;
const uint8_t kPreferredVer15 = 0;
#define TEST_CASE(Num) \
{ \
kNetworkData##Num, sizeof(kNetworkData##Num), kSeqNumbers##Num, sizeof(kSeqNumbers##Num), \
kPreferredSeqNum##Num, kPreferredVer##Num \
}
const TestInfo kTests[] = {
{kNetworkData1, sizeof(kNetworkData1), kSeqNumbers1, sizeof(kSeqNumbers1), kPreferredSeqNum1},
{kNetworkData2, sizeof(kNetworkData2), kSeqNumbers2, sizeof(kSeqNumbers2), kPreferredSeqNum2},
{kNetworkData3, sizeof(kNetworkData3), kSeqNumbers3, sizeof(kSeqNumbers3), kPreferredSeqNum3},
{kNetworkData4, sizeof(kNetworkData4), kSeqNumbers4, sizeof(kSeqNumbers4), kPreferredSeqNum4},
{kNetworkData5, sizeof(kNetworkData5), kSeqNumbers5, sizeof(kSeqNumbers5), kPreferredSeqNum5},
{kNetworkData6, sizeof(kNetworkData6), kSeqNumbers6, sizeof(kSeqNumbers6), kPreferredSeqNum6},
{kNetworkData7, sizeof(kNetworkData7), kSeqNumbers7, sizeof(kSeqNumbers7), kPreferredSeqNum7},
{kNetworkData8, sizeof(kNetworkData8), kSeqNumbers8, sizeof(kSeqNumbers8), kPreferredSeqNum8},
{kNetworkData9, sizeof(kNetworkData9), kSeqNumbers9, sizeof(kSeqNumbers9), kPreferredSeqNum9},
{kNetworkData10, sizeof(kNetworkData10), kSeqNumbers10, sizeof(kSeqNumbers10), kPreferredSeqNum10},
{kNetworkData11, sizeof(kNetworkData11), kSeqNumbers11, sizeof(kSeqNumbers11), kPreferredSeqNum11},
TEST_CASE(1), TEST_CASE(2), TEST_CASE(3), TEST_CASE(4), TEST_CASE(5),
TEST_CASE(6), TEST_CASE(7), TEST_CASE(8), TEST_CASE(9), TEST_CASE(10),
TEST_CASE(11), TEST_CASE(12), TEST_CASE(13), TEST_CASE(14), TEST_CASE(15),
};
Service::Manager &manager = instance->Get<Service::Manager>();
@@ -959,8 +1028,9 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
{
SuccessOrQuit(manager.GetNextDnsSrpAnycastInfo(iterator, anycastInfo));
printf("\n { %s, seq:%d, rlco16:%04x }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber, anycastInfo.mRloc16);
printf("\n { %s, seq:%u, version:%u, rlco16:%04x }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber, anycastInfo.mVersion, anycastInfo.mRloc16);
VerifyOrQuit(anycastInfo.mSequenceNumber == test.mSeqNumbers[index]);
VerifyOrQuit(anycastInfo.mRloc16 == 0x5000 + index);
@@ -969,8 +1039,9 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
VerifyOrQuit(manager.GetNextDnsSrpAnycastInfo(iterator, anycastInfo) == kErrorNotFound);
SuccessOrQuit(manager.FindPreferredDnsSrpAnycastInfo(anycastInfo));
printf("\n preferred -> seq:%d ", anycastInfo.mSequenceNumber);
printf("\n preferred -> seq:%u, version:%u ", anycastInfo.mSequenceNumber, anycastInfo.mVersion);
VerifyOrQuit(anycastInfo.mSequenceNumber == test.mPreferredSeqNum);
VerifyOrQuit(anycastInfo.mVersion == test.mPreferredVersion);
}
testFreeInstance(instance);