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

[xcvrd] Add to support MEDIA_LANE_SPEED_KEY in media_settings.json #528

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"GLOBAL_MEDIA_SETTINGS": {
Copy link
Collaborator

@prgeor prgeor Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcsteven why not make use of regex like so:-

*-10GBASE-CR* {

}

"*-50GBASE-* {

}

Ref:-#471

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order not to misunderstand your suggestion, I would like to re-address your suggestion as:

why not make use of regex with 'media_key' or 'lane_speed_key' ?

A. Here is my response with the sample media_settings.json and Transceiver information in B. and C. as below.

A.1
However, it is possible to construct 'media_key' with regex as in the media_settings.json as below B.1.
In Breakout mode 2x200G in physical_port=1 and 1x400G in physical_port=2, 'lane_speed_key' can't help to locate the media_dict (Pre-empassis setting).
From this Transceiver information, 'lane_speed_key' are different in :
- 'lane_speed_key'='speed:400G' for Breakout mode 1x400G physical_port=2
- 'lane_speed_key': 'speed:200GBASE-CR4' for Breakout mode 2x200G physical_port=1

However, it is possible to resolve this issue via duplicating the same media_dict for "speed:400G*" and "speed:200G*" as below media-settings.json in B.1.

But, the above resolution still does not resolve the issue for the Transceiver QSFP28-* in physical_port=5,9,13,14.
However, it is still possible to resolve this issue via adding another 'lane_speed_key' format or add another 'media_key' for physical_port=5,9,13,14, but I think that is not the purpose that the regex to simplify the media_setting.sjon format.

A.2
To refer to B.2, you will see that 'media_lane_speed_key' could help to simplify media_settings.json in our platform.

B. Sample media_settings.json

B.1 To construct the media_settings.json with 'media_key' and 'lane_speed_key'

{
    "GLOBAL_MEDIA_SETTINGS": {
        "1-32": {
           "QSFP-DD-passive_copper_media_interface-*|QSFP28-*-CR4*":{
				"speed:400G*":{
					"post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
					"post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
					"pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
					"preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
					},
				"speed:200G*":{
					"post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
					"post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
					"pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
					"preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
					}
				},
        	"QSFP-DD-passive_copper_media_interface-*|QSFP28-Unknown-*":{
				"post2": {"lane0": "0x101","lane1": "0x101","lane2": "0x101","lane3": "0x101","lane4": "0x101","lane5": "0x101","lane6": "0x101","lane7": "0x101"},
				"post3": {"lane0": "0x101","lane1": "0x101", "lane2": "0x101","lane3": "0x101","lane4": "0x101","lane5": "0x101","lane6": "0x101","lane7": "0x101"},
				"pre2": {"lane0": "0x101","lane1": "0x101","lane2": "0x101","lane3": "0x101","lane4": "0x101","lane5": "0x101","lane6": "0x101","lane7": "0x101"},
				"preemphasis": {"lane0": "0x007F01","lane1": "0x007F01","lane2": "0x007F01","lane3": "0x007F01","lane4": "0x007F01","lane5": "0x007F01","lane6": "0x007F01","lane7": "0x007F01"}
				}
		}
	}
}

B.2 To construct the media_settings.json with 'media_lane_speed_key'

