Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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 @@ -259,7 +260,8 @@ 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')
'lldp_loc_sys_desc',
'lldp_loc_man_addr')
parsed_chassis = zip(loc_chassis_keys,
self.parse_chassis(lldp_json['lldp_loc_chassis']
['local-chassis']['chassis']))
Expand All @@ -282,15 +284,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
27 changes: 26 additions & 1 deletion src/lldp_syncd/dbsyncd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import subprocess
import re
from swsssdk import ConfigDBConnector

from sonic_syncd import SonicSyncDaemon
from . import logger

MGMT_INTERFACE_PATTERN = r"MGMT_INTERFACE*"
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MGMT_INTERFACE_PATTERN [](start = 0, length = 22)

not used? #Closed

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


class DBSyncDaemon(SonicSyncDaemon):
"""
Expand All @@ -17,6 +21,7 @@ def __init__(self):
self.config_db.connect()
logger.info("[lldp dbsyncd] Connected to configdb")
self.port_table = {}
self.man_addr = None
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man_addr [](start = 13, length = 8)

not used? #Closed


def run_command(self, command):
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
Expand All @@ -40,16 +45,36 @@ def port_handler(self, key, data):
# update local cache
self.port_table[key] = data

def run(self):
def man_addr_init(self):
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man_addr_init [](start = 8, length = 13)

mgmt_addr_init #Closed


man_table = self.config_db.get_table('MGMT_INTERFACE')
# 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')
# 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()
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

del the empty line? #Closed

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

self.man_addr_init()
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man_addr_init [](start = 13, length = 13)

man_addr_init before subscribe? #Closed


logger.info("[lldp dbsyncd] Subscribed to configdb PORT table")
self.config_db.listen()