Skip to content

Commit

Permalink
[sonic-py-common] Add interface utilities (sonic-net#5113)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
judyjoseph authored and santhosh-kt committed Feb 25, 2021
1 parent f58f1ed commit a35ba7a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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"
Expand All @@ -37,7 +38,6 @@

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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
43 changes: 43 additions & 0 deletions src/sonic-py-common/sonic_py_common/interface.py
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit a35ba7a

Please sign in to comment.