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_interfaces - Add support for LLDP TLVs i.e., 'port_vlan_id', 'vlan_name', 'link_aggregation', 'max_frame_size', and 'vlan_name_tlv' attributes (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/406).
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ 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': {
'elements': 'str',
'type': 'list'
}
},
'type': 'dict'
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def get_all_lldp_interfaces(self):
lldp_interface_data = {}
lldp_interface_data['tlv_set'] = {}
lldp_interface_data['tlv_select'] = {}
lldp_interface_data['vlan_name_tlv'] = {}
lldp_interface_data['med_tlv_select'] = {}
lldp_tlv_dict = {}
config = interface.get('config', {})
Expand All @@ -104,6 +105,12 @@ def get_all_lldp_interfaces(self):
lldp_interface_data['med_tlv_select']['network_policy'] = True
lldp_interface_data['med_tlv_select']['power_management'] = True
lldp_interface_data['tlv_select']['power_management'] = True
lldp_interface_data['tlv_select']['port_vlan_id'] = True
lldp_interface_data['tlv_select']['vlan_name'] = True
lldp_interface_data['tlv_select']['link_aggregation'] = True
lldp_interface_data['tlv_select']['max_frame_size'] = True
lldp_interface_data['vlan_name_tlv']['max_tlv_count'] = 10
lldp_interface_data['vlan_name_tlv']['allowed_vlans'] = []
if re.search('Eth', interface['name']):
if 'openconfig-lldp-ext:mode' in config:
lldp_interface_data['mode'] = config.get('openconfig-lldp-ext:mode').lower()
Expand All @@ -116,6 +123,18 @@ def get_all_lldp_interfaces(self):
lldp_interface_data['med_tlv_select']['power_management'] = False
if 'openconfig-lldp-ext:MDI_POWER' in config['openconfig-lldp-ext:suppress-tlv-advertisement']:
lldp_interface_data['tlv_select']['power_management'] = False
if 'openconfig-lldp-ext:PORT_VLAN_ID' in config['openconfig-lldp-ext:suppress-tlv-advertisement']:
lldp_interface_data['tlv_select']['port_vlan_id'] = False
if 'openconfig-lldp-ext:VLAN_NAME' in config['openconfig-lldp-ext:suppress-tlv-advertisement']:
lldp_interface_data['tlv_select']['vlan_name'] = False
if 'openconfig-lldp-ext:LINK_AGGREGATION' in config['openconfig-lldp-ext:suppress-tlv-advertisement']:
lldp_interface_data['tlv_select']['link_aggregation'] = False
if 'openconfig-lldp-ext:MAX_FRAME_SIZE' in config['openconfig-lldp-ext:suppress-tlv-advertisement']:
lldp_interface_data['tlv_select']['max_frame_size'] = False
if 'openconfig-lldp-ext:allowed-vlans' in config:
lldp_interface_data['vlan_name_tlv']['allowed_vlans'] = config.get('openconfig-lldp-ext:allowed-vlans')
if 'openconfig-lldp-ext:vlan-name-tlv-count' in config:
lldp_interface_data['vlan_name_tlv']['max_tlv_count'] = config.get('openconfig-lldp-ext:vlan-name-tlv-count')
if 'openconfig-lldp-ext:management-address-ipv4' in config:
lldp_tlv_dict['ipv4_management_address'] = config.get('openconfig-lldp-ext:management-address-ipv4')
if 'openconfig-lldp-ext:management-address-ipv6' in config:
Expand Down
80 changes: 80 additions & 0 deletions plugins/modules/sonic_lldp_interfaces.py
kerry-meyer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,51 @@
- This command can be used to select whether to advertise power-management
LLDP TLVs or not. By default power-management LLDP TLVs are advertised.
type: bool
port_vlan_id:
description:
- This command can be used to select whether to advertise port-vlan-id
LLDP TLVs or not. By default port-vlan-id LLDP TLVs are advertised.
version_added: '3.1.0'
type: bool
vlan_name:
description:
- This command can be used to select whether to advertise vlan-name
LLDP TLVs or not. By default vlan-name LLDP TLVs are advertised.
version_added: '3.1.0'
type: bool
link_aggregation:
description:
- This command can be used to select whether to advertise link-aggregation
LLDP TLVs or not. By default link-aggregation LLDP TLVs are advertised.
version_added: '3.1.0'
type: bool
max_frame_size:
description:
- This command can be used to select whether to advertise max-frame-size
LLDP TLVs or not. By default max-frame-size LLDP TLVs are advertised.
version_added: '3.1.0'
type: bool
vlan_name_tlv:
description:
- This command can be used to configure the vlan list for the Vlan name TLV advertisement.
- This command is supported only on physical interfaces and not on logical interfaces.
version_added: '3.1.0'
type: dict
suboptions:
max_tlv_count:
description:
- This command can be used to configure the maximum number of Vlan name TLVs
that can be advertised on the interface.
- Range is 1-128 and the default value is 10.
type: int
allowed_vlans:
description:
- This command can be used to configure the vlan list for the Vlan name TLV advertisement.
- Multiple Vlans or Vlan ranges can be configured.
- Ranges are specified by a start and end Vlan value separated by double dots.
- Vlans configured should be in the range 1-4094.
type: list
Copy link
Collaborator

@kerry-meyer kerry-meyer Dec 13, 2024

Choose a reason for hiding this comment

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

Although this is the only case in our collection where a range would be represented in a playbook by ".." instead of "-" and this range delimiter string is never used in the SONiC CLI, I can see the advantage of using it here and I think it is okay.

I am a little bit concerned that users will be confused by this alternate notation, but it is acceptable if the examples clearly illustrate this. (The examples have not yet been updated to this form.)

