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

Update intfutil and sfpshow to support DPC role #51

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ from utilities_common import multi_asic as multi_asic_util
from utilities_common.intf_filter import parse_interface_in_filter
from utilities_common.platform_sfputil_helper import is_rj45_port, RJ45_PORT_TYPE
from sonic_py_common.interface import get_intf_longname
from sonic_py_common import multi_asic

# ========================== Common interface-utils logic ==========================

Expand All @@ -53,6 +54,7 @@ PORT_INTERFACE_TYPE = 'interface_type'
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
PORT_TPID = "tpid"
OPTICS_TYPE_RJ45 = RJ45_PORT_TYPE
TYPE_DPC = 'DPU-NPU Data Port'
PORT_LINK_TRAINING = 'link_training'
PORT_LINK_TRAINING_STATUS = 'link_training_status'

Expand Down Expand Up @@ -214,15 +216,17 @@ def port_oper_speed_get_raw(db, intf_name):
speed = db.get(db.APPL_DB, PORT_STATUS_TABLE_PREFIX + intf_name, PORT_SPEED)
return speed

def port_optics_get(state_db, intf_name, type):
def port_optics_get(db, intf_name, type):
"""
Get optic type info for port
"""
full_table_id = PORT_TRANSCEIVER_TABLE_PREFIX + intf_name
optics_type = state_db.get(state_db.STATE_DB, full_table_id, type)
optics_type = db.get(db.STATE_DB, full_table_id, type)
if optics_type is None:
if is_rj45_port(intf_name):
return OPTICS_TYPE_RJ45
elif db.get(db.APPL_DB, PORT_STATUS_TABLE_PREFIX + intf_name, multi_asic.PORT_ROLE) == multi_asic.DPU_CONNECT_PORT:
return TYPE_DPC
else:
return "N/A"
return optics_type
Expand Down
13 changes: 8 additions & 5 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 import multi_asic
from utilities_common.sfp_helper import covert_application_advertisement_to_output_string
from utilities_common.sfp_helper import (
Expand Down Expand Up @@ -544,6 +543,10 @@ class SFPShow(object):
output = ZR_PM_NOT_APPLICABLE_STR + '\n'
return output

def is_valid_physical_port(self, port_name):
role = self.db.get(self.db.APPL_DB, 'PORT_TABLE:{}'.format(port_name), multi_asic.PORT_ROLE)
return multi_asic.is_front_panel_port(port_name, role)

@multi_asic_util.run_on_multi_asic
def get_eeprom(self):
if self.intf_name is not None:
Expand All @@ -553,7 +556,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 self.is_valid_physical_port(interface):
self.intf_eeprom[interface] = self.convert_interface_sfp_info_to_cli_output_string(
self.db, interface, self.dump_dom)

Expand All @@ -577,7 +580,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 self.is_valid_physical_port(key):
presence_string = self.convert_interface_sfp_presence_state_to_cli_output_string(self.db, key)
port_table.append((key, presence_string))

Expand All @@ -592,7 +595,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 self.is_valid_physical_port(interface):
self.intf_pm[interface] = self.convert_interface_sfp_pm_to_cli_output_string(
self.db, interface)

Expand All @@ -605,7 +608,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 self.is_valid_physical_port(interface):
self.intf_status[interface] = self.convert_interface_sfp_status_to_cli_output_string(
self.db, interface)

Expand Down
34 changes: 17 additions & 17 deletions tests/intfutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
scripts_path = os.path.join(modules_path, "scripts")

show_interface_status_output="""\
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- --------------- ------- ----- ----- --------- --------------- ------ ------- --------------- ----------
Ethernet0 0 25G 9100 rs Ethernet0 routed down up QSFP28 or later off
Ethernet16 16 100M 9100 N/A etp5 trunk up up RJ45 off
Ethernet24 24 1G 9100 N/A etp6 trunk up up QSFP28 or later off
Ethernet28 28 1000M 9100 N/A etp8 trunk up up RJ45 off
Ethernet32 13,14,15,16 40G 9100 rs etp9 PortChannel1001 up up N/A off
Ethernet36 9,10,11,12 10M 9100 N/A etp10 routed up up RJ45 off
Ethernet112 93,94,95,96 40G 9100 rs etp29 PortChannel0001 up up N/A off
Ethernet116 89,90,91,92 40G 9100 rs etp30 PortChannel0002 up up N/A off
Ethernet120 101,102,103,104 40G 9100 rs etp31 PortChannel0003 up up N/A off
Ethernet124 97,98,99,100 40G 9100 auto etp32 PortChannel0004 up up N/A off
PortChannel0001 N/A 40G 9100 N/A N/A routed down up N/A N/A
PortChannel0002 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel0003 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel0004 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel1001 N/A 40G 9100 N/A N/A trunk N/A N/A N/A N/A
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- --------------- ------- ----- ----- --------- --------------- ------ ------- ----------------- ----------
Ethernet0 0 25G 9100 rs Ethernet0 routed down up QSFP28 or later off
Ethernet16 16 100M 9100 N/A etp5 trunk up up RJ45 off
Ethernet24 24 1G 9100 N/A etp6 trunk up up DPU-NPU Data Port off
Ethernet28 28 1000M 9100 N/A etp8 trunk up up RJ45 off
Ethernet32 13,14,15,16 40G 9100 rs etp9 PortChannel1001 up up N/A off
Ethernet36 9,10,11,12 10M 9100 N/A etp10 routed up up RJ45 off
Ethernet112 93,94,95,96 40G 9100 rs etp29 PortChannel0001 up up N/A off
Ethernet116 89,90,91,92 40G 9100 rs etp30 PortChannel0002 up up N/A off
Ethernet120 101,102,103,104 40G 9100 rs etp31 PortChannel0003 up up N/A off
Ethernet124 97,98,99,100 40G 9100 auto etp32 PortChannel0004 up up N/A off
PortChannel0001 N/A 40G 9100 N/A N/A routed down up N/A N/A
PortChannel0002 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel0003 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel0004 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel1001 N/A 40G 9100 N/A N/A trunk N/A N/A N/A N/A
"""

show_interface_status_Ethernet32_output="""\
Expand Down
3 changes: 2 additions & 1 deletion tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"pfc_asym": "off",
"mtu": "9100",
"tpid": "0x8100",
"admin_status": "up"
"admin_status": "up",
"role": "Dpc"
},
"PORT_TABLE:Ethernet28": {
"index": "7",
Expand Down
3 changes: 2 additions & 1 deletion tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"tpid": "0x8100",
"mode": "trunk",
"pfc_asym": "off",
"speed": "1000"
"speed": "1000",
"role": "Dpc"
},
"PORT|Ethernet28": {
"admin_status": "up",
Expand Down
18 changes: 0 additions & 18 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,6 @@
"nominal_bit_rate": "N/A",
"application_advertisement": "N/A"
},
"TRANSCEIVER_INFO|Ethernet24": {
"type": "QSFP28 or later",
"hardware_rev": "AC",
"serial": "MT1706FT02066",
"manufacturer": "Mellanox",
"model": "MFA1A00-C003",
"vendor_oui": "00-02-c9",
"vendor_date": "2017-01-13 ",
"connector": "No separable connector",
"encoding": "64B66B",
"ext_identifier": "Power Class 3(2.5W max), CDR present in Rx Tx",
"ext_rateselect_compliance": "QSFP+ Rate Select Version 1",
"cable_type": "Length Cable Assembly(m)",
"cable_length": "3",
"specification_compliance": "{'10/40G Ethernet Compliance Code': '40G Active Cable (XLPPI)'}",
"nominal_bit_rate": "255",
"application_advertisement": "N/A"
},
"TRANSCEIVER_INFO|Ethernet28": {
"type": "RJ45",
"hardware_rev": "N/A",
Expand Down
22 changes: 22 additions & 0 deletions tests/sfp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,28 @@ def test_sfp_presence(self):
assert result.exit_code == 0
assert result.output == expected

def test_sfp_dpc_ports(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["presence"])
assert result.exit_code == 0
assert "Ethernet24" not in result.output

result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"])
assert result.exit_code == 0
assert "Ethernet24" not in result.output

result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["status"])
assert result.exit_code == 0
assert "Ethernet24" not in result.output

result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["pm"])
assert result.exit_code == 0
assert "Ethernet24" not in result.output

result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"])
assert result.exit_code == 0
assert "Ethernet24" not in result.output

def test_sfp_eeprom_with_dom(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ["Ethernet0", "-d"])
Expand Down
Loading