Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ansible support for LLDP TLVs(port-vlan-id, vlan-name, link-aggregation, maximum-frame-size) #406

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions changelogs/fragments/406-lldp-tlv-support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- sonic_lldp - Enable PVID, Vlan name, Link aggregation, Max-Frame-Size TLV support in LLDP(https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/406).
awhaley-dell marked this conversation as resolved.
Show resolved Hide resolved
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ def __init__(self, **kwargs):
'options': {
'power_management': {
'type': 'bool'
},
'port_vlan_id': {
'type': 'bool'
},
'vlan_name': {
'type': 'bool'
},
'link_aggregation': {
'type': 'bool'
},
'max_frame_size': {
'type': 'bool'
}
},
'type': 'dict'
},
'vlan_name_tlv': {
'options': {
'max_tlv_count': {
'type': 'int'
},
'allowed_vlans': {
'type': 'str'
}
},
'type': 'dict'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Lldp_interfaces(ConfigBase):
'ipv6_management_address': lldp_intf_path + '/config/openconfig-lldp-ext:management-address-ipv6',
'mode': lldp_intf_path + '/config/openconfig-lldp-ext:mode',
'suppress_tlv': lldp_intf_path + '/config/openconfig-lldp-ext:suppress-tlv-advertisement',
'allowed_vlan': lldp_intf_path + '/config/openconfig-lldp-ext:allowed-vlans',
'vlan_name_tlv_count': lldp_intf_path + '/config/openconfig-lldp-ext:vlan-name-tlv-count',
'suppress_tlv_delete': lldp_intf_path + '/config/openconfig-lldp-ext:suppress-tlv-advertisement={med_tlv_select}'
}

Expand All @@ -80,6 +82,24 @@ def get_lldp_interfaces_facts(self):
return []
return lldp_interfaces_facts

def range_to_list(self, vrange):
""" Convert a range of values to a list
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
:rtype: A list
:returns: The list of values
"""
range_list = []
vlist = vrange.split(",")
for v in vlist:
if isinstance(v, int):
range_list.append(v)
elif "-" in v:
ranges = v.split("-")
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
for i in range(int(ranges[0]), int(ranges[1]) + 1):
range_list.append(i)
else:
range_list.append(int(v))
return range_list

