Skip to content

Commit

Permalink
EEPROM/DOM Info: The Compliance Code will show "unknown" by using FIN…
Browse files Browse the repository at this point in the history
…ISAR 10G LR XCVR (#319)

* JIRA-SONIC-5341: [eBay_ec202111_214] EEPROM/DOM Info: The Compliance Code will show "unknown" by using FINISAR 10G LR XCVR

correct the code mapping

* Fix others error code mapping and add unit test
  • Loading branch information
chiourung authored Nov 23, 2022
1 parent 7c48be2 commit ce9aacb
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 48 deletions.
34 changes: 17 additions & 17 deletions sonic_platform_base/sonic_xcvr/codes/public/sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ class Sff8436Codes(Sff8024):

POWER_CLASSES = {
0: "Power Class 1 Module (1.5W max. Power consumption)",
64: "Power Class 2 Module (2.0W max. Power consumption)",
128: "Power Class 3 Module (2.5W max. Power consumption)",
192: "Power Class 4 Module (3.5W max. Power consumption)",
1: "Power Class 2 Module (2.0W max. Power consumption)",
2: "Power Class 3 Module (2.5W max. Power consumption)",
3: "Power Class 4 Module (3.5W max. Power consumption)",
}

CLEI_CODE = {
0: "No CLEI code present in Page 02h",
16: "CLEI code present in Page 02h"
1: "CLEI code present in Page 02h"
}

CDR_TX = {
0: "No CDR in TX",
8: "CDR present in TX"
1: "CDR present in TX"
}

CDR_RX = {
0: "No CDR in RX",
4: "CDR present in RX"
1: "CDR present in RX"
}

ETHERNET_10_40G_COMPLIANCE = {
Expand Down Expand Up @@ -65,20 +65,20 @@ class Sff8436Codes(Sff8024):
}

FIBRE_CHANNEL_LINK_LENGTH = {
8: "Medium (M)",
16: "Long distance (L)",
32: "Intermediate distance (I)",
64: "Short distance (S)",
128: "Very long distance (V)"
1: "Medium (M)",
2: "Long distance (L)",
4: "Intermediate distance (I)",
8: "Short distance (S)",
16: "Very long distance (V)"
}

FIBRE_CHANNEL_TRANSMITTER_TECH = {
16: "Longwave Laser (LL)",
32: "Shortwave laser w OFC (SL)",
64: "Shortwave laser w/o OFC (SN)",
128: "Electrical intra-enclosure",
256: "Electrical inter-enclosure (EN)",
512: "Longwave laser (LC)"
1: "Longwave Laser (LL)",
2: "Shortwave laser w OFC (SL)",
4: "Shortwave laser w/o OFC (SN)",
8: "Electrical intra-enclosure",
16: "Electrical inter-enclosure (EN)",
32: "Longwave laser (LC)"
}

FIBRE_CHANNEL_TRANSMISSION_MEDIA = {
Expand Down
38 changes: 19 additions & 19 deletions sonic_platform_base/sonic_xcvr/codes/public/sff8472.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class Sff8472Codes(Sff8024):
192: "Power Class 4 Module (3.5W max.)",
193: "Power Class 5 Module (4.0W max.)",
194: "Power Class 6 Module (4.5W max.)",
197: "Power Class 7 Module (5.0W max.)",
195: "Power Class 7 Module (5.0W max.)",
32: "Power Class 8 Module",
}

ETHERNET_10G_COMPLIANCE = {
16: "10GBASE-SR",
32: "10GBASE-LR",
64: "10GBASE-LRM",
128: "10GBASE-ER",
1: "10GBASE-SR",
2: "10GBASE-LR",
4: "10GBASE-LRM",
8: "10GBASE-ER",
}

INFINIBAND_COMPLIANCE = {
Expand All @@ -56,8 +56,8 @@ class Sff8472Codes(Sff8024):
}

ESCON_COMPLIANCE = {
128: "ESCON MMF, 1310nm LED",
64: "ESCON SMF, 1310nm Laser"
2: "ESCON MMF, 1310nm LED",
1: "ESCON SMF, 1310nm Laser"
}

SONET_COMPLIANCE = {
Expand Down Expand Up @@ -87,21 +87,21 @@ class Sff8472Codes(Sff8024):
}

FIBRE_CHANNEL_LINK_LENGTH = {
8: "Medium (M)",
16: "Long distance (L)",
32: "Intermediate distance (I)",
64: "Short distance (S)",
128: "Very long distance (V)"
1: "Medium (M)",
2: "Long distance (L)",
4: "Intermediate distance (I)",
8: "Short distance (S)",
16: "Very long distance (V)"
}

FIBRE_CHANNEL_TRANSMITTER_TECH = {
16: "Longwave Laser (LL)",
32: "Shortwave laser w OFC (SL)",
64: "Shortwave laser w/o OFC (SN)",
128: "Electrical intra-enclosure (EL)",
256: "Electrical inter-enclosure (EL)",
512: "Longwave laser (LC)",
1024: "Shortwave laser, linear RX (SA)"
1: "Longwave Laser (LL)",
2: "Shortwave laser w OFC (SL)",
4: "Shortwave laser w/o OFC (SN)",
8: "Electrical intra-enclosure (EL)",
16: "Electrical inter-enclosure (EL)",
32: "Longwave laser (LC)",
64: "Shortwave laser, linear RX (SA)"
}

SFP_CABLE_TECH = {
Expand Down
14 changes: 7 additions & 7 deletions sonic_platform_base/sonic_xcvr/codes/public/sff8636.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Sff8636Codes(Sff8024):
192: "Power Class 4 Module (3.5W max.)",
193: "Power Class 5 Module (4.0W max.)",
194: "Power Class 6 Module (4.5W max.)",
197: "Power Class 7 Module (5.0W max.)",
195: "Power Class 7 Module (5.0W max.)",
32: "Power Class 8 Module",
}

Expand Down Expand Up @@ -91,12 +91,12 @@ class Sff8636Codes(Sff8024):
}

