Skip to content

Commit

Permalink
Made convert_sfp_info_to_output_string generic for CMIS and non CMIS …
Browse files Browse the repository at this point in the history
…and added test case to address PR comment
  • Loading branch information
mihirpat1 committed Feb 2, 2023
1 parent 686603e commit b6aa0e0
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 98 deletions.
37 changes: 9 additions & 28 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -280,36 +280,20 @@ class SFPShow(object):
units)
return output

# Convert cmis sfp info in DB to cli output string
def convert_cmis_sfp_info_to_output_string(self, sfp_info_dict):
# Convert sfp info in DB to cli output string
def convert_sfp_info_to_output_string(self, sfp_info_dict):
indent = ' ' * 8
output = ''
is_sfp_cmis = 'cmis_rev' in sfp_info_dict

sorted_cmis_data_map_keys = sorted(CMIS_DATA_MAP, key=CMIS_DATA_MAP.get)
for key in sorted_cmis_data_map_keys:
data_map = CMIS_DATA_MAP if is_sfp_cmis else QSFP_DATA_MAP
sorted_data_map_keys = sorted(data_map, key=data_map.get)
for key in sorted_data_map_keys:
if key == 'cable_type':
output += '{}{}: {}\n'.format(indent, sfp_info_dict['cable_type'], sfp_info_dict['cable_length'])
elif key == 'cable_length':
pass
elif key == 'application_advertisement':
output += covert_application_advertisement_to_output_string(indent, sfp_info_dict)
else:
output += '{}{}: {}\n'.format(indent, CMIS_DATA_MAP[key], sfp_info_dict[key])

return output

# Convert non cmis sfp info in DB to cli output string
def convert_non_cmis_sfp_info_to_output_string(self, sfp_info_dict):
indent = ' ' * 8
output = ''

sorted_qsfp_data_map_keys = sorted(QSFP_DATA_MAP, key=QSFP_DATA_MAP.get)
for key in sorted_qsfp_data_map_keys:
if key == 'cable_type':
output += '{}{}: {}\n'.format(indent, sfp_info_dict['cable_type'], sfp_info_dict['cable_length'])
elif key == 'cable_length':
pass
elif key == 'specification_compliance':
elif key == 'specification_compliance' and not(is_sfp_cmis):
if sfp_info_dict['type'] == "QSFP-DD Double Density 8X Pluggable Transceiver":
output += '{}{}: {}\n'.format(indent, QSFP_DATA_MAP[key], sfp_info_dict[key])
else:
Expand All @@ -326,7 +310,7 @@ class SFPShow(object):
elif key == 'application_advertisement':
output += covert_application_advertisement_to_output_string(indent, sfp_info_dict)
else:
output += '{}{}: {}\n'.format(indent, QSFP_DATA_MAP[key], sfp_info_dict[key])
output += '{}{}: {}\n'.format(indent, data_map[key], sfp_info_dict[key])

return output

Expand Down Expand Up @@ -438,10 +422,7 @@ class SFPShow(object):
output = 'SFP EEPROM is not applicable for RJ45 port\n'
else:
output = 'SFP EEPROM detected\n'
if 'cmis_rev' in sfp_info_dict:
sfp_info_output = self.convert_cmis_sfp_info_to_output_string(sfp_info_dict)
else:
sfp_info_output = self.convert_non_cmis_sfp_info_to_output_string(sfp_info_dict)
sfp_info_output = self.convert_sfp_info_to_output_string(sfp_info_dict)
output += sfp_info_output

