Skip to content

Commit 6655396

Browse files
authored
Adding frequency grid validation for ZR optics (#466)
* Update test_xcvrd.py Added test case for frequency config validation for ZR optics * Update xcvrd.py Added change to call validation routine for laser frequency grid check. * Added 100Ghz grid check * Addresses indentation xcvrd.py * Updated xcvrd.py with proper return enum values * Updated test cases for coverage * Update for code optimisation * Added frequency and grid information is failure cases * renamed the function to validate_frequency_and_grid
1 parent 759862e commit 6655396

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

sonic-xcvrd/tests/test_xcvrd.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,7 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl):
16991699
mock_xcvr_api.get_module_pwr_up_duration = MagicMock(return_value=70000.0)
17001700
mock_xcvr_api.get_datapath_deinit_duration = MagicMock(return_value=600000.0)
17011701
mock_xcvr_api.get_cmis_rev = MagicMock(return_value='5.0')
1702+
mock_xcvr_api.get_supported_freq_config = MagicMock(return_value=(0xA0,0,0,191300,196100))
17021703
mock_xcvr_api.get_dpinit_pending = MagicMock(return_value={
17031704
'DPInitPending1': True,
17041705
'DPInitPending2': True,
@@ -2573,7 +2574,7 @@ def test_DaemonXcvrd_init_deinit_cold(self):
25732574
xcvrdaemon.deinit()
25742575

25752576
status_tbl.hdel.assert_called()
2576-
2577+
25772578
@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=(test_path, '/invalid/path')))
25782579
def test_load_optical_si_file_from_platform_folder(self):
25792580
assert optics_si_parser.load_optics_si_settings() != {}
@@ -2589,6 +2590,25 @@ def test_load_media_settings_file_from_platform_folder(self):
25892590
@patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/invalid/path', test_path)))
25902591
def test_load_media_settings_file_from_hwsku_folder(self):
25912592
assert media_settings_parser.load_media_settings() != {}
2593+
2594+
@pytest.mark.parametrize("lport, freq, grid, expected", [
2595+
(1, 193100, 75, True),
2596+
(1, 193100, 100, False),
2597+
(1, 193125, 75, False),
2598+
(1, 193100, 25, False),
2599+
(1, 191295, 75, False),
2600+
(1, 196105, 75, False)
2601+
])
2602+
def test_CmisManagerTask_validate_frequency_and_grid(self, lport, freq, grid, expected):
2603+
mock_xcvr_api = MagicMock()
2604+
mock_xcvr_api.get_supported_freq_config = MagicMock()
2605+
mock_xcvr_api.get_supported_freq_config.return_value = (0x80, 0, 0, 191300, 196100)
2606+
port_mapping = PortMapping()
2607+
stop_event = threading.Event()
2608+
task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event)
2609+
result = task.validate_frequency_and_grid(mock_xcvr_api, lport, freq, grid)
2610+
assert result == expected
2611+
25922612

25932613
def wait_until(total_wait_time, interval, call_back, *args, **kwargs):
25942614
wait_time = 0

sonic-xcvrd/xcvrd/xcvrd.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,15 +1207,32 @@ def configure_tx_output_power(self, api, lport, tx_power):
12071207
self.log_error("{} configured tx power {} > maximum power {} supported".format(lport, tx_power, max_p))
12081208
return api.set_tx_power(tx_power)
12091209

1210-
def configure_laser_frequency(self, api, lport, freq, grid=75):
1211-
_, _, _, lowf, highf = api.get_supported_freq_config()
1210+
def validate_frequency_and_grid(self, api, lport, freq, grid=75):
1211+
supported_grid, _, _, lowf, highf = api.get_supported_freq_config()
12121212
if freq < lowf:
12131213
self.log_error("{} configured freq:{} GHz is lower than the supported freq:{} GHz".format(lport, freq, lowf))
1214+
return False
12141215
if freq > highf:
12151216
self.log_error("{} configured freq:{} GHz is higher than the supported freq:{} GHz".format(lport, freq, highf))
1216-
chan = int(round((freq - 193100)/25))
1217-
if chan % 3 != 0:
1218-
self.log_error("{} configured freq:{} GHz is NOT in 75GHz grid".format(lport, freq))
1217+
return False
1218+
if grid == 75:
1219+
if (supported_grid >> 7) & 0x1 != 1:
1220+
self.log_error("{} configured freq:{}GHz supported grid:{} 75GHz is not supported".format(lport, freq, supported_grid))
1221+
return False
1222+
chan = int(round((freq - 193100)/25))
1223+
if chan % 3 != 0:
1224+
self.log_error("{} configured freq:{}GHz is NOT in 75GHz grid".format(lport, freq))
1225+
return False
1226+
elif grid == 100:
1227+
if (supported_grid >> 5) & 0x1 != 1:
1228+
self.log_error("{} configured freq:{}GHz 100GHz is not supported".format(lport, freq))
1229+
return False
1230+
else:
1231+
self.log_error("{} configured freq:{}GHz {}GHz is not supported".format(lport, freq, grid))
1232+
return False
1233+
return True
1234+
1235+
def configure_laser_frequency(self, api, lport, freq, grid=75):
12191236
if api.get_tuning_in_progress():
12201237
self.log_error("{} Tuning in progress, subport selection may fail!".format(lport))
12211238
return api.set_laser_freq(freq, grid)
@@ -1442,11 +1459,15 @@ def task_worker(self):
14421459

14431460
# For ZR module, Datapath needes to be re-initlialized on new channel selection
14441461
if api.is_coherent_module():
1445-
freq = self.port_dict[lport]['laser_freq']
1446-
# If user requested frequency is NOT the same as configured on the module
1447-
# force datapath re-initialization
1448-
if 0 != freq and freq != api.get_laser_config_freq():
1449-
need_update = True
1462+
freq = self.port_dict[lport]['laser_freq']
1463+
# If user requested frequency is NOT the same as configured on the module
1464+
# force datapath re-initialization
1465+
if 0 != freq and freq != api.get_laser_config_freq():
1466+
if self.validate_frequency_and_grid(api, lport, freq) == True:
1467+
need_update = True
1468+
else:
1469+
# clear setting of invalid frequency config
1470+
self.port_dict[lport]['laser_freq'] = 0
14501471

14511472
if not need_update:
14521473
# No application updates

0 commit comments

Comments
 (0)