FIBRE_CHANNEL_TRANSMITTER_TECH = {
16: "Longwave Laser (LL)",
32: "Shortwave laser w OFC (SL)",
64: "Shortwave laser w/o OFC (SN)",
128: "Electrical intra-enclosure",
256: "Electrical inter-enclosure (EN)",
512: "Longwave laser (LC)"
1: "Longwave Laser (LL)",
2: "Shortwave laser w OFC (SL)",
4: "Shortwave laser w/o OFC (SN)",
8: "Electrical intra-enclosure",
16: "Electrical inter-enclosure (EN)",
32: "Longwave laser (LC)"
}

FIBRE_CHANNEL_TRANSMISSION_MEDIA = {
Expand Down
6 changes: 3 additions & 3 deletions sonic_platform_base/sonic_xcvr/mem_maps/public/sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def __init__(self, codes):
*(RegBitField("%s_%d" % (consts.FIBRE_CHANNEL_LINK_LENGTH_FIELD, bit), bit) for bit in range(3, 8))
),
CodeRegField(consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD, self.get_addr(0, 135), self.codes.FIBRE_CHANNEL_TRANSMITTER_TECH,
*(RegBitField("%s_%d" % (consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD, bit), bit) for bit in list(range(0,3)) + list(range(8, 16))),
size=2, format="<H"
*(RegBitField("%s_%d" % (consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD, bit), bit) for bit in range(4, 11)),
size=2, format=">H"
),
CodeRegField(consts.FIBRE_CHANNEL_TRANSMISSION_MEDIA_FIELD, self.get_addr(0, 137), self.codes.FIBRE_CHANNEL_TRANSMISSION_MEDIA),
CodeRegField(consts.FIBRE_CHANNEL_SPEED_FIELD, self.get_addr(0, 138), self.codes.FIBRE_CHANNEL_SPEED),
Expand Down Expand Up @@ -139,4 +139,4 @@ def __init__(self, codes):
)

