Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 21 additions & 8 deletions src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

SONIC_ETHERNET_RE_PATTERN = r'^(Ethernet(\d+)|eth0)$'
LLDPD_UPTIME_RE_SPLIT_PATTERN = r' days?, '
MANAGEMENT_PORT_NAME = 'eth0'


def parse_time(time_str):
Expand Down Expand Up @@ -145,7 +144,7 @@ def parse_sys_capabilities(self, capability_list, enabled=False):
if (not enabled) or capability["enabled"]:
sys_cap |= 128 >> LldpSystemCapabilitiesMap[capability["type"].lower()]
except KeyError:
logger.warning("Unknown capability {}".format(capability["type"]))
logger.debug("Unknown capability {}".format(capability["type"]))
return "%0.2X 00" % sys_cap

def __init__(self, update_interval=None):
Expand Down Expand Up @@ -235,7 +234,8 @@ def parse_update(self, lldp_json):
rem_chassis_keys = ('lldp_rem_chassis_id_subtype',
'lldp_rem_chassis_id',
'lldp_rem_sys_name',
'lldp_rem_sys_desc')
'lldp_rem_sys_desc',
'lldp_rem_man_addr')
parsed_chassis = zip(rem_chassis_keys,
self.parse_chassis(if_attributes['chassis']))
parsed_interfaces[if_name].update(parsed_chassis)
Expand All @@ -250,7 +250,7 @@ def parse_update(self, lldp_json):
capability_list = self.get_sys_capability_list(if_attributes)
# lldpSysCapSupported
parsed_interfaces[if_name].update({'lldp_rem_sys_cap_supported':
self.parse_sys_capabilities(capability_list)})
self.parse_sys_capabilities(capability_list)})
# lldpSysCapEnabled
parsed_interfaces[if_name].update({'lldp_rem_sys_cap_enabled':
self.parse_sys_capabilities(
Expand All @@ -259,10 +259,21 @@ def parse_update(self, lldp_json):
loc_chassis_keys = ('lldp_loc_chassis_id_subtype',
'lldp_loc_chassis_id',
'lldp_loc_sys_name',
'lldp_loc_sys_desc')
parsed_chassis = zip(loc_chassis_keys,
'lldp_loc_sys_desc',
'lldp_loc_man_addr')
parsed_chassis = dict(zip(loc_chassis_keys,
self.parse_chassis(lldp_json['lldp_loc_chassis']
['local-chassis']['chassis']))
['local-chassis']['chassis'])))

loc_capabilities = self.get_sys_capability_list(lldp_json['lldp_loc_chassis']
['local-chassis'])
# lldpLocSysCapSupported
parsed_chassis.update({'lldp_loc_sys_cap_supported':
self.parse_sys_capabilities(loc_capabilities)})
# lldpLocSysCapEnabled
parsed_chassis.update({'lldp_loc_sys_cap_enabled':
self.parse_sys_capabilities(loc_capabilities, enabled=True)})

parsed_interfaces['local-chassis'].update(parsed_chassis)

return parsed_interfaces
Expand All @@ -282,15 +293,17 @@ def parse_chassis(self, chassis_attributes):
chassis_id_subtype = str(self.ChassisIdSubtypeMap[id_attributes['type']].value)
chassis_id = id_attributes.get('value', '')
descr = attributes.get('descr', '')
mgmt_ip = attributes.get('mgmt-ip', '')
except (KeyError, ValueError):
logger.exception("Could not infer system information from: {}"
.format(chassis_attributes))
chassis_id_subtype = chassis_id = sys_name = descr = ''
chassis_id_subtype = chassis_id = sys_name = descr = mgmt_ip = ''

return (chassis_id_subtype,
chassis_id,
sys_name,
descr,
mgmt_ip,
)

def parse_port(self, port_attributes):
Expand Down
30 changes: 27 additions & 3 deletions src/lldp_syncd/dbsyncd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import subprocess
import re
from swsssdk import ConfigDBConnector

from sonic_syncd import SonicSyncDaemon
from . import logger

PORT_TABLE_NAME = "PORT"
MGMT_INTERFACE_TABLE_NAME = "MGMT_INTERFACE"
IPV4_PATTERN = r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$'


class DBSyncDaemon(SonicSyncDaemon):
"""
Expand Down Expand Up @@ -40,15 +45,34 @@ def port_handler(self, key, data):
# update local cache
self.port_table[key] = data

def run(self):
self.port_table = self.config_db.get_table('PORT')
def mgmt_addr_init(self):

man_table = self.config_db.get_table(MGMT_INTERFACE_TABLE_NAME)
# example table:
# {('eth0', 'FC00:2::32/64'): {'forced_mgmt_routes': ['10.0.0.100/31'], 'gwaddr': 'fc00:2::fe'},
# ('eth0', '10.224.23.69/24'): {'gwaddr': '10.224.23.254'}}
mgmt_ips = [i[1].split('/')[0] for i in man_table.keys()]
ipv4_mgmt_ips = [i for i in mgmt_ips if re.match(IPV4_PATTERN, i)]
try:
self.run_command("lldpcli configure system ip management pattern {}"
.format(ipv4_mgmt_ips[0]))
logger.debug("Configured lldpd with {} local management ip".format(ipv4_mgmt_ips[0]))
except IndexError:
logger.error("No IPv4 management interface found")

def port_table_init(self):
self.port_table = self.config_db.get_table(PORT_TABLE_NAME)
# supply LLDP_LOC_ENTRY_TABLE and lldpd with correct values on start
for port_name, attributes in self.port_table.items():
self.run_command("lldpcli configure lldp portidsubtype local {} description '{}'"
.format(port_name, attributes.get("description", " ")))

def run(self):
self.port_table_init()
self.mgmt_addr_init()

# subscribe for further changes
self.config_db.subscribe('PORT', lambda table, key, data:
self.config_db.subscribe(PORT_TABLE_NAME, lambda table, key, data:
self.port_handler(key, data))

logger.info("[lldp dbsyncd] Subscribed to configdb PORT table")
Expand Down
Loading