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 support for front panel port prefix regex #10471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/sonic-config-engine/portconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def __hash__(self):
return hash((self.num_ports, tuple(self.supported_speed), self.num_assigned_lanes))

def __init__(self, name, bmode, properties):
self._interface_base_id = int(name.replace(PORT_STR, ''))
self._name = name
self._front_panel_prefix, self._interface_base_id = self._parse_name_to_prefix_and_id()
self._properties = properties
self._lanes = properties ['lanes'].split(',')
self._indexes = properties ['index'].split(',')
Expand All @@ -254,6 +255,12 @@ def __init__(self, name, bmode, properties):
if not self._breakout_capabilities:
raise RuntimeError("Unsupported breakout mode {}!".format(bmode))

def _parse_name_to_prefix_and_id(self):
itamar-talmon marked this conversation as resolved.
Show resolved Hide resolved
match = re.match(swsscommon.FRONT_PANEL_PORT_REGEX, self._name)
if not match:
raise RuntimeError("Failed to parse front panel prefix of {}!", self._name)
return match.group(1), int(match.group(2))

def _re_group_to_entry(self, group):
if len(group) != BRKOUT_PATTERN_GROUPS:
raise RuntimeError("Unsupported breakout mode format!")
Expand Down Expand Up @@ -300,7 +307,7 @@ def get_config(self):
lanes_per_port = entry.num_assigned_lanes // entry.num_ports

for port in range(entry.num_ports):
interface_name = PORT_STR + str(self._interface_base_id + lane_id)
interface_name = self._front_panel_prefix + str(self._interface_base_id + lane_id)

lanes = self._lanes[lane_id:lane_id + lanes_per_port]

Expand Down
2 changes: 1 addition & 1 deletion src/sonic-device-data/tests/hwsku_json_checker
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sys
# Global variable
PORT_ATTRIBUTES = ["default_brkout_mode"]
OPTIONAL_PORT_ATTRIBUTES = ["fec", "autoneg", "port_type"]
PORT_REG = "Ethernet(\d+)"
PORT_REG = "(Ethernet)(\d+)"
HWSKU_JSON = '*hwsku.json'
INTF_KEY = "interfaces"

Expand Down
3 changes: 2 additions & 1 deletion src/sonic-device-data/tests/platform_json_checker
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import sys
# Global variable
PORT_ATTRIBUTES = ["index", "lanes", "breakout_modes"]
ATTR_LEN = len(PORT_ATTRIBUTES)
PORT_REG = "Ethernet(\d+)"
# PORT_REG should be taken from scheme.h FRONT_PANEL_PORT_PREFIX_REGEX
PORT_REG = "(Ethernet)(\d+)"
PLATFORM_JSON = '*platform.json'
INTF_KEY = "interfaces"
CHASSIS_KEY = "chassis"
Expand Down
16 changes: 14 additions & 2 deletions src/sonic-py-common/sonic_py_common/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"Human readable interface string":"Sonic interface prefix"
Currently this is a static mapping, but in future could be stored as metadata in DB.
"""
import re
from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX


SONIC_INTERFACE_PREFIXES = {
"FrontPanel" : FRONT_PANEL_PORT_PREFIX_REGEX,
"Ethernet-FrontPanel": "Ethernet",
"PortChannel": "PortChannel",
"Vlan": "Vlan",
Expand All @@ -22,6 +26,14 @@

VLAN_SUB_INTERFACE_SEPARATOR = '.'


def front_panel_prefix_regex():
"""
Retrieves the SONIC front panel interface name prefix regex.
"""
return SONIC_INTERFACE_PREFIXES["FrontPanel"]


def front_panel_prefix():
"""
Retrieves the SONIC front panel interface name prefix.
Expand Down Expand Up @@ -79,7 +91,7 @@ def portchannel_subinterface_prefix():
def get_interface_table_name(interface_name):
"""Get table name by interface_name prefix
"""
if interface_name.startswith(front_panel_prefix()):
if re.match(front_panel_prefix_regex(), interface_name):
if VLAN_SUB_INTERFACE_SEPARATOR in interface_name:
return "VLAN_SUB_INTERFACE"
return "INTERFACE"
Expand All @@ -100,7 +112,7 @@ def get_interface_table_name(interface_name):
def get_port_table_name(interface_name):
"""Get table name by port_name prefix
"""
if interface_name.startswith(front_panel_prefix()):
if re.match(front_panel_prefix_regex(), interface_name):
if VLAN_SUB_INTERFACE_SEPARATOR in interface_name:
return "VLAN_SUB_INTERFACE"
return "PORT"
Expand Down