[netdata] update Publisher to allow change to previous entries (#7827)

This commit updates `NetworkData::Publisher` so that a call to
`PublishOnMeshPrefix()` or `PublishExternalRoute()` replaces a
previous request for the same prefix. In particular, if the new call
only changes the flags (e.g., preference level) and the prefix is
already added in the Network Data, the change to flags is immediately
reflected in the Network Data. This ensures that existing entries in
the Network Data are not abruptly removed. Note that a change in the
preference level can potentially later cause the entry to be removed
from the Network Data after determining there are other nodes that
are publishing the same prefix with the same or higher preference.

This commit also updates `test_netdata_publisher.py` to test the newly
added behavior.
This commit is contained in:
Abtin Keshavarzian
2022-06-22 14:17:28 -07:00
committed by GitHub
parent 64e837861f
commit 5cfbcfcbf4
5 changed files with 102 additions and 28 deletions
@@ -57,10 +57,10 @@ END_DEV5 = 11
WAIT_TIME = 55
ON_MESH_PREFIX = 'fd00:1234::/64'
ON_MESH_PREFIX = 'fd00:1234:0:0::/64'
ON_MESH_FLAGS = 'paso'
EXTERNAL_ROUTE = 'fd00:abce::/64'
EXTERNAL_ROUTE = 'fd00:abce:0:0::/64'
EXTERNAL_FLAGS = 's'
ANYCAST_SEQ_NUM = 4
@@ -444,6 +444,8 @@ class NetDataPublisher(thread_cert.TestCase):
#---------------------------------------------------------------------------------
# External route
# Publish same external route on all nodes with low preference.
num = 0
for node in nodes:
node.netdata_publish_route(EXTERNAL_ROUTE, EXTERNAL_FLAGS, 'low')
@@ -452,12 +454,26 @@ class NetDataPublisher(thread_cert.TestCase):
routes = leader.get_routes()
self.check_num_of_routes(routes, num, 0, 0)
leader.netdata_unpublish_prefix(EXTERNAL_ROUTE)
# Change the preference level of the existing entry on leader to high.
leader.netdata_publish_route(EXTERNAL_ROUTE, EXTERNAL_FLAGS, 'high')
self.simulator.go(WAIT_TIME)
routes = leader.get_routes()
self.check_num_of_routes(routes, num - 1, 0, 1)
# Publish the same prefix on leader as an on-mesh prefix. Make
# sure it is removed from external routes and now seen in the
# prefix list.
leader.netdata_publish_prefix(EXTERNAL_ROUTE, ON_MESH_FLAGS, 'low')
self.simulator.go(WAIT_TIME)
routes = leader.get_routes()
self.check_num_of_routes(routes, num - 1, 0, 0)
prefixes = leader.get_prefixes()
print(prefixes)
self.assertIn(EXTERNAL_ROUTE, [prefix.split()[0] for prefix in prefixes])
if __name__ == '__main__':
unittest.main()