def get_addr(self, page, offset, page_size=128):
return page * page_size + offset
return page * page_size + offset
4 changes: 2 additions & 2 deletions sonic_platform_base/sonic_xcvr/mem_maps/public/sff8636.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def __init__(self, codes):
*(RegBitField("%s_%d" % (consts.FIBRE_CHANNEL_LINK_LENGTH_FIELD, bit), bit) for bit in range(3, 8))
),
CodeRegField(consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD, self.get_addr(0, 135), self.codes.FIBRE_CHANNEL_TRANSMITTER_TECH,
*(RegBitField("%s_%d" % (consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD, bit), bit) for bit in list(range(0,3)) + list(range(8, 16))),
size=2, format="<H"
*(RegBitField("%s_%d" % (consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD, bit), bit) for bit in range(4, 11)),
size=2, format=">H"
),
CodeRegField(consts.FIBRE_CHANNEL_TRANSMISSION_MEDIA_FIELD, self.get_addr(0, 137), self.codes.FIBRE_CHANNEL_TRANSMISSION_MEDIA),
CodeRegField(consts.FIBRE_CHANNEL_SPEED_FIELD, self.get_addr(0, 138), self.codes.FIBRE_CHANNEL_SPEED),
Expand Down
31 changes: 31 additions & 0 deletions tests/sonic_xcvr/test_sff8436.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from mock import MagicMock, patch
import pytest


from sonic_platform_base.sonic_xcvr.api.public.sff8436 import Sff8436Api
from sonic_platform_base.sonic_xcvr.codes.public.sff8436 import Sff8436Codes
from sonic_platform_base.sonic_xcvr.mem_maps.public.sff8436 import Sff8436MemMap
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom
from sonic_platform_base.sonic_xcvr.fields import consts

class TestSff8436(object):
codes = Sff8436Codes
Expand Down Expand Up @@ -52,6 +55,33 @@ def test_api(self):
self.api.get_lpmode_support()
self.api.get_power_override_support()

@pytest.mark.parametrize("mock_response, expected", [
(bytearray([0x0]), "Power Class 1 Module (1.5W max. Power consumption)"),
(bytearray([0x40]), "Power Class 2 Module (2.0W max. Power consumption)"),
(bytearray([0x80]), "Power Class 3 Module (2.5W max. Power consumption)"),
(bytearray([0xC0]), "Power Class 4 Module (3.5W max. Power consumption)")
])
def test_power_class(self, mock_response, expected):
self.api.xcvr_eeprom.reader = MagicMock()
self.api.xcvr_eeprom.reader.return_value = mock_response
result = self.api.xcvr_eeprom.read(consts.POWER_CLASS_FIELD)
assert result == expected


@pytest.mark.parametrize("mock_response, expected", [
(bytearray([0x02, 0x0]), "Longwave laser (LC)"),
(bytearray([0x01, 0x0]), "Electrical inter-enclosure (EN)"),
(bytearray([0x0, 0x80]), "Electrical intra-enclosure"),
(bytearray([0x0, 0x40]), "Shortwave laser w/o OFC (SN)"),
(bytearray([0x0, 0x20]), "Shortwave laser w OFC (SL)"),
(bytearray([0x0, 0x10]), "Longwave Laser (LL)")
])
def test_fiber_channel_transmitter_tech(self, mock_response, expected):
self.api.xcvr_eeprom.reader = MagicMock()
self.api.xcvr_eeprom.reader.return_value = mock_response
result = self.api.xcvr_eeprom.read(consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD)
assert result == expected

def test_is_copper(self):
with patch.object(self.api, 'xcvr_eeprom') as mock_eeprom:
mock_eeprom.read = MagicMock()
Expand All @@ -73,3 +103,4 @@ def test_simulate_copper(self):
assert not self.api.get_rx_power_support()
assert not self.api.get_temperature_support()
assert not self.api.get_voltage_support()

16 changes: 16 additions & 0 deletions tests/sonic_xcvr/test_sff8472.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from mock import MagicMock
import sys
import pytest

from sonic_platform_base.sonic_xcvr.api.public.sff8472 import Sff8472Api
from sonic_platform_base.sonic_xcvr.codes.public.sff8472 import Sff8472Codes
Expand Down Expand Up @@ -170,3 +171,18 @@ def test_rx_power(self):
}
decoded = rx_power_field.decode(data, **deps)
assert decoded == 209.713

