@@ -119,9 +119,8 @@ class LldpManager(object):
119
119
120
120
def generate_pending_lldp_config_cmd_for_port (self , port_name ):
121
121
"""
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.
125
124
"""
126
125
# Retrieve all entires for this port from the Port table
127
126
port_table = swsscommon .Table (self .config_db , swsscommon .CFG_PORT_TABLE_NAME )
@@ -135,34 +134,21 @@ class LldpManager(object):
135
134
if not port_alias :
136
135
log_info ("Unable to retrieve port alias for port '{}'. Using port name instead." .format (port_name ))
137
136
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
+
138
141
else :
139
142
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 ))
140
143
port_alias = port_name
141
144
142
145
lldpcli_cmd = "lldpcli configure ports {0} lldp portidsubtype local {1}" .format (port_name , port_alias )
143
146
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 )
164
150
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 ))
166
152
167
153
# Add the command to our dictionary of pending commands, overwriting any
168
154
# previous pending command for this port
@@ -200,9 +186,11 @@ class LldpManager(object):
200
186
201
187
def run (self ):
202
188
"""
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.
206
194
"""
207
195
# Set select timeout to 10 seconds
208
196
SELECT_TIMEOUT_MS = 1000 * 10
@@ -211,8 +199,10 @@ class LldpManager(object):
211
199
sel = swsscommon .Select ()
212
200
sst = swsscommon .SubscriberStateTable (self .state_db , swsscommon .STATE_PORT_TABLE_NAME )
213
201
sel .addSelectable (sst )
202
+ sst = swsscommon .SubscriberStateTable (self .config_db , swsscommon .CFG_PORT_TABLE_NAME )
203
+ sel .addSelectable (sst )
214
204
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
216
206
while True :
217
207
(state , c ) = sel .select (SELECT_TIMEOUT_MS )
218
208
@@ -221,9 +211,14 @@ class LldpManager(object):
221
211
222
212
fvp_dict = dict (fvp )
223
213
214
+ # handle creation
224
215
if op == "SET" and fvp_dict .get ("state" ) == "ok" :
225
216
self .generate_pending_lldp_config_cmd_for_port (key )
226
217
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
+
227
222
# Process all pending commands
228
223
self .process_pending_cmds ()
229
224
0 commit comments