def execute_module(self):
""" Execute the module

Expand Down Expand Up @@ -158,6 +178,7 @@ def _state_merged(self, diff):
commands = update_states(commands, 'merged')
else:
commands = []

return commands, requests

def _state_deleted(self, want, have, diff):
Expand Down Expand Up @@ -251,13 +272,33 @@ def _state_overridden(self, want, have, diff):
commands.extend(update_states(diff, 'overridden'))
for cmd in diff:
requests.extend(self.get_modify_specific_lldp_interfaces_param_requests(cmd))

return commands, requests

def get_delete_lldp_interfaces_complete_requests(self, have):
"""Get requests to delete all existing LLDP global
configurations in the chassis
"""
default_dict = {'tlv_select': {'power_management': True}, 'med_tlv_select': {'network_policy': True, 'power_management': True}, 'enable': True}
default_dict = {
'tlv_select':
{
'power_management': True,
'port_vlan_id': True,
'vlan_name': True,
'link_aggregation': True,
'max_frame_size': True
},
'med_tlv_select':
{
'network_policy': True,
'power_management': True
},
'vlan_name_tlv':
{
'max_tlv_count': 10
},
'enable': True
}
requests = []
conf = copy.deepcopy(have)
for cfg in conf:
Expand All @@ -277,6 +318,8 @@ def get_modify_specific_lldp_interfaces_param_requests(self, command):
name = command['name']
ipv6_mgmt_addr = ''
ipv4_mgmt_addr = ''
allowed_vlan = ''
max_tlv_count = ''
if re.search('Eth', name):
if 'mode' in command and command['mode'] is not None:
payload = {'openconfig-lldp-ext:mode': command['mode'].upper()}
Expand All @@ -299,16 +342,65 @@ def get_modify_specific_lldp_interfaces_param_requests(self, command):
payload = {'openconfig-lldp-ext:management-address-ipv6': ipv6_mgmt_addr}
url = self.lldp_intf_config_path['ipv6_management_address'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'vlan_name_tlv' in command and command['vlan_name_tlv'] is not None:
if 'allowed_vlans' in command['vlan_name_tlv'] and command['vlan_name_tlv']['allowed_vlans'] is not None:
allowed_vlan = command['vlan_name_tlv']['allowed_vlans']
if allowed_vlan:
payload = {'openconfig-lldp-ext:allowed-vlans': self.range_to_list(allowed_vlan)}
url = self.lldp_intf_config_path['allowed_vlan'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'max_tlv_count' in command['vlan_name_tlv'] and command['vlan_name_tlv']['max_tlv_count'] is not None:
max_tlv_count = command['vlan_name_tlv']['max_tlv_count']
if max_tlv_count:
payload = {'openconfig-lldp-ext:vlan-name-tlv-count': max_tlv_count}
url = self.lldp_intf_config_path['vlan_name_tlv_count'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'tlv_select' in command and command['tlv_select'] is not None:
tlv = command['tlv_select']['power_management']
if tlv:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="MDI_POWER")
requests.append({'path': url, 'method': DELETE})
else:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["MDI_POWER"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})

if 'power_management' in command['tlv_select'] and command['tlv_select']['power_management'] is not None:
tlv1 = command['tlv_select']['power_management']
if tlv1:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="MDI_POWER")
requests.append({'path': url, 'method': DELETE})
elif tlv1 is False:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["MDI_POWER"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'port_vlan_id' in command['tlv_select'] and command['tlv_select']['port_vlan_id'] is not None:
tlv2 = command['tlv_select']['port_vlan_id']
if tlv2:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="PORT_VLAN_ID")
requests.append({'path': url, 'method': DELETE})
elif tlv2 is False:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["PORT_VLAN_ID"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'vlan_name' in command['tlv_select'] and command['tlv_select']['vlan_name'] is not None:
tlv3 = command['tlv_select']['vlan_name']
if tlv3:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="VLAN_NAME")
requests.append({'path': url, 'method': DELETE})
elif tlv3 is False:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["VLAN_NAME"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'link_aggregation' in command['tlv_select'] and command['tlv_select']['link_aggregation'] is not None:
tlv4 = command['tlv_select']['link_aggregation']
if tlv4:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="LINK_AGGREGATION")
requests.append({'path': url, 'method': DELETE})
elif tlv4 is False:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["LINK_AGGREGATION"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'max_frame_size' in command['tlv_select'] and command['tlv_select']['max_frame_size'] is not None:
tlv5 = command['tlv_select']['max_frame_size']
if tlv5:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="MAX_FRAME_SIZE")
requests.append({'path': url, 'method': DELETE})
elif tlv5 is False:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["MAX_FRAME_SIZE"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
if 'med_tlv_select' in command and command['med_tlv_select'] is not None:
if 'power_management' in command['med_tlv_select'] and command['med_tlv_select']['power_management'] is not None:
med_tlv1 = command['med_tlv_select']['power_management']
Expand Down Expand Up @@ -362,16 +454,59 @@ def get_delete_specific_lldp_interfaces_param_requests(self, command, config):
if command['tlv_set'].get('ipv6_management_address') is not None:
url = self.lldp_intf_config_path['ipv6_management_address'].format(intf_name=name)
requests.append({'path': url, 'method': DELETE})
if 'tlv_select' in command and command['tlv_select'] is not None:
tlv = command['tlv_select'].get('power_management')
if tlv:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["MDI_POWER"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
else:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="MDI_POWER")
if 'vlan_name_tlv' in command and command['vlan_name_tlv'] is not None:
if command['vlan_name_tlv'].get('allowed_vlans') is not None:
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
url = self.lldp_intf_config_path['allowed_vlan'].format(intf_name=name)
requests.append({'path': url, 'method': DELETE})

if command['vlan_name_tlv'].get('max_tlv_count') is not None:
url = self.lldp_intf_config_path['vlan_name_tlv_count'].format(intf_name=name)
requests.append({'path': url, 'method': DELETE})
if 'tlv_select' in command and command['tlv_select'] is not None:
if 'power_management' in command['tlv_select'] and command['tlv_select']['power_management'] is not None:
tlv1 = command['tlv_select']['power_management']
if tlv1:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["MDI_POWER"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
elif tlv1 is False:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="MDI_POWER")
requests.append({'path': url, 'method': DELETE})
if 'port_vlan_id' in command['tlv_select'] and command['tlv_select']['port_vlan_id'] is not None:
tlv2 = command['tlv_select']['port_vlan_id']
if tlv2:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["PORT_VLAN_ID"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
elif tlv2 is False:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="PORT_VLAN_ID")
requests.append({'path': url, 'method': DELETE})
if 'vlan_name' in command['tlv_select'] and command['tlv_select']['vlan_name'] is not None:
tlv3 = command['tlv_select']['vlan_name']
if tlv3:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["VLAN_NAME"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
elif tlv3 is False:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="VLAN_NAME")
requests.append({'path': url, 'method': DELETE})
if 'link_aggregation' in command['tlv_select'] and command['tlv_select']['link_aggregation'] is not None:
tlv4 = command['tlv_select']['link_aggregation']
if tlv4:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["LINK_AGGREGATION"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
elif tlv4 is False:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="LINK_AGGREGATION")
requests.append({'path': url, 'method': DELETE})
if 'max_frame_size' in command['tlv_select'] and command['tlv_select']['max_frame_size'] is not None:
tlv5 = command['tlv_select']['max_frame_size']
if tlv5:
payload = {"openconfig-lldp-ext:suppress-tlv-advertisement": ["MAX_FRAME_SIZE"]}
url = self.lldp_intf_config_path['suppress_tlv'].format(intf_name=name)
requests.append({'path': url, 'method': PATCH, 'data': payload})
elif tlv5 is False:
url = self.lldp_intf_config_path['suppress_tlv_delete'].format(intf_name=name, med_tlv_select="MAX_FRAME_SIZE")
requests.append({'path': url, 'method': DELETE})
if 'med_tlv_select' in command and command['med_tlv_select'] is not None:
if 'power_management' in command['med_tlv_select'] and command['med_tlv_select']['power_management'] is not None:
med_tlv1 = command['med_tlv_select']['power_management']
Expand Down Expand Up @@ -417,7 +552,8 @@ def remove_default_entries(self, data):
default_val_dict = {
'enable': True,
'med_tlv_select': {'network_policy': True, 'power_management': True},
'tlv_select': {'power_management': True}
'tlv_select': {'power_management': True, 'port_vlan_id': True, 'vlan_name': True, 'link_aggregation': True, 'max_frame_size': True},
'vlan_name_tlv': {'max_tlv_count': 10}
}
for intf_conf in data:
default_val_dict['name'] = intf_conf['name']
Expand Down
Loading
Loading