Skip to content

Commit 9484449

Browse files
dduttAndryNick98
authored andcommitted
services/lldp: handle cdp/lldp both being present
Signed-off-by: Dinesh Dutt <[email protected]>
1 parent d4cf1bc commit 9484449

File tree

1 file changed

+36
-7
lines changed
  • suzieq/poller/worker/services

1 file changed

+36
-7
lines changed

suzieq/poller/worker/services/lldp.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from typing import Dict, List
23

34
import numpy as np
45

@@ -65,8 +66,8 @@ def _common_cleaner(self, entry):
6566

6667
def _clean_nxos_data(self, processed_data, _):
6768

68-
drop_indices = []
69-
entries = {}
69+
drop_indices: List[int] = []
70+
entries: Dict[str, int] = {}
7071

7172
for i, entry in enumerate(processed_data):
7273
entry['peerHostname'] = re.sub(r'\(.*\)', '',
@@ -88,15 +89,23 @@ def _clean_nxos_data(self, processed_data, _):
8889

8990
entry['ifname'] = expand_nxos_ifname(entry['ifname'])
9091

91-
if entry['ifname'] in entries:
92+
# Handle the case where both LLDP and CDP entries are present.
93+
# Ensure we copy the relvant fields from one into the other.
94+
# key is computed to handle p2mp ports.
95+
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
96+
f'{entry.get("peerIfname")}')
97+
if key in entries:
98+
old_entry = processed_data[entries[key]]
99+
92100
# Description is sometimes filled in with CDP, but not LLDP
93101
if not entry.get('description', ''):
94-
old_entry = processed_data[entries[entry['ifname']]]
95102
entry['description'] = old_entry.get('description', '')
96103
entry['subtype'] = old_entry.get('subtype', '')
97-
drop_indices.append(entries[entry['ifname']])
104+
if not entry.get('peerPlatform', ''):
105+
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
106+
drop_indices.append(entries[key])
98107
else:
99-
entries[entry['ifname']] = i
108+
entries[key] = i
100109

101110
if entry.get('protocol', '') == 'cdp':
102111
entry['subtype'] = 'interface name'
@@ -201,7 +210,9 @@ def _clean_iosxr_data(self, processed_data, _):
201210

202211
def _clean_iosxe_data(self, processed_data, _):
203212

204-
drop_indices = []
213+
drop_indices: List[int] = []
214+
entries: Dict[str, int] = {}
215+
205216
for i, entry in enumerate(processed_data):
206217
entry['peerHostname'] = re.sub(r'\(.*\)', '',
207218
entry['peerHostname'])
@@ -221,6 +232,24 @@ def _clean_iosxe_data(self, processed_data, _):
221232
entry[field] = expand_ios_ifname(entry[field])
222233
if ' ' in entry.get(field, ''):
223234
entry[field] = entry[field].replace(' ', '')
235+
236+
# Handle the case where both LLDP and CDP entries are present.
237+
# Ensure we copy the relvant fields from one into the other.
238+
# key is computed to handle p2mp ports.
239+
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
240+
f'{entry.get("peerIfname")}')
241+
if key in entries:
242+
old_entry = processed_data[entries[key]]
243+
# Description is sometimes filled in with CDP, but not LLDP
244+
if not entry.get('description', ''):
245+
entry['description'] = old_entry.get('description', '')
246+
entry['subtype'] = old_entry.get('subtype', '')
247+
if not entry.get('peerPlatform', ''):
248+
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
249+
drop_indices.append(entries[key])
250+
else:
251+
entries[key] = i
252+
224253
self._common_cleaner(entry)
225254

226255
processed_data = np.delete(processed_data, drop_indices).tolist()

0 commit comments

Comments
 (0)