Please update the examples to show the new format. (Including the use of a list of vlans and ranges for "merged" and "deleted" states).

elements: str
tlv_set:
description:
- This command can be used to configure an IPv4 or IPv6 management address
Expand Down Expand Up @@ -186,6 +231,10 @@
- name: Ethernet1
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
state: deleted
Expand All @@ -207,6 +256,10 @@
# no shutdown
# no lldp med-tlv-select network-policy
# no lldp tlv-select power-management
# no lldp tlv-select port-vlan-id
# no lldp tlv-select vlan-name
# no lldp tlv-select link-aggregation
# no lldp tlv-select max-frame-size
# sonic#


Expand All @@ -223,6 +276,8 @@
# no shutdown
# lldp receive
# lldp tlv-set management-address ipv4 20.1.1.1
# lldp vlan-name-tlv allowed Vlan 10,15-20
# lldp vlan-name-tlv max-tlv-count 15
# !
# interface Ethernet1
# mtu 9100
Expand All @@ -231,6 +286,8 @@
# no shutdown
# lldp transmit
# lldp tlv-set management-address ipv4 21.1.1.1
# lldp vlan-name-tlv allowed Vlan 10,15-20
# lldp vlan-name-tlv max-tlv-count 15
# !
# sonic#

Expand All @@ -251,6 +308,8 @@
# no shutdown
# lldp receive
# lldp tlv-set management-address ipv4 20.1.1.1
# lldp vlan-name-tlv allowed Vlan 10,15-20
# lldp vlan-name-tlv max-tlv-count 15
# !
# interface Ethernet1
# mtu 9100
Expand Down Expand Up @@ -291,6 +350,11 @@
power_management: true
tlv_set:
ipv4_management_address: 10.1.1.2
vlan_name_tlv:
allowed_vlans:
- 10
- '15..20'
max_tlv_count: 15
state: merged

# After State:
Expand All @@ -310,6 +374,8 @@
# no shutdown
# lldp transmit
# lldp tlv-set management-address ipv4 10.1.1.2
# lldp vlan-name-tlv allowed Vlan 10,15-20
# lldp vlan-name-tlv max-tlv-count 15
# sonic#

# Using replaced
Expand All @@ -327,6 +393,8 @@
# lldp tlv-set management-address ipv6 10::1
# no lldp med-tlv-select network-policy
# no lldp med-tlv-select power-management
# lldp vlan-name-tlv allowed Vlan 10,15-20
# lldp vlan-name-tlv max-tlv-count 15
#
# !
# interface Eth1/6
Expand All @@ -346,6 +414,9 @@
ipv6_management_address: '30::1'
med_tlv_select:
network_policy: False
vlan_name_tlv:
allowed_vlans: '20..30'
max_tlv_count: 20
state: replaced

# After State:
Expand All @@ -361,6 +432,8 @@
# lldp receive
# lldp tlv-set management-address ipv6 30::1
# no lldp med-tlv-select network-policy
# lldp vlan-name-tlv allowed Vlan 20-30
# lldp vlan-name-tlv max-tlv-count 20
# !
# interface Eth1/6
# mtu 9100
Expand Down Expand Up @@ -399,6 +472,11 @@
mode: receive
tlv_set:
ipv4_management_address: '10.1.1.2'
vlan_name_tlv:
allowed_vlans:
- 10
- '15..20'
max_tlv_count: 15
state: overridden

# After State:
Expand All @@ -413,6 +491,8 @@
# no shutdown
# lldp receive
# lldp tlv-set management-address ipv4 10.1.1.2
# lldp vlan-name-tlv allowed Vlan 10,15-20
# lldp vlan-name-tlv max-tlv-count 15
# !
# interface Eth1/6
# mtu 9100
Expand Down
32 changes: 32 additions & 0 deletions tests/regression/roles/sonic_lldp_interfaces/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ tests:
ipv6_management_address: '20::1'
tlv_select:
power_management: False
port_vlan_id: False
vlan_name: False
link_aggregation: False
max_frame_size: False
vlan_name_tlv:
allowed_vlans:
- 10
- '15..20'
max_tlv_count: 15

- name: test_case_03
description: Delete default LLDP Interface configurations
Expand Down Expand Up @@ -58,6 +67,15 @@ tests:
med_tlv_select:
network_policy: False
power_management: True
tlv_select:
power_management: False
port_vlan_id: False
vlan_name: False
link_aggregation: False
max_frame_size: False
vlan_name_tlv:
allowed_vlans: ["10", "15"]
max_tlv_count: 15

- name: test_case_05
description: Replace specific LLDP Interface configuration
Expand All @@ -82,6 +100,10 @@ tests:
mode: transmit
tlv_set:
ipv4_management_address: '40.1.1.1'
vlan_name_tlv:
allowed_vlans:
- '30..40'
max_tlv_count: 25

- name: test_case_07
description: Replace specific LLDP Interface configuration
Expand Down Expand Up @@ -109,6 +131,11 @@ tests:
mode: receive
tlv_set:
ipv4_management_address: '30.1.1.2'
vlan_name_tlv:
allowed_vlans:
- 30
- '50..60'
max_tlv_count: 5

- name: test_case_10
description: Override specific LLDP Interface configuration
Expand All @@ -118,6 +145,11 @@ tests:
mode: receive
tlv_set:
ipv4_management_address: '30.1.1.2'
vlan_name_tlv:
allowed_vlans:
- 30
- '50..60'
max_tlv_count: 5

- name: test_case_11
description: Delete default LLDP Interface configurations
Expand Down
Loading
Loading