[sonic-py-common] Add interface utilities (#5113)

* Add sonic_interface.py in sonic-py-common for sonic interface utilities to keep this SONIC PREFIX naming convention in one place in py-common and all modules/applications use the functions defined here.
This commit is contained in:
judyjoseph 2020-08-18 10:20:26 -07:00 committed by GitHub
parent 4487abdfcb
commit 52fe7ae365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 3 deletions

View File

@ -15,6 +15,7 @@ from lxml.etree import QName
from portconfig import get_port_config
from sonic_py_common.multi_asic import get_asic_id_from_name
from sonic_py_common.interface import backplane_prefix
"""minigraph.py
version_added: "1.9"
@ -37,7 +38,6 @@ VLAN_SUB_INTERFACE_VLAN_ID = '10'
FRONTEND_ASIC_SUB_ROLE = 'FrontEnd'
BACKEND_ASIC_SUB_ROLE = 'BackEnd'
BACKEND_ASIC_INTERFACE_NAME_PREFIX = 'Ethernet-BP'
# Default Virtual Network Index (VNI)
vni_default = 8000
@ -729,7 +729,7 @@ def filter_acl_table_bindings(acls, neighbors, port_channels, sub_role):
# architecture
for port_channel_intf in port_channels:
backend_port_channel = any(lag_member in port_alias_asic_map \
and lag_member.startswith(BACKEND_ASIC_INTERFACE_NAME_PREFIX) \
and lag_member.startswith(backplane_prefix()) \
for lag_member in port_channels[port_channel_intf]['members'])
if not backend_port_channel:
front_port_channel_intf.append(port_channel_intf)
@ -751,7 +751,7 @@ def filter_acl_table_bindings(acls, neighbors, port_channels, sub_role):
# This will be applicable in Multi-NPU Platforms.
front_panel_ports = []
for port in group_params.get('ports', []):
if port in port_alias_asic_map and port.startswith(BACKEND_ASIC_INTERFACE_NAME_PREFIX):
if port in port_alias_asic_map and port.startswith(backplane_prefix()):
continue
if port in port_channels and port not in front_port_channel_intf:
continue

View File

@ -0,0 +1,43 @@
"""
Dictionary of SONIC interface name prefixes. Each entry in the format
"Human readable interface string":"Sonic interface prefix"
Currently this is a static mapping, but in future could be stored as metadata in DB.
"""
SONIC_INTERFACE_PREFIXES = {
"Ethernet-FrontPanel": "Ethernet",
"PortChannel": "PortChannel",
"Vlan": "Vlan",
"Loopback": "Loopback",
"Ethernet-Backplane": "Ethernet-BP"
}
def front_panel_prefix():
"""
Retrieves the SONIC front panel interface name prefix.
"""
return SONIC_INTERFACE_PREFIXES["Ethernet-FrontPanel"]
def backplane_prefix():
"""
Retrieves the SONIC backplane interface name prefix.
"""
return SONIC_INTERFACE_PREFIXES["Ethernet-Backplane"]
def portchannel_prefix():
"""
Retrieves the SONIC PortChannel interface name prefix.
"""
return SONIC_INTERFACE_PREFIXES["PortChannel"]
def vlan_prefix():
"""
Retrieves the SONIC Vlan interface name prefix.
"""
return SONIC_INTERFACE_PREFIXES["Vlan"]
def loopback_prefix():
"""
Retrieves the SONIC Loopback interface name prefix.
"""
return SONIC_INTERFACE_PREFIXES["Loopback"]