From 52fe7ae365862c9c9e354bb1f07475aec89c1e3b Mon Sep 17 00:00:00 2001 From: judyjoseph <53951155+judyjoseph@users.noreply.github.com> Date: Tue, 18 Aug 2020 10:20:26 -0700 Subject: [PATCH] [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. --- src/sonic-config-engine/minigraph.py | 6 +-- .../sonic_py_common/interface.py | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/sonic-py-common/sonic_py_common/interface.py diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 3500f8ba20..c387d3eb17 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -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 diff --git a/src/sonic-py-common/sonic_py_common/interface.py b/src/sonic-py-common/sonic_py_common/interface.py new file mode 100644 index 0000000000..9136b71f78 --- /dev/null +++ b/src/sonic-py-common/sonic_py_common/interface.py @@ -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"]