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

[LLDP] Fix for LLDP advertisements being sent with wrong information. #5493

Merged
merged 7 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions dockers/docker-lldp/lldpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ configure ports eth0 lldp portidsubtype local {{ mgmt_port_name }}
configure system ip management pattern {{ ipv4 }}
{% endif %}
configure system hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
{# pause lldpd operations until all interfaces are well configured, resume command will run in lldpmgrd #}
pause
35 changes: 35 additions & 0 deletions dockers/docker-lldp/lldpmgrd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ try:
import subprocess
import sys

import syslog
import os.path
import time
from sonic_py_common import daemon_base
from swsscommon import swsscommon
except ImportError as err:
Expand All @@ -27,6 +30,7 @@ except ImportError as err:
VERSION = "1.0"

SYSLOG_IDENTIFIER = "lldpmgrd"
PORT_INIT_TIMEOUT = 300


class LldpManager(daemon_base.DaemonBase):
Expand Down Expand Up @@ -166,6 +170,13 @@ class LldpManager(daemon_base.DaemonBase):
# Set select timeout to 10 seconds
SELECT_TIMEOUT_MS = 1000 * 10

# Daemon is paused on the configuration file to avoid lldp packets with wrong information
# until all interfaces are well configured on lldpd
port_init_done = False
port_config_done = False
resume_lldp_sent = False
start_time = time.time()

sel = swsscommon.Select()

# Subscribe to PORT table notifications in the Config DB
Expand Down Expand Up @@ -204,9 +215,21 @@ class LldpManager(daemon_base.DaemonBase):
else:
self.pending_cmds.pop(key, None)

elif key == "PortInitDone":
port_init_done = True
elif key == "PortConfigDone":
port_config_done = True

# Process all pending commands
self.process_pending_cmds()

# Resume the daemon since all interfaces data updated and configured to the lldpd so no miss leading packets will be sent
if port_init_done and port_config_done:
port_init_done = port_config_done = False
resume_lldpd(self)
resume_lldp_sent = True
if not resume_lldp_sent:
check_timeout(self, start_time)

# ============================= Functions =============================

Expand All @@ -219,6 +242,18 @@ def main():

lldpmgr.run()

def resume_lldpd(self):
cmd = "lldpcli resume"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
shlomibitton marked this conversation as resolved.
Show resolved Hide resolved
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
self.log_error("Failed to resume lldpd with command: '{}': {}".format(cmd, stderr))
sys.exit(1)
shlomibitton marked this conversation as resolved.
Show resolved Hide resolved

def check_timeout(self, start_time):
if time.time() - start_time > PORT_INIT_TIMEOUT:
self.log_error("Port init timeout reached ({} seconds), killing lldpmgrd...".format(PORT_INIT_TIMEOUT))
sys.exit(1)
shlomibitton marked this conversation as resolved.
Show resolved Hide resolved

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions src/sonic-config-engine/tests/sample_output/py2/lldpd.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern 10.0.0.100
configure system hostname switch-t0
pause
1 change: 1 addition & 0 deletions src/sonic-config-engine/tests/sample_output/py3/lldpd.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern 10.0.0.100
configure system hostname switch-t0
pause