Skip to content

Commit

Permalink
[lldp]Fix the issue of only one field lldp_rem_time_mark in APPL_DB
Browse files Browse the repository at this point in the history
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
  • Loading branch information
ZhaohuiS committed Dec 4, 2024
1 parent d5fa793 commit b9245f9
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,25 +390,36 @@ def sync(self, parsed_update):

new, changed, deleted = self.cache_diff(self.interfaces_cache, parsed_update)

# For changed elements, if only lldp_rem_time_mark changed, update its value, otherwise delete and repopulate
for interface in changed:
if re.match(SONIC_ETHERNET_RE_PATTERN, interface) is None:
logger.warning("Ignoring interface '{}'".format(interface))
continue
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
if self.is_only_time_mark_modified(self.interfaces_cache[interface], parsed_update[interface]):
self.db_connector.set(self.db_connector.APPL_DB, table_key, 'lldp_rem_time_mark', parsed_update[interface]['lldp_rem_time_mark'], blocking=True)
logger.debug("Only sync'd interface {} lldp_rem_time_mark: {}".format(interface, parsed_update[interface]['lldp_rem_time_mark']))
else:
if new or deleted:
# If detects any new or deleted interfaces, repopulate for changed interfaces
for interface in changed:
if re.match(SONIC_ETHERNET_RE_PATTERN, interface) is None:
logger.warning("Ignoring interface '{}'".format(interface))
continue
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
self.db_connector.delete(self.db_connector.APPL_DB, table_key)
self.db_connector.hmset(self.db_connector.APPL_DB, table_key, parsed_update[interface])
logger.debug("Sync'd changed interface {} : {}".format(interface, parsed_update[interface]))
logger.info("Force repopulate the changed interface {} : {}".format(interface, parsed_update[interface]))
else:
# For changed elements, if only lldp_rem_time_mark changed, update its value, otherwise delete and repopulate
for interface in changed:
if re.match(SONIC_ETHERNET_RE_PATTERN, interface) is None:
logger.warning("Ignoring interface '{}'".format(interface))
continue
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
if self.is_only_time_mark_modified(self.interfaces_cache[interface], parsed_update[interface]):
self.db_connector.set(self.db_connector.APPL_DB, table_key, 'lldp_rem_time_mark', parsed_update[interface]['lldp_rem_time_mark'], blocking=True)
logger.debug("Only sync'd interface {} lldp_rem_time_mark: {}".format(interface, parsed_update[interface]['lldp_rem_time_mark']))
else:
self.db_connector.delete(self.db_connector.APPL_DB, table_key)
self.db_connector.hmset(self.db_connector.APPL_DB, table_key, parsed_update[interface])
logger.info("Repopulate for changed interface {} : {}".format(interface, parsed_update[interface]))
self.interfaces_cache = parsed_update
# Delete LLDP_ENTRIES which are missing
for interface in deleted:
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
self.db_connector.delete(self.db_connector.APPL_DB, table_key)
logger.debug("Delete table_key: {}".format(table_key))
logger.info("Delete table_key: {}".format(table_key))
# Repopulate LLDP_ENTRY_TABLE by adding new elements
for interface in new:
if re.match(SONIC_ETHERNET_RE_PATTERN, interface) is None:
Expand All @@ -417,4 +428,4 @@ def sync(self, parsed_update):
# port_table_key = LLDP_ENTRY_TABLE:INTERFACE_NAME;
table_key = ':'.join([LldpSyncDaemon.LLDP_ENTRY_TABLE, interface])
self.db_connector.hmset(self.db_connector.APPL_DB, table_key, parsed_update[interface])
logger.debug("Add new interface {} : {}".format(interface, parsed_update[interface]))
logger.info("Add new interface {} : {}".format(interface, parsed_update[interface]))

0 comments on commit b9245f9

Please sign in to comment.