Skip to content

Commit

Permalink
Add 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 2513da1 commit 20f26de
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
5 changes: 3 additions & 2 deletions pfc/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python3

import click
from swsscommon.swsscommon import ConfigDBConnector
from swsscommon.swsscommon import ConfigDBConnector, FRONT_PANEL_PORT_PREFIX_REGEX
from tabulate import tabulate
from natsort import natsorted
import re

ALL_PRIORITIES = [str(x) for x in range(8)]
PRIORITY_STATUS = ['on', 'off']
Expand Down Expand Up @@ -39,7 +40,7 @@ def showPfcAsym(interface):
if i:
key = i.split('|')[-1]

if key and key.startswith('Ethernet'):
if key and re.match(FRONT_PANEL_PORT_PREFIX_REGEX, key):
entry = configdb.get_entry('PORT', key)
table.append([key, entry.get('pfc_asym', 'N/A')])

Expand Down
4 changes: 3 additions & 1 deletion pfcwd/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib
import os
import sys
import re

import click
import utilities_common.cli as clicommon
Expand All @@ -10,6 +11,7 @@
from utilities_common import multi_asic as multi_asic_util
from utilities_common import constants
from sonic_py_common import logger
from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX

SYSLOG_IDENTIFIER = "config"

Expand Down Expand Up @@ -82,7 +84,7 @@ def get_all_ports(db, namespace=None, display=constants.DISPLAY_ALL):
# Get list of physical ports
port_names = {}
for i in all_port_names:
if i.startswith('Ethernet'):
if re.search(FRONT_PANEL_PORT_PREFIX_REGEX, i):
port_names[i] = all_port_names[i]
display_ports = list(port_names.keys())
if display == constants.DISPLAY_EXTERNAL:
Expand Down
3 changes: 2 additions & 1 deletion scripts/ipintutil
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import subprocess
import sys
import re

import netaddr
import netifaces
Expand Down Expand Up @@ -55,7 +56,7 @@ def get_bgp_peer():

def skip_ip_intf_display(interface, display_option):
if display_option != constants.DISPLAY_ALL:
if interface.startswith('Ethernet') and multi_asic.is_port_internal(interface):
if re.search(swsscommon.FRONT_PANEL_PORT_PREFIX_REGEX, interface) and multi_asic.is_port_internal(interface):
return True
elif interface.startswith('PortChannel') and multi_asic.is_port_channel_internal(interface):
return True
Expand Down
6 changes: 3 additions & 3 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from typing import Dict

import click
from natsort import natsorted
from sonic_py_common.interface import front_panel_prefix, backplane_prefix, inband_prefix, recirc_prefix
from sonic_py_common.interface import front_panel_prefix_regex, backplane_prefix, inband_prefix, recirc_prefix
from sonic_py_common import multi_asic
from tabulate import tabulate
from utilities_common import multi_asic as multi_asic_util
Expand Down Expand Up @@ -417,7 +417,7 @@ class SFPShow(object):
port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*")
for i in port_table_keys:
interface = re.split(':', i, maxsplit=1)[-1].strip()
if interface and interface.startswith(front_panel_prefix()) and not interface.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
if interface and re.search(front_panel_prefix_regex(), interface) and not interface.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface))
if presence:
self.intf_eeprom[interface] = self.convert_interface_sfp_info_to_cli_output_string(
Expand All @@ -440,7 +440,7 @@ class SFPShow(object):
port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*")
for i in port_table_keys:
key = re.split(':', i, maxsplit=1)[-1].strip()
if key and key.startswith(front_panel_prefix()) and not key.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
if key and re.search(front_panel_prefix_regex(), key) and not key.startswith((backplane_prefix(), inband_prefix(), recirc_prefix())):
presence = self.db.exists(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(key))
if presence:
port_table.append((key, 'Present'))
Expand Down
5 changes: 3 additions & 2 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
import sys
import re
import natsort
import ast
import time
Expand All @@ -16,7 +17,7 @@
import click
import sonic_platform
import sonic_platform_base.sonic_sfp.sfputilhelper
from swsscommon.swsscommon import SonicV2Connector
from swsscommon.swsscommon import SonicV2Connector, FRONT_PANEL_PORT_PREFIX_REGEX
from natsort import natsorted
from sonic_py_common import device_info, logger, multi_asic
from tabulate import tabulate
Expand Down Expand Up @@ -481,7 +482,7 @@ def get_physical_port_name(logical_port, physical_port, ganged):


def logical_port_name_to_physical_port_list(port_name):
if port_name.startswith("Ethernet"):
if re.search(FRONT_PANEL_PORT_PREFIX_REGEX, port_name):
if platform_sfputil.is_logical_port(port_name):
return platform_sfputil.get_logical_to_physical(port_name)
else:
Expand Down
7 changes: 5 additions & 2 deletions utilities_common/intf_filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Interface filtering functions
import re
from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX

SONIC_PORT_NAME_PREFIX = "Ethernet"
SONIC_LAG_NAME_PREFIX = "PortChannel"

def parse_interface_in_filter(intf_filter):
Expand All @@ -13,10 +14,12 @@ def parse_interface_in_filter(intf_filter):
for x in fs:
if '-' in x:
# handle range
if not x.startswith(SONIC_PORT_NAME_PREFIX) and not x.startswith(SONIC_LAG_NAME_PREFIX):
if not re.search(FRONT_PANEL_PORT_PREFIX_REGEX, x) and not x.startswith(SONIC_LAG_NAME_PREFIX):
continue
if x.startswith(SONIC_PORT_NAME_PREFIX):
intf = SONIC_PORT_NAME_PREFIX
if x.startswith(SONIC_IB_PORT_NAME_PREFIX):
intf = SONIC_IB_PORT_NAME_PREFIX
if x.startswith(SONIC_LAG_NAME_PREFIX):
intf = SONIC_LAG_NAME_PREFIX
start = x.split('-')[0].split(intf,1)[1]
Expand Down
4 changes: 3 additions & 1 deletion utilities_common/platform_sfputil_helper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sys
import re

import click

from . import cli as clicommon
from sonic_py_common import multi_asic, device_info
from swsscommon.swsscommon import FRONT_PANEL_PORT_PREFIX_REGEX

platform_sfputil = None

Expand Down Expand Up @@ -43,7 +45,7 @@ def platform_sfputil_read_porttab_mappings():


def logical_port_name_to_physical_port_list(port_name):
if port_name.startswith("Ethernet"):
if re.search(FRONT_PANEL_PORT_PREFIX_REGEX, port_name):
if platform_sfputil.is_logical_port(port_name):
return platform_sfputil.get_logical_to_physical(port_name)
else:
Expand Down

0 comments on commit 20f26de

Please sign in to comment.