if dump_dom:
Expand Down
51 changes: 35 additions & 16 deletions tests/mock_tables/asic1/state_db.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
{
"TRANSCEIVER_INFO|Ethernet64": {
"type": "QSFP28 or later",
"vendor_rev": "AC",
"serial": "MT1706FT02064",
"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"
"type" : "QSFP-DD Double Density 8X Pluggable Transceiver",
"hardware_rev" : "1.1",
"serial" : "214455197",
"manufacturer" : "Acacia Comm Inc.",
"model" : "DP04QSDD-E20-001",
"connector" : "LC",
"encoding" : "N/A",
"ext_identifier" : "Power Class 8 (20.0W Max)",
"ext_rateselect_compliance" : "N/A",
"cable_type" : "Length Cable Assembly(m)",
"cable_length" : "0.0",
"nominal_bit_rate" : "0",
"specification_compliance" : "sm_media_interface",
"vendor_date" : "2021-11-19",
"vendor_oui" : "7c-b2-5c",
"application_advertisement" : "{1: {'host_electrical_interface_id': '400GAUI-8 C2M (Annex 120E)', 'module_media_interface_id': '400ZR, DWDM, amplified', 'media_lane_count': 1, 'host_lane_count': 8, 'host_lane_assignment_options': 1, 'media_lane_assignment_options': 1}, 2: {'host_electrical_interface_id': '400GAUI-8 C2M (Annex 120E)', 'module_media_interface_id': '400ZR, Single Wavelength, Unamplified', 'media_lane_count': 1, 'host_lane_count': 8, 'host_lane_assignment_options': 1, 'media_lane_assignment_options': 1}, 3: {'host_electrical_interface_id': '100GAUI-2 C2M (Annex 135G)', 'module_media_interface_id': '400ZR, DWDM, amplified', 'media_lane_count': 1, 'host_lane_count': 2, 'host_lane_assignment_options': 85, 'media_lane_assignment_options': 1}}",
"host_lane_count" : "8",
"media_lane_count" : "1",
"active_apsel_hostlane1" : "1",
"active_apsel_hostlane2" : "1",
"active_apsel_hostlane3" : "1",
"active_apsel_hostlane4" : "1",
"active_apsel_hostlane5" : "1",
"active_apsel_hostlane6" : "1",
"active_apsel_hostlane7" : "1",
"active_apsel_hostlane8" : "1",
"media_interface_technology" : "1550 nm DFB",
"vendor_rev" : "A",
"cmis_rev" : "4.1",
"active_firmware" : "61.20",
"inactive_firmware" : "161.10",
"supported_max_tx_power" : "4.0",
"supported_min_tx_power" : "-22.9",
"supported_max_laser_freq" : "196100",
"supported_min_laser_freq" : "191300"
},
"TRANSCEIVER_DOM_SENSOR|Ethernet64": {
"temperature": "30.9258",
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
"rx_sig_power_min": "-40",
"rx_sig_power_max": "40"
},
"TRANSCEIVER_INFO|Ethernet48": {
"TRANSCEIVER_INFO|Ethernet64": {
"type" : "QSFP-DD Double Density 8X Pluggable Transceiver",
"hardware_rev" : "1.1",
"serial" : "214455197",
Expand Down
118 changes: 82 additions & 36 deletions tests/sfp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"""

test_cmis_eeprom_output = """\
Ethernet48: SFP EEPROM detected
Ethernet64: SFP EEPROM detected
Active Firmware: 61.20
Active application selected code assigned to host lane 1: 1
Active application selected code assigned to host lane 2: 1
Expand All @@ -242,7 +242,7 @@
Media Lane Count: 1
Module Hardware Rev: 1.1
Nominal Bit Rate(100Mbs): 0
Specification Compliance: sm_media_interface
Specification compliance: sm_media_interface
Supported Max Laser Frequency: 196100
Supported Max TX Power: 4.0
Supported Min Laser Frequency: 191300
Expand Down Expand Up @@ -307,22 +307,42 @@
Ethernet4: SFP EEPROM Not detected
Ethernet64: SFP EEPROM detected
Application Advertisement: N/A
Connector: No separable connector
Encoding: 64B66B
Extended Identifier: Power Class 3(2.5W max), CDR present in Rx Tx
Extended RateSelect Compliance: QSFP+ Rate Select Version 1
Identifier: QSFP28 or later
Length Cable Assembly(m): 3
Nominal Bit Rate(100Mbs): 255
Specification compliance:
10/40G Ethernet Compliance Code: 40G Active Cable (XLPPI)
Vendor Date Code(YYYY-MM-DD Lot): 2017-01-13
Vendor Name: Mellanox
Vendor OUI: 00-02-c9
Vendor PN: MFA1A00-C003
Vendor Rev: AC
Vendor SN: MT1706FT02064
Active Firmware: 61.20
Active application selected code assigned to host lane 1: 1
Active application selected code assigned to host lane 2: 1
Active application selected code assigned to host lane 3: 1
Active application selected code assigned to host lane 4: 1
Active application selected code assigned to host lane 5: 1
Active application selected code assigned to host lane 6: 1
Active application selected code assigned to host lane 7: 1
Active application selected code assigned to host lane 8: 1
Application Advertisement: 400GAUI-8 C2M (Annex 120E) - Host Assign (0x1) - 400ZR, DWDM, amplified - Media Assign (0x1)
400GAUI-8 C2M (Annex 120E) - Host Assign (0x1) - 400ZR, Single Wavelength, Unamplified - Media Assign (0x1)
100GAUI-2 C2M (Annex 135G) - Host Assign (0x55) - 400ZR, DWDM, amplified - Media Assign (0x1)
CMIS Rev: 4.1
Connector: LC
Encoding: N/A
Extended Identifier: Power Class 8 (20.0W Max)
Extended RateSelect Compliance: N/A
Host Lane Count: 8
Identifier: QSFP-DD Double Density 8X Pluggable Transceiver
Inactive Firmware: 161.10
Length Cable Assembly(m): 0.0
Media Interface Technology: 1550 nm DFB
Media Lane Count: 1
Module Hardware Rev: 1.1
Nominal Bit Rate(100Mbs): 0
Specification compliance: sm_media_interface
Supported Max Laser Frequency: 196100
Supported Max TX Power: 4.0
Supported Min Laser Frequency: 191300
Supported Min TX Power: -22.9
Vendor Date Code(YYYY-MM-DD Lot): 2021-11-19
Vendor Name: Acacia Comm Inc.
Vendor OUI: 7c-b2-5c
Vendor PN: DP04QSDD-E20-001
Vendor Rev: A
Vendor SN: 214455197
ChannelMonitorValues:
RX1Power: 0.3802dBm
RX2Power: -0.4871dBm
Expand Down Expand Up @@ -377,22 +397,42 @@
Ethernet4: SFP EEPROM Not detected
Ethernet64: SFP EEPROM detected
Application Advertisement: N/A
Connector: No separable connector
Encoding: 64B66B
Extended Identifier: Power Class 3(2.5W max), CDR present in Rx Tx
Extended RateSelect Compliance: QSFP+ Rate Select Version 1
Identifier: QSFP28 or later
Length Cable Assembly(m): 3
Nominal Bit Rate(100Mbs): 255
Specification compliance:
10/40G Ethernet Compliance Code: 40G Active Cable (XLPPI)
Vendor Date Code(YYYY-MM-DD Lot): 2017-01-13
Vendor Name: Mellanox
Vendor OUI: 00-02-c9
Vendor PN: MFA1A00-C003
Vendor Rev: AC
Vendor SN: MT1706FT02064
Active Firmware: 61.20
Active application selected code assigned to host lane 1: 1
Active application selected code assigned to host lane 2: 1
Active application selected code assigned to host lane 3: 1
Active application selected code assigned to host lane 4: 1
Active application selected code assigned to host lane 5: 1
Active application selected code assigned to host lane 6: 1
Active application selected code assigned to host lane 7: 1
Active application selected code assigned to host lane 8: 1
Application Advertisement: 400GAUI-8 C2M (Annex 120E) - Host Assign (0x1) - 400ZR, DWDM, amplified - Media Assign (0x1)
400GAUI-8 C2M (Annex 120E) - Host Assign (0x1) - 400ZR, Single Wavelength, Unamplified - Media Assign (0x1)
100GAUI-2 C2M (Annex 135G) - Host Assign (0x55) - 400ZR, DWDM, amplified - Media Assign (0x1)
CMIS Rev: 4.1
Connector: LC
Encoding: N/A
Extended Identifier: Power Class 8 (20.0W Max)
Extended RateSelect Compliance: N/A
Host Lane Count: 8
Identifier: QSFP-DD Double Density 8X Pluggable Transceiver
Inactive Firmware: 161.10
Length Cable Assembly(m): 0.0
Media Interface Technology: 1550 nm DFB
Media Lane Count: 1
Module Hardware Rev: 1.1
Nominal Bit Rate(100Mbs): 0
Specification compliance: sm_media_interface
Supported Max Laser Frequency: 196100
Supported Max TX Power: 4.0
Supported Min Laser Frequency: 191300
Supported Min TX Power: -22.9
Vendor Date Code(YYYY-MM-DD Lot): 2021-11-19
Vendor Name: Acacia Comm Inc.
Vendor OUI: 7c-b2-5c
Vendor PN: DP04QSDD-E20-001
Vendor Rev: A
Vendor SN: 214455197
"""

test_sfp_presence_all_output = """\
Expand Down Expand Up @@ -506,7 +546,7 @@ def test_qsfp_dd_eeprom_adv_app(self):

def test_cmis_info(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ["Ethernet48"])
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ["Ethernet64"])
assert result.exit_code == 0
assert result.output == test_cmis_eeprom_output

Expand Down Expand Up @@ -593,7 +633,7 @@ def test_qsfp_dd_pm_with_ns(self):

def test_cmis_sfp_info_with_ns(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ["Ethernet48 -n asic0"])
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"], ["Ethernet64 -n asic1"])
assert result.exit_code == 0
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_cmis_eeprom_output

Expand All @@ -603,6 +643,12 @@ def test_sfp_eeprom_all(self):
assert result.exit_code == 0
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_sfp_eeprom_all_output

def test_sfp_info_all(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["info"])
assert result.exit_code == 0
assert "\n".join([ l.rstrip() for l in result.output.split('\n')]) == test_sfp_eeprom_all_output

def test_sfp_eeprom_dom_all(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["interfaces"].commands["transceiver"].commands["eeprom"], ["-d"])
Expand Down
20 changes: 3 additions & 17 deletions utilities_common/sfp_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,7 @@
'application_advertisement': 'Application Advertisement'
}

CMIS_DATA_MAP = {
'model': 'Vendor PN',
'vendor_oui': 'Vendor OUI',
'vendor_date': 'Vendor Date Code(YYYY-MM-DD Lot)',
'manufacturer': 'Vendor Name',
'vendor_rev': 'Vendor Rev',
'serial': 'Vendor SN',
'type': 'Identifier',
'ext_identifier': 'Extended Identifier',
'ext_rateselect_compliance': 'Extended RateSelect Compliance',
'cable_length': 'cable_length',
'cable_type': 'Length',
'nominal_bit_rate': 'Nominal Bit Rate(100Mbs)',
'specification_compliance': 'Specification Compliance',
'encoding': 'Encoding',
'connector': 'Connector',
'application_advertisement': 'Application Advertisement',
QSFP_CMIS_DELTA_DATA_MAP = {
'host_lane_count': 'Host Lane Count',
'media_lane_count': 'Media Lane Count',
'active_apsel_hostlane1': 'Active application selected code assigned to host lane 1',
Expand All @@ -57,6 +41,8 @@
'supported_min_laser_freq': 'Supported Min Laser Frequency'
}

CMIS_DATA_MAP = {**QSFP_DATA_MAP, **QSFP_CMIS_DELTA_DATA_MAP}

def covert_application_advertisement_to_output_string(indent, sfp_info_dict):
key = 'application_advertisement'
field_name = '{}{}: '.format(indent, QSFP_DATA_MAP[key])
Expand Down

0 comments on commit b6aa0e0

Please sign in to comment.