Skip to content

Commit

Permalink
Added support for front panel port prefix regex
Browse files Browse the repository at this point in the history
  • Loading branch information
itamar-talmon authored and Itamar Talmon committed Jan 12, 2023
1 parent 96c0590 commit 53b6c2b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/swsssdk/port_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
import re


SONIC_ETHERNET_RE_PATTERN = "^Ethernet(\d+)$"
from swsscommon.swsscommon import FRONT_PANEL_PORT_REGEX

# Following is a list of regexs that match different interfaces type
# the convention is to have the port index in the end of the name so it can
# be retrived with match.groups()[-1]

# front panel ports, e.g. Ethernet4
SONIC_FRONT_PANEL_RE_PATTERN = FRONT_PANEL_PORT_REGEX
"""
Ethernet-BP refers to BackPlane interfaces
in multi-asic platform.
Expand All @@ -18,7 +25,7 @@
SONIC_ETHERNET_REC_RE_PATTERN = "^Ethernet-Rec(\d+)$"

class BaseIdx:
ethernet_base_idx = 1
front_panel_base_idx = 1
vlan_interface_base_idx = 2000
ethernet_bp_base_idx = 9000
portchannel_base_idx = 1000
Expand Down Expand Up @@ -52,7 +59,7 @@ def get_index_from_str(if_name):
Ethernet_Rec N = N + 12000
"""
patterns = {
SONIC_ETHERNET_RE_PATTERN: BaseIdx.ethernet_base_idx,
SONIC_FRONT_PANEL_RE_PATTERN: BaseIdx.front_panel_base_idx,
SONIC_ETHERNET_BP_RE_PATTERN: BaseIdx.ethernet_bp_base_idx,
SONIC_VLAN_RE_PATTERN: BaseIdx.vlan_interface_base_idx,
SONIC_PORTCHANNEL_RE_PATTERN: BaseIdx.portchannel_base_idx,
Expand All @@ -64,7 +71,7 @@ def get_index_from_str(if_name):
for pattern, baseidx in patterns.items():
match = re.match(pattern, if_name)
if match:
return int(match.group(1)) + baseidx
return int(match.groups()[-1]) + baseidx

def get_interface_oid_map(db, blocking=True):
"""
Expand Down

0 comments on commit 53b6c2b

Please sign in to comment.