@pytest.mark.parametrize("mock_response, expected", [
(bytearray([0x04, 0x0]), "Shortwave laser, linear RX (SA)"),
(bytearray([0x02, 0x0]), "Longwave laser (LC)"),
(bytearray([0x01, 0x0]), "Electrical inter-enclosure (EL)"),
(bytearray([0x0, 0x80]), "Electrical intra-enclosure (EL)"),
(bytearray([0x0, 0x40]), "Shortwave laser w/o OFC (SN)"),
(bytearray([0x0, 0x20]), "Shortwave laser w OFC (SL)"),
(bytearray([0x0, 0x10]), "Longwave Laser (LL)")
])
def test_fiber_channel_transmitter_tech(self, mock_response, expected):
self.api.xcvr_eeprom.reader = MagicMock()
self.api.xcvr_eeprom.reader.return_value = mock_response
result = self.api.xcvr_eeprom.read(consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD)
assert result == expected
34 changes: 34 additions & 0 deletions tests/sonic_xcvr/test_sff8636.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from mock import MagicMock, patch
import pytest


from sonic_platform_base.sonic_xcvr.api.public.sff8636 import Sff8636Api
from sonic_platform_base.sonic_xcvr.codes.public.sff8636 import Sff8636Codes
from sonic_platform_base.sonic_xcvr.mem_maps.public.sff8636 import Sff8636MemMap
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom
from sonic_platform_base.sonic_xcvr.fields import consts

class TestSff8636(object):
codes = Sff8636Codes
Expand Down Expand Up @@ -52,6 +55,36 @@ def test_api(self):
self.api.get_lpmode_support()
self.api.get_power_override_support()

@pytest.mark.parametrize("mock_response, expected", [
(bytearray([0x0]), "Power Class 1 Module (1.5W max.)"),
(bytearray([0x40]), "Power Class 2 Module (2.0W max.)"),
(bytearray([0x80]), "Power Class 3 Module (2.5W max.)"),
(bytearray([0xC0]), "Power Class 4 Module (3.5W max.)"),
(bytearray([0xC1]), "Power Class 5 Module (4.0W max.)"),
(bytearray([0xC2]), "Power Class 6 Module (4.5W max.)"),
(bytearray([0xC3]), "Power Class 7 Module (5.0W max.)"),
(bytearray([0x20]), "Power Class 8 Module")
])
def test_power_class(self, mock_response, expected):
self.api.xcvr_eeprom.reader = MagicMock()
self.api.xcvr_eeprom.reader.return_value = mock_response
result = self.api.xcvr_eeprom.read(consts.POWER_CLASS_FIELD)
assert result == expected

@pytest.mark.parametrize("mock_response, expected", [
(bytearray([0x02, 0x0]), "Longwave laser (LC)"),
(bytearray([0x01, 0x0]), "Electrical inter-enclosure (EN)"),
(bytearray([0x0, 0x80]), "Electrical intra-enclosure"),
(bytearray([0x0, 0x40]), "Shortwave laser w/o OFC (SN)"),
(bytearray([0x0, 0x20]), "Shortwave laser w OFC (SL)"),
(bytearray([0x0, 0x10]), "Longwave Laser (LL)")
])
def test_fiber_channel_transmitter_tech(self, mock_response, expected):
self.api.xcvr_eeprom.reader = MagicMock()
self.api.xcvr_eeprom.reader.return_value = mock_response
result = self.api.xcvr_eeprom.read(consts.FIBRE_CHANNEL_TRANSMITTER_TECH_FIELD)
assert result == expected

def test_is_copper(self):
with patch.object(self.api, 'xcvr_eeprom') as mock_eeprom:
mock_eeprom.read = MagicMock()
Expand All @@ -71,3 +104,4 @@ def test_simulate_copper(self):
assert not self.api.get_rx_power_support()
assert not self.api.get_temperature_support()
assert not self.api.get_voltage_support()

0 comments on commit ce9aacb

Please sign in to comment.