Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle port deletion while updating lldp #66

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions dockers/docker-lldp-sv2/lldpmgrd
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ class LldpManager(object):
True)

self.pending_cmds = {}
self.config_port_names = set()
self.app_port_names = set()

def is_port_up(self, port_name):
"""
Determine if a port is up or down by looking into the oper-status for the port in
Determine if a port is up or down by looking into the oper-status for the port in
PORT TABLE in the Application DB
"""
# Retrieve all entires for this port from the Port table
Expand Down Expand Up @@ -141,8 +143,8 @@ class LldpManager(object):
if not port_alias:
log_info("Unable to retrieve port alias for port '{}'. Using port name instead.".format(port_name))
port_alias = port_name
# Get the port description. If None or empty string, we'll skip this configuration

# Get the port description. If None or empty string, we'll skip this configuration
port_desc = port_table_dict.get("description")

else:
Expand Down Expand Up @@ -208,32 +210,43 @@ class LldpManager(object):
sel.addSelectable(sst_appdb)

# Listen for changes to the PORT table in the CONFIG_DB and APP_DB
# Only when port is present in both DBs and the operation status is UP
# we are going to configure it in lldp
while True:
(state, c) = sel.select(SELECT_TIMEOUT_MS)

if state == swsscommon.Select.OBJECT:

# handle alias or description changes, by listening to
# changes in config DB
(key, op, fvp) = sst_confdb.pop()
if fvp:
fvp_dict = dict(fvp)
if op == "DEL":
self.config_port_names.discard(key)
zhenggen-xu marked this conversation as resolved.
Show resolved Hide resolved
self.pending_cmds.pop(key, None)
elif op == "SET":
self.config_port_names.add(key)
if fvp and key in self.app_port_names:
fvp_dict = dict(fvp)

# handle config change
if (fvp_dict.has_key("alias") or fvp_dict.has_key("description")) and (op in ["SET", "DEL"]):
if self.is_port_up(key):
if (fvp_dict.has_key("alias") or fvp_dict.has_key("description")) and (self.is_port_up(key)):
self.generate_pending_lldp_config_cmd_for_port(key)
else:
self.pending_cmds.pop(key, None)

# handle port status change, by listening to
# changes in APP DB
(key, op, fvp) = sst_appdb.pop()
if (key != "PortInitDone") and (key != "PortConfigDone"):
if fvp:
fvp_dict = dict(fvp)

# handle port status change
if fvp_dict.has_key("oper_status"):
if "up" in fvp_dict.get("oper_status"):
self.generate_pending_lldp_config_cmd_for_port(key)
else:
self.pending_cmds.pop(key, None)
if op == "DEL":
self.app_port_names.discard(key)
self.pending_cmds.pop(key, None)
elif op == "SET":
self.app_port_names.add(key)
if fvp and key in self.config_port_names:
fvp_dict = dict(fvp)

# handle port status change
if fvp_dict.has_key("oper_status"):
if "up" in fvp_dict.get("oper_status"):
self.generate_pending_lldp_config_cmd_for_port(key)

# Process all pending commands
self.process_pending_cmds()
Expand Down