From fffb489b2694a5f87800367ee4894f8e81fa7006 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 1 Feb 2024 11:28:00 -0800 Subject: [PATCH] [netdata-publisher] remove SRP unicast on anycast entry added by a BR (#9807) This commit updates how the `NetworkData::Publisher` handles "DNS/SRP Service Unicast Address" entries. Specifically, when a "DNS/SRP Service Anycast" entry is added by another BR, the publisher will set the desired count of unicast entries to zero. This effectively removes any previously added unicast entry. This new behavior is only applied when the address and port are included in the Server TLV data in a "DNS/SRP Service Unicast Address" entry. The `test_netdata_publisher` has been updated to verify this new behavior. --- src/core/thread/network_data_publisher.cpp | 21 ++++++++++++- .../thread-cert/test_netdata_publisher.py | 31 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/core/thread/network_data_publisher.cpp b/src/core/thread/network_data_publisher.cpp index 6094eddef..ec925b824 100644 --- a/src/core/thread/network_data_publisher.cpp +++ b/src/core/thread/network_data_publisher.cpp @@ -658,10 +658,29 @@ void Publisher::DnsSrpServiceEntry::Process(void) desiredNumEntries = kDesiredNumAnycast; break; - case kTypeUnicast: case kTypeUnicastMeshLocalEid: + { + Service::DnsSrpAnycast::Info anycastInfo; + CountUnicastEntries(numEntries, numPreferredEntries); desiredNumEntries = kDesiredNumUnicast; + + if (Get().FindPreferredDnsSrpAnycastInfo(anycastInfo) == kErrorNone) + { + // If there is any anycast entry in netdata, we set the + // desired number of unicast entries (with address added + // in server TLV) to zero to remove any added unicast + // entry. + + desiredNumEntries = 0; + } + + break; + } + + case kTypeUnicast: + desiredNumEntries = kDesiredNumUnicast; + CountUnicastEntries(numEntries, numPreferredEntries); break; } diff --git a/tests/scripts/thread-cert/test_netdata_publisher.py b/tests/scripts/thread-cert/test_netdata_publisher.py index f1a1c5d35..7192e6f43 100755 --- a/tests/scripts/thread-cert/test_netdata_publisher.py +++ b/tests/scripts/thread-cert/test_netdata_publisher.py @@ -304,6 +304,37 @@ class NetDataPublisher(thread_cert.TestCase): node.srp_server_set_enabled(False) self.assertEqual(node.srp_server_get_state(), 'disabled') + #--------------------------------------------------------------------------------- + # DNS/SRP unicast and anycast entry + + # Verify that publishing an anycast entry will update the limit + # for the unicast MLE-EID address entry and all are removed. + + num = 0 + for node in routers: + node.netdata_publish_dnssrp_unicast_mleid(DNSSRP_PORT) + self.simulator.go(WAIT_TIME) + num += 1 + services = leader.get_services() + self.assertEqual(len(services), min(num, DESIRED_NUM_DNSSRP_UNCIAST)) + self.verify_unicast_services(services) + + leader.netdata_publish_dnssrp_anycast(ANYCAST_SEQ_NUM) + self.simulator.go(WAIT_TIME) + services = leader.get_services() + self.assertEqual(len(services), 1) + self.verify_anycast_services(services) + + leader.netdata_unpublish_dnssrp() + self.simulator.go(WAIT_TIME) + + services = leader.get_services() + self.assertEqual(len(services), min(num, DESIRED_NUM_DNSSRP_UNCIAST)) + self.verify_unicast_services(services) + + for node in routers: + node.netdata_unpublish_dnssrp() + #--------------------------------------------------------------------------------- # DNS/SRP entries: Verify publisher preference when removing # entries.