[netdata] enhance GetNextDnsSrpAnycastInfo() to include RLOC16 (#10620)

This commit updates `Service::Manager::GetNextDnsSrpAnycastInfo()` to
iterate over Server sub-TLVs and include the RLOC16 of each entry in
the returned `Info` structure. The unit test `test_network_data` is
updated accordingly. This change simplifies the `Publisher` method
used for counting existing anycast entries in the Network Data.
This commit is contained in:
Abtin Keshavarzian
2024-08-20 08:31:02 -07:00
committed by GitHub
parent f127469f7d
commit afac808a81
5 changed files with 68 additions and 49 deletions
+23 -18
View File
@@ -635,13 +635,14 @@ void TestNetworkDataDsnSrpServices(void)
{
uint16_t mAloc16;
uint8_t mSequenceNumber;
uint16_t mRloc16;
bool Matches(Service::DnsSrpAnycast::Info aInfo) const
{
VerifyOrQuit(aInfo.mAnycastAddress.GetIid().IsAnycastServiceLocator());
return (aInfo.mAnycastAddress.GetIid().GetLocator() == mAloc16) &&
(aInfo.mSequenceNumber == mSequenceNumber);
(aInfo.mSequenceNumber == mSequenceNumber) && (aInfo.mRloc16 == mRloc16);
}
};
@@ -663,19 +664,20 @@ void TestNetworkDataDsnSrpServices(void)
};
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, 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,
};
const AnycastEntry kAnycastEntries[] = {
{0xfc10, 0x02},
{0xfc11, 0xff},
{0xfc12, 0x03},
{0xfc10, 0x02, 0x2800}, {0xfc11, 0xff, 0x6c00}, {0xfc12, 0x03, 0x4c00},
{0xfc13, 0xfe, 0x1200}, {0xfc13, 0xfe, 0x1201}, {0xfc13, 0xfe, 0x1600},
};
const UnicastEntry kUnicastEntriesFromServerData[] = {
@@ -691,7 +693,9 @@ void TestNetworkDataDsnSrpServices(void)
{"fdde:ad00:beef:0:2d0e:c627:5556:18d9", 0x1234, 0x2800},
};
const uint16_t kExpectedRlocs[] = {0x6c00, 0x2800, 0x4c00, 0x0000};
const uint16_t kExpectedRlocs[] = {0x6c00, 0x2800, 0x4c00, 0x0000, 0x1200, 0x1201, 0x1600, 0x1401};
const uint16_t kExpectedRouterRlocs[] = {0x6c00, 0x2800, 0x4c00, 0x0000, 0x1200, 0x1600};
const uint16_t kExpectedChildRlocs[] = {0x1201, 0x1401};
const uint8_t kPreferredAnycastEntryIndex = 2;
@@ -712,10 +716,10 @@ void TestNetworkDataDsnSrpServices(void)
VerifyRlocsArray(rlocs, kExpectedRlocs);
instance->Get<Leader>().FindRlocs(kAnyBrOrServer, kRouterRoleOnly, rlocs);
VerifyRlocsArray(rlocs, kExpectedRlocs);
VerifyRlocsArray(rlocs, kExpectedRouterRlocs);
instance->Get<Leader>().FindRlocs(kAnyBrOrServer, kChildRoleOnly, rlocs);
VerifyOrQuit(rlocs.GetLength() == 0);
VerifyRlocsArray(rlocs, kExpectedChildRlocs);
instance->Get<Leader>().FindRlocs(kBrProvidingExternalIpConn, kAnyRole, rlocs);
VerifyOrQuit(rlocs.GetLength() == 0);
@@ -729,8 +733,8 @@ void TestNetworkDataDsnSrpServices(void)
{
SuccessOrQuit(manager.GetNextDnsSrpAnycastInfo(iterator, anycastInfo));
printf("\nanycastInfo { %s, seq:%d }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber);
printf("\nanycastInfo { %s, seq:%d, rlco16:%04x }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber, anycastInfo.mRloc16);
VerifyOrQuit(entry.Matches(anycastInfo), "GetNextDnsSrpAnycastInfo() returned incorrect info");
}
@@ -955,10 +959,11 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
{
SuccessOrQuit(manager.GetNextDnsSrpAnycastInfo(iterator, anycastInfo));
printf("\n { %s, seq:%d }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber);
printf("\n { %s, seq:%d, rlco16:%04x }", anycastInfo.mAnycastAddress.ToString().AsCString(),
anycastInfo.mSequenceNumber, anycastInfo.mRloc16);
VerifyOrQuit(anycastInfo.mSequenceNumber == test.mSeqNumbers[index]);
VerifyOrQuit(anycastInfo.mRloc16 == 0x5000 + index);
}
VerifyOrQuit(manager.GetNextDnsSrpAnycastInfo(iterator, anycastInfo) == kErrorNotFound);