Skip to content

Commit a65e47f

Browse files
mykolafyxieca
authored andcommitted
[lldpmgr] add mgmt ip to lldpd conf template, handle port description/alias changes (#2396)
* [lldpmgr] add mgmt ip to lldpd conf templte, handle port description/alias config Signed-off-by: Mykola Faryma <[email protected]> * fix typo * [config-engine] update test sample output lldpd.conf Signed-off-by: Mykola Faryma <[email protected]> * fix the log message * fix lldpd.conf.j2
1 parent 24bce77 commit a65e47f

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

dockers/docker-lldp-sv2/lldpd.conf.j2

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{% if MGMT_INTERFACE %}
22
{# If MGMT port alias is available, use it for port ID subtype, otherwise use port name #}
33
{% set mgmt_port_name = MGMT_INTERFACE.keys()[0][0] %}
4+
{% set ipv4 = MGMT_INTERFACE.keys()[0][1].split('/')[0] %}
45
{% if MGMT_PORT and MGMT_PORT[mgmt_port_name] and MGMT_PORT[mgmt_port_name].alias %}
56
configure ports eth0 lldp portidsubtype local {{ MGMT_PORT[mgmt_port_name].alias }}
67
{% else %}
78
configure ports eth0 lldp portidsubtype local {{ mgmt_port_name }}
89
{% endif %}
10+
configure system ip management pattern {{ ipv4 }}
911
{% endif %}

dockers/docker-lldp-sv2/lldpmgrd

+23-28
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ class LldpManager(object):
119119

120120
def generate_pending_lldp_config_cmd_for_port(self, port_name):
121121
"""
122-
For port `port_name`, look up the neighboring device's hostname and
123-
corresponding port alias in the Config database, then form the
124-
appropriate lldpcli configuration command and run it.
122+
For port `port_name`, look up the description and alias in the Config database,
123+
then form the appropriate lldpcli configuration command and run it.
125124
"""
126125
# Retrieve all entires for this port from the Port table
127126
port_table = swsscommon.Table(self.config_db, swsscommon.CFG_PORT_TABLE_NAME)
@@ -135,34 +134,21 @@ class LldpManager(object):
135134
if not port_alias:
136135
log_info("Unable to retrieve port alias for port '{}'. Using port name instead.".format(port_name))
137136
port_alias = port_name
137+
138+
# Get the port description. If None or empty string, we'll skip this configuration
139+
port_desc = port_table_dict.get("description")
140+
138141
else:
139142
log_error("Port '{}' not found in {} table in Config DB. Using port name instead of port alias.".format(port_name, swsscommon.CFG_PORT_TABLE_NAME))
140143
port_alias = port_name
141144

142145
lldpcli_cmd = "lldpcli configure ports {0} lldp portidsubtype local {1}".format(port_name, port_alias)
143146

144-
# Retrieve all entires for this port from the Device Neighbor table
145-
device_neighbor_table = swsscommon.Table(self.config_db, swsscommon.CFG_DEVICE_NEIGHBOR_TABLE_NAME)
146-
(status, fvp) = device_neighbor_table.get(port_name)
147-
if status:
148-
# Convert list of tuples to a dictionary
149-
device_neighbor_table_dict = dict(fvp)
150-
151-
# Get neighbor host name and port name
152-
neighbor_hostname = device_neighbor_table_dict.get("name")
153-
neighbor_portname = device_neighbor_table_dict.get("port")
154-
155-
# If we sucessfully obtained the neighbor's host name and port name, append a port description to the command
156-
if neighbor_hostname and neighbor_portname:
157-
lldpcli_cmd += " description {0}:{1}".format(neighbor_hostname, neighbor_portname)
158-
else:
159-
if not neighbor_hostname:
160-
log_info("Failed to retrieve neighbor host name for port '{}'. Not adding port description.".format(port_name))
161-
162-
if not neighbor_portname:
163-
log_info("Failed to retrieve neighbor port name for port '{}'. Not adding port description.".format(port_name))
147+
# if there is a description available, also configure that
148+
if port_desc:
149+
lldpcli_cmd += " description {}".format(port_desc)
164150
else:
165-
log_info("Unable to retrieve neighbor information for port '{}'. Not adding port description.".format(port_name))
151+
log_info("Unable to retrieve description for port '{}'. Not adding port description".format(port_name))
166152

167153
# Add the command to our dictionary of pending commands, overwriting any
168154
# previous pending command for this port
@@ -200,9 +186,11 @@ class LldpManager(object):
200186

201187
def run(self):
202188
"""
203-
Infinite loop. Subscribes to notifications of changes in the PORT table
204-
of the Redis State database. When we are notified of the creation of an
205-
interface, update LLDP configuration accordingly.
189+
Subscribes to notifications of changes in the PORT table
190+
of the Redis State database.
191+
Subscribe to STATE_DB - get notified of the creation of an interface
192+
Subscribe to CONFIG_DB - get notified of port config changes
193+
Update LLDP configuration accordingly.
206194
"""
207195
# Set select timeout to 10 seconds
208196
SELECT_TIMEOUT_MS = 1000 * 10
@@ -211,8 +199,10 @@ class LldpManager(object):
211199
sel = swsscommon.Select()
212200
sst = swsscommon.SubscriberStateTable(self.state_db, swsscommon.STATE_PORT_TABLE_NAME)
213201
sel.addSelectable(sst)
202+
sst = swsscommon.SubscriberStateTable(self.config_db, swsscommon.CFG_PORT_TABLE_NAME)
203+
sel.addSelectable(sst)
214204

215-
# Listen indefinitely for changes to the PORT table in the State DB
205+
# Listen for changes to the PORT table in the STATE_DB and CONFIG_DB
216206
while True:
217207
(state, c) = sel.select(SELECT_TIMEOUT_MS)
218208

@@ -221,9 +211,14 @@ class LldpManager(object):
221211

222212
fvp_dict = dict(fvp)
223213

214+
# handle creation
224215
if op == "SET" and fvp_dict.get("state") == "ok":
225216
self.generate_pending_lldp_config_cmd_for_port(key)
226217

218+
# handle config change
219+
if op in ["SET", "DEL"] and (fvp_dict.get("alias") or fvp_dict.get("description")) :
220+
self.generate_pending_lldp_config_cmd_for_port(key)
221+
227222
# Process all pending commands
228223
self.process_pending_cmds()
229224

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
configure ports eth0 lldp portidsubtype local eth0
2+
configure system ip management pattern 10.0.0.100
23

0 commit comments

Comments
 (0)