{
    "GLOBAL_MEDIA_SETTINGS": {
		"1-32": {
			"50000,CR":{
				"post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
				"post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
				"pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
				"preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
				},
			"50000":{
				"post2": {"lane0": "0x102","lane1": "0x102","lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
				"post3": {"lane0": "0x102","lane1": "0x102", "lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
				"pre2": {"lane0": "0x102","lane1": "0x102","lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
				"preemphasis": {"lane0": "0x007F02","lane1": "0x007F02","lane2": "0x007F02","lane3": "0x007F02","lane4": "0x007F02","lane5": "0x007F02","lane6": "0x007F02","lane7": "0x007F02"}
				}
			}
	}
}

C. Sample Transceiver information

**For Brteakout mode is 2x200G in physical_port=1**

physical_port=1  logical_port_name=Ethernet0, port_speed=200000 lane_count=4 
key={
	'vendor_key': 'EDGECORE        -ET7502-DAC-2.5M ', 
	'media_key': 'QSFP-DD-passive_copper_media_interface-2.5M', 
	'lane_speed_key': 'speed:200GBASE-CR4', 
	'media_lane_speed_key': '50000,CR'
	}
media_dict={
            "post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
        	}

physical_port=1 logical_port_name=Ethernet4, port_speed=200000 lane_count=4 
key={
	'vendor_key': 'EDGECORE        -ET7502-DAC-2.5M ', 
	'media_key': 'QSFP-DD-passive_copper_media_interface-2.5M', 
	'lane_speed_key': 'speed:200GBASE-CR4', 
	'media_lane_speed_key': '50000,CR'
	}
media_dict={
            "post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
        	}

**For Breakout mode is 1x400G, physical_port=2,5,9,13,14**
physical_port=2  logical_port_name=Ethernet8, port_speed=400000 lane_count=8 
key={
	'vendor_key': 'EDGECORE        -ET7502-DAC-2.5M ', 
	'media_key': 'QSFP-DD-passive_copper_media_interface-2.5M', 
	'lane_speed_key': 'speed:400G', 
	'media_lane_speed_key': '50000,CR'
	}
media_dict={
            "post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
        	}

physical_port=5 logical_port_name=Ethernet32, port_speed=400000 lane_count=8 
key={
	'vendor_key': 'EDGECORE        -ET7502-LR4      ', 
	'media_key': 'QSFP-DD-sm_media_interface', 
	'lane_speed_key': 'speed:400GAUI-8', 
	'media_lane_speed_key': '50000'
	}
media_dict={
            "post2": {"lane0": "0x102","lane1": "0x102","lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
            "post3": {"lane0": "0x102","lane1": "0x102", "lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
            "pre2": {"lane0": "0x102","lane1": "0x102","lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
            "preemphasis": {"lane0": "0x007F02","lane1": "0x007F02","lane2": "0x007F02","lane3": "0x007F02","lane4": "0x007F02","lane5": "0x007F02","lane6": "0x007F02","lane7": "0x007F02"}
        	}

physical_port=9  logical_port_name=Ethernet64, port_speed=400000 lane_count=8 
key={
	'vendor_key': 'EDGECORE        -ET7402-LR4      ', 
	'media_key': 'QSFP28-Unknown-M', 
	'lane_speed_key': None, 
	'media_lane_speed_key': '50000'
	}
media_dict={
            "post2": {"lane0": "0x102","lane1": "0x102","lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
            "post3": {"lane0": "0x102","lane1": "0x102", "lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
            "pre2": {"lane0": "0x102","lane1": "0x102","lane2": "0x102","lane3": "0x102","lane4": "0x102","lane5": "0x102","lane6": "0x102","lane7": "0x102"},
            "preemphasis": {"lane0": "0x007F02","lane1": "0x007F02","lane2": "0x007F02","lane3": "0x007F02","lane4": "0x007F02","lane5": "0x007F02","lane6": "0x007F02","lane7": "0x007F02"}
        	}

physical_port=13 logical_port_name=Ethernet96, port_speed=400000 lane_count=8 
key={
	'vendor_key': 'EDGECORE        -ET7402-DAC-0.5M ', 
	'media_key': 'QSFP28-40GBASE-CR4-1.0M', 
	'lane_speed_key': None, 
	'media_lane_speed_key': '50000,CR'
	}
media_dict={
            "post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
        	}

physical_port=14 logical_port_name=Ethernet104, port_speed=400000 lane_count=8 
key={
	'vendor_key': 'EDGECORE        -ET7402-DAC-0.5M ', 
	'media_key': 'QSFP28-40GBASE-CR4-1.0M', 
	'lane_speed_key': None, 
	'media_lane_speed_key': '50000,CR'
	}
media_dict={
            "post2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "post3": {"lane0": "0x100","lane1": "0x100", "lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "pre2": {"lane0": "0x100","lane1": "0x100","lane2": "0x100","lane3": "0x100","lane4": "0x100","lane5": "0x100","lane6": "0x100","lane7": "0x100"},
            "preemphasis": {"lane0": "0x007F00","lane1": "0x007F00","lane2": "0x007F00","lane3": "0x007F00","lane4": "0x007F00","lane5": "0x007F00","lane6": "0x007F00","lane7": "0x007F00"}
        	}

"1-32": {
"10000,CR":{
"preemphasis": {
"lane0":"0x16440A",
"lane1":"0x16440A",
"lane2":"0x16440A",
"lane3":"0x16440A"
}
},
"25000,CR":{
"preemphasis": {
"lane0":"0x16440B",
"lane1":"0x16440B",
"lane2":"0x16440B",
"lane3":"0x16440B"
}
},
"50000,CR":{
"preemphasis": {
"lane0":"0x16440C",
"lane1":"0x16440C",
"lane2":"0x16440C",
"lane3":"0x16440C"
}
},
"10000":{
"preemphasis": {
"lane0":"0x1A400A",
"lane1":"0x1A400A",
"lane2":"0x1A400A",
"lane3":"0x1A400A"
}
},
"25000":{
"preemphasis": {
"lane0":"0x1A400B",
"lane1":"0x1A400B",
"lane2":"0x1A400B",
"lane3":"0x1A400B"
}
},
"50000":{
"preemphasis": {
"lane0":"0x1A400C",
"lane1":"0x1A400C",
"lane2":"0x1A400C",
"lane3":"0x1A400C"
}
}
}
}
}
79 changes: 75 additions & 4 deletions sonic-xcvrd/tests/test_xcvrd.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@
media_settings_port_default_media_key_lane_speed_si = copy.deepcopy(media_settings_port_media_key_lane_speed_si)
media_settings_port_default_media_key_lane_speed_si['PORT_MEDIA_SETTINGS']['7']['Default'] = {'speed:400GAUI-8': {'idriver': {'lane0': '0x0000000d', 'lane1': '0x0000000d', 'lane2': '0x0000000d', 'lane3': '0x0000000d'}, 'pre1': {'lane0': '0x0000000d', 'lane1': '0x0000000d', 'lane2': '0x0000000d', 'lane3': '0x0000000d'}, 'ob_m2lp': {'lane0': '0x0000000d', 'lane1': '0x0000000d', 'lane2': '0x0000000d', 'lane3': '0x0000000d'}}}

# Creating instances of media_settings.json for media_lane_speed_key
with open(os.path.join(test_path, 'media_settings_with_media_lane_speed_key_format.json'), 'r') as f:
media_settings_mls_key_dict = json.load(f)

# Generate media_settings in 'GLOBAL_MEDIA_SETTINGS' with media_lane_speed_key for range port[1-32]
media_settings_global_range_mls_key_dict = copy.deepcopy(media_settings_mls_key_dict)

# Generate media_settings in 'PORT_MEDIA_SETTINGS' with media_lane_speed_key for port list
media_settings_port_list_mls_key_dict = {'PORT_MEDIA_SETTINGS':{}}
media_settings_port_list_mls_key_dict['PORT_MEDIA_SETTINGS'] = {f'{i}': copy.deepcopy(media_settings_mls_key_dict['GLOBAL_MEDIA_SETTINGS']['1-32']) for i in range(1,33) }

media_settings_empty = {}


Expand Down Expand Up @@ -642,6 +653,60 @@ def test_init_port_sfp_status_tbl(self):
def test_load_media_settings_missing_file(self):
assert media_settings_parser.load_media_settings() == {}

@pytest.mark.parametrize("physical_port, port_speed, lane_count", [
(1,"10000","1"),
(1, "10000","1"),
(1, "40000","4"),
(1,"40000","4"),
(1,"25000","1"),
(1,"25000","1"),
(1,"100000","4"),
(1,"100000","4")
])
@patch('xcvrd.xcvrd.platform_chassis')
def test_get_media_lane_speed_key(self, mock_chassis, physical_port, port_speed, lane_count):
#print("\ntest_get_media_lane_speed_key-start")

# Mock objects
mock_api = MagicMock(name="mock api")
mock_sfp = MagicMock(name="mock sfp")
mock_sfp.get_xcvr_api.return_value = mock_api
mock_chassis.get_sfp.return_value = mock_sfp

expect_lane_speed = int(int(port_speed)/int(lane_count))

# Test case for is_copper mock is True
mock_api.is_copper.return_value = True
result = get_media_lane_speed_key(physical_port, port_speed, lane_count)
expected = "{},CR".format(expect_lane_speed)
assert result == expected

# Test case for is_copper mock is False
mock_api.is_copper.return_value = False
result = get_media_lane_speed_key(physical_port, port_speed, lane_count)
expected = "{}".format(expect_lane_speed)
assert result == expected

# Test case for is_copper mock is None
mock_api.is_copper.return_value = None
result = get_media_lane_speed_key(physical_port, port_speed, lane_count)
expected = "{},UNKNOWN".format(expect_lane_speed)
assert result == expected

# Test casese for mock as api.is_copper raises [NotImplementedError]
mock_api.is_copper.reset_mock()
mock_api.is_copper.side_effect = NotImplementedError
expected = "{},UNKNOWN".format(expect_lane_speed)
result = get_media_lane_speed_key(physical_port, port_speed, lane_count)
assert result == expected

# Test casese for mock as sfp = xcvrd.platform_chassis.get_sfp(physical_port)= IndexError
mock_chassis.get_sfp.reset_mock()
mock_chassis.get_sfp.side_effect = IndexError
result = get_media_lane_speed_key(physical_port, port_speed, lane_count)
expected = "{},UNKNOWN".format(expect_lane_speed)
assert result == expected

@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/invalid/path', '/invalid/path')))
def test_load_optical_si_settings_missing_file(self):
assert optics_si_parser.load_optics_si_settings() == {}
Expand All @@ -654,6 +719,7 @@ def test_get_media_settings_key(self, mock_is_cmis_api, mock_chassis):
mock_api = MagicMock()
mock_sfp.get_xcvr_api = MagicMock(return_value=mock_api)
mock_is_cmis_api.return_value = False
mock_api.is_copper.return_value = True

xcvr_info_dict = {
0: {
Expand All @@ -668,12 +734,12 @@ def test_get_media_settings_key(self, mock_is_cmis_api, mock_chassis):

# Test a good 'specification_compliance' value
result = media_settings_parser.get_media_settings_key(0, xcvr_info_dict, 100000, 2)
assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-10GBase-SR-255M', 'lane_speed_key': None }
assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-10GBase-SR-255M', 'lane_speed_key': None ,'media_lane_speed_key': '50000,CR' }

# Test a bad 'specification_compliance' value
xcvr_info_dict[0]['specification_compliance'] = 'N/A'
result = media_settings_parser.get_media_settings_key(0, xcvr_info_dict, 100000, 2)
assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-*', 'lane_speed_key': None }
assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP+-*', 'lane_speed_key': None, 'media_lane_speed_key': '50000,CR' }
# TODO: Ensure that error message was logged

mock_is_cmis_api.return_value = True
Expand All @@ -700,8 +766,9 @@ def test_get_media_settings_key(self, mock_is_cmis_api, mock_chassis):
}

mock_api.get_application_advertisement = MagicMock(return_value=mock_app_adv_value)
mock_api.is_copper.return_value = False
result = media_settings_parser.get_media_settings_key(0, xcvr_info_dict, 100000, 2)
assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP-DD-sm_media_interface', 'lane_speed_key': 'speed:100GBASE-CR2' }
assert result == { 'vendor_key': 'MOLEX-1064141421', 'media_key': 'QSFP-DD-sm_media_interface', 'lane_speed_key': 'speed:100GBASE-CR2', 'media_lane_speed_key': '50000' }

@pytest.mark.parametrize("data_found, data, expected", [
(True, [('speed', '400000'), ('lanes', '1,2,3,4,5,6,7,8'), ('mtu', '9100')], ('400000', 8)),
Expand Down Expand Up @@ -802,7 +869,11 @@ def test_is_si_per_speed_supported(self):
(media_settings_empty, 7, {'vendor_key': 'AMPHANOL-5678', 'media_key': 'QSFP-DD-active_cable_media_interface', 'lane_speed_key': 'speed:100GAUI-2'}, {}),
(media_settings_with_regular_expression_dict, 7, {'vendor_key': 'UNKOWN', 'media_key': 'QSFP28-40GBASE-CR4-1M', 'lane_speed_key': 'UNKOWN'}, {'preemphasis': {'lane0': '0x16440A', 'lane1': '0x16440A', 'lane2': '0x16440A', 'lane3': '0x16440A'}}),
(media_settings_with_regular_expression_dict, 7, {'vendor_key': 'UNKOWN', 'media_key': 'QSFP+-40GBASE-CR4-2M', 'lane_speed_key': 'UNKOWN'}, {'preemphasis': {'lane0': '0x18420A', 'lane1': '0x18420A', 'lane2': '0x18420A', 'lane3': '0x18420A'}}),
(media_settings_with_regular_expression_dict, 7, {'vendor_key': 'UNKOWN', 'media_key': 'QSFP+-40GBASE-CR4-10M', 'lane_speed_key': 'UNKOWN'}, {'preemphasis': {'lane0': '0x1A400A', 'lane1': '0x1A400A', 'lane2': '0x1A400A', 'lane3': '0x1A400A'}})
(media_settings_with_regular_expression_dict, 7, {'vendor_key': 'UNKOWN', 'media_key': 'QSFP+-40GBASE-CR4-10M', 'lane_speed_key': 'UNKOWN'}, {'preemphasis': {'lane0': '0x1A400A', 'lane1': '0x1A400A', 'lane2': '0x1A400A', 'lane3': '0x1A400A'}}),
(media_settings_global_range_mls_key_dict, 7, {'vendor_key': 'UNKOWN', 'media_key': 'MISSING', 'lane_speed_key': 'UNKOWN', 'media_lane_speed_key': '50000,CR'}, {'preemphasis': {'lane0': '0x16440C', 'lane1': '0x16440C', 'lane2': '0x16440C', 'lane3': '0x16440C'}}),
(media_settings_global_range_mls_key_dict, 7, {'vendor_key': 'UNKOWN','media_key': 'MISSING' , 'lane_speed_key': 'UNKOWN', 'media_lane_speed_key': '50000'}, {'preemphasis': {'lane0': '0x1A400C', 'lane1': '0x1A400C', 'lane2': '0x1A400C', 'lane3': '0x1A400C'}} ),
(media_settings_port_list_mls_key_dict, 7, {'vendor_key': 'UNKOWN','media_key': 'MISSING' , 'lane_speed_key': 'UNKOWN', 'media_lane_speed_key': '25000,CR'}, {'preemphasis': {'lane0': '0x16440B', 'lane1': '0x16440B', 'lane2': '0x16440B', 'lane3': '0x16440B'}}),
(media_settings_port_list_mls_key_dict, 7, {'vendor_key': 'UNKOWN','media_key': 'MISSING' , 'lane_speed_key': 'UNKOWN', 'media_lane_speed_key': '25000'}, {'preemphasis': {'lane0': '0x1A400B', 'lane1': '0x1A400B', 'lane2': '0x1A400B', 'lane3': '0x1A400B'}})
])
def test_get_media_settings_value(self, media_settings_dict, port, key, expected):
with patch('xcvrd.xcvrd_utilities.media_settings_parser.g_dict', media_settings_dict):
Expand Down
26 changes: 25 additions & 1 deletion sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
VENDOR_KEY = 'vendor_key'
MEDIA_KEY = 'media_key'
LANE_SPEED_KEY = 'lane_speed_key'
MEDIA_LANE_SPEED_KEY = 'media_lane_speed_key'
SYSLOG_IDENTIFIER = "xcvrd"
helper_logger = logger.Logger(SYSLOG_IDENTIFIER)

Expand Down Expand Up @@ -62,6 +63,26 @@ def get_lane_speed_key(physical_port, port_speed, lane_count):

return lane_speed_key

def get_media_lane_speed_key(physical_port, port_speed, lane_count):
is_copper = None
media_lane_speed = ""

lane_speed = int(int(port_speed)/int(lane_count))
try:
sfp = xcvrd.platform_chassis.get_sfp(physical_port)
api = sfp.get_xcvr_api()
is_copper = api.is_copper()

except Exception as e:
helper_logger.log_notice("Invalid information of xcvrd is_copper api for port {}".format(physical_port))

if is_copper is True: # For Copper lane_speed =25000, '25000,CR'
media_lane_speed = "{},CR".format(lane_speed)
elif is_copper is False: # For Fiber lane_speed =25000, '25000'
media_lane_speed = "{}".format(lane_speed)
else: # For known media lane_speed =25000, '25000,UNKNOWN'
media_lane_speed = "{},UNKNOWN".format(lane_speed)
return media_lane_speed

def get_media_settings_key(physical_port, transceiver_dict, port_speed, lane_count):
sup_compliance_str = '10/40G Ethernet Compliance Code'
Expand Down Expand Up @@ -111,11 +132,13 @@ def get_media_settings_key(physical_port, transceiver_dict, port_speed, lane_cou
media_key += '-' + '*'

lane_speed_key = get_lane_speed_key(physical_port, port_speed, lane_count)
media_lane_speed_key = get_media_lane_speed_key(physical_port,port_speed,lane_count)
# return (vendor_key, media_key, lane_speed_key)
return {
VENDOR_KEY: vendor_key,
MEDIA_KEY: media_key,
LANE_SPEED_KEY: lane_speed_key
LANE_SPEED_KEY: lane_speed_key,
MEDIA_LANE_SPEED_KEY: media_lane_speed_key
}


Expand Down Expand Up @@ -180,6 +203,7 @@ def get_media_settings(key, media_dict):
for dict_key in media_dict.keys():
if (re.match(dict_key, key[VENDOR_KEY]) or \
re.match(dict_key, key[VENDOR_KEY].split('-')[0]) # e.g: 'AMPHENOL-1234'
or (key.get(MEDIA_LANE_SPEED_KEY) and re.match(dict_key, key[MEDIA_LANE_SPEED_KEY])) # e.g: '50000,CR' or '50000'
or re.match(dict_key, key[MEDIA_KEY]) ): # e.g: 'QSFP28-40GBASE-CR4-1M'
if is_si_per_speed_supported(media_dict[dict_key]):
if key[LANE_SPEED_KEY] is not None and key[LANE_SPEED_KEY] in media_dict[dict_key]: # e.g: 'speed:400GAUI-8'
Expand Down
Loading