Skip to content

Commit

Permalink
services/lldp: handle cdp/lldp both being present
Browse files Browse the repository at this point in the history
Signed-off-by: Dinesh Dutt <[email protected]>
  • Loading branch information
ddutt authored and AndryNick98 committed May 21, 2024
1 parent d4cf1bc commit 9484449
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions suzieq/poller/worker/services/lldp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from typing import Dict, List

import numpy as np

Expand Down Expand Up @@ -65,8 +66,8 @@ def _common_cleaner(self, entry):

def _clean_nxos_data(self, processed_data, _):

drop_indices = []
entries = {}
drop_indices: List[int] = []
entries: Dict[str, int] = {}

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

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

if entry['ifname'] in entries:
# Handle the case where both LLDP and CDP entries are present.
# Ensure we copy the relvant fields from one into the other.
# key is computed to handle p2mp ports.
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
f'{entry.get("peerIfname")}')
if key in entries:
old_entry = processed_data[entries[key]]

# Description is sometimes filled in with CDP, but not LLDP
if not entry.get('description', ''):
old_entry = processed_data[entries[entry['ifname']]]
entry['description'] = old_entry.get('description', '')
entry['subtype'] = old_entry.get('subtype', '')
drop_indices.append(entries[entry['ifname']])
if not entry.get('peerPlatform', ''):
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
drop_indices.append(entries[key])
else:
entries[entry['ifname']] = i
entries[key] = i

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

def _clean_iosxe_data(self, processed_data, _):

drop_indices = []
drop_indices: List[int] = []
entries: Dict[str, int] = {}

for i, entry in enumerate(processed_data):
entry['peerHostname'] = re.sub(r'\(.*\)', '',
entry['peerHostname'])
Expand All @@ -221,6 +232,24 @@ def _clean_iosxe_data(self, processed_data, _):
entry[field] = expand_ios_ifname(entry[field])
if ' ' in entry.get(field, ''):
entry[field] = entry[field].replace(' ', '')

# Handle the case where both LLDP and CDP entries are present.
# Ensure we copy the relvant fields from one into the other.
# key is computed to handle p2mp ports.
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
f'{entry.get("peerIfname")}')
if key in entries:
old_entry = processed_data[entries[key]]
# Description is sometimes filled in with CDP, but not LLDP
if not entry.get('description', ''):
entry['description'] = old_entry.get('description', '')
entry['subtype'] = old_entry.get('subtype', '')
if not entry.get('peerPlatform', ''):
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
drop_indices.append(entries[key])
else:
entries[key] = i

self._common_cleaner(entry)

processed_data = np.delete(processed_data, drop_indices).tolist()
Expand Down

0 comments on commit 9484449

Please sign in to comment.