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.