Skip to content

Commit 9f3a124

Browse files
authored
Retrieve subport from CONFIG_DB to enable breakout support (#342)
Retrieve subport from CONFIG_DB to enable breakout support --------- Signed-off-by: Mihir Patel <[email protected]>
1 parent 3d9cca6 commit 9f3a124

File tree

2 files changed

+241
-87
lines changed

2 files changed

+241
-87
lines changed

sonic-xcvrd/tests/test_xcvrd.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from xcvrd.xcvrd_utilities.port_mapping import *
33
from xcvrd.xcvrd_utilities.sfp_status_helper import *
44
from xcvrd.xcvrd import *
5+
import pytest
56
import copy
67
import os
78
import sys
@@ -653,6 +654,111 @@ def test_CmisManagerTask_task_run_stop(self, mock_chassis):
653654
cmis_manager.join()
654655
assert not cmis_manager.is_alive()
655656

657+
DEFAULT_DP_STATE = {
658+
'DP1State': 'DataPathActivated',
659+
'DP2State': 'DataPathActivated',
660+
'DP3State': 'DataPathActivated',
661+
'DP4State': 'DataPathActivated',
662+
'DP5State': 'DataPathActivated',
663+
'DP6State': 'DataPathActivated',
664+
'DP7State': 'DataPathActivated',
665+
'DP8State': 'DataPathActivated'
666+
}
667+
DEFAULT_CONFIG_STATUS = {
668+
'ConfigStatusLane1': 'ConfigSuccess',
669+
'ConfigStatusLane2': 'ConfigSuccess',
670+
'ConfigStatusLane3': 'ConfigSuccess',
671+
'ConfigStatusLane4': 'ConfigSuccess',
672+
'ConfigStatusLane5': 'ConfigSuccess',
673+
'ConfigStatusLane6': 'ConfigSuccess',
674+
'ConfigStatusLane7': 'ConfigSuccess',
675+
'ConfigStatusLane8': 'ConfigSuccess'
676+
}
677+
CONFIG_LANE_8_UNDEFINED = {
678+
'ConfigStatusLane1': 'ConfigSuccess',
679+
'ConfigStatusLane2': 'ConfigSuccess',
680+
'ConfigStatusLane3': 'ConfigSuccess',
681+
'ConfigStatusLane4': 'ConfigSuccess',
682+
'ConfigStatusLane5': 'ConfigSuccess',
683+
'ConfigStatusLane6': 'ConfigSuccess',
684+
'ConfigStatusLane7': 'ConfigSuccess',
685+
'ConfigStatusLane8': 'ConfigUndefined'
686+
}
687+
@pytest.mark.parametrize("app_new, host_lanes_mask, lane_appl_code, default_dp_state, default_config_status, expected", [
688+
(1, 0x0F, {0 : 1, 1 : 1, 2 : 1, 3 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False),
689+
(1, 0x0F, {0 : 1, 1 : 1, 2 : 1, 3 : 0}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True),
690+
(1, 0xF0, {4 : 1, 5 : 1, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False),
691+
(1, 0xF0, {4 : 1, 5 : 1, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, CONFIG_LANE_8_UNDEFINED, True),
692+
(1, 0xF0, {4 : 1, 5 : 7, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True),
693+
(4, 0xF0, {4 : 1, 5 : 7, 6 : 1, 7 : 1}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True),
694+
(3, 0xC0, {7 : 3, 8 : 3}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False),
695+
(1, 0x0F, {}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, True),
696+
(-1, 0x0F, {}, DEFAULT_DP_STATE, DEFAULT_CONFIG_STATUS, False)
697+
])
698+
def test_CmisManagerTask_is_cmis_application_update_required(self, app_new, host_lanes_mask, lane_appl_code, default_dp_state, default_config_status, expected):
699+
700+
mock_xcvr_api = MagicMock()
701+
mock_xcvr_api.is_flat_memory = MagicMock(return_value=False)
702+
703+
def get_application(lane):
704+
return lane_appl_code.get(lane, 0)
705+
mock_xcvr_api.get_application = MagicMock(side_effect=get_application)
706+
707+
mock_xcvr_api.get_datapath_state = MagicMock(return_value=default_dp_state)
708+
mock_xcvr_api.get_config_datapath_hostlane_status = MagicMock(return_value=default_config_status)
709+
710+
port_mapping = PortMapping()
711+
stop_event = threading.Event()
712+
task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event)
713+
714+
assert task.is_cmis_application_update_required(mock_xcvr_api, app_new, host_lanes_mask) == expected
715+
716+
@pytest.mark.parametrize("host_lane_count, speed, subport, expected", [
717+
(8, 400000, 0, 0xFF),
718+
(4, 100000, 1, 0xF),
719+
(4, 100000, 2, 0xF0),
720+
(4, 100000, 0, 0xF),
721+
(4, 100000, 9, 0x0),
722+
(1, 50000, 2, 0x2),
723+
(1, 200000, 2, 0x0)
724+
])
725+
def test_CmisManagerTask_get_cmis_host_lanes_mask(self, host_lane_count, speed, subport, expected):
726+
appl_advert_dict = {
727+
1: {
728+
'host_electrical_interface_id': '400GAUI-8 C2M (Annex 120E)',
729+
'module_media_interface_id': '400GBASE-DR4 (Cl 124)',
730+
'media_lane_count': 4,
731+
'host_lane_count': 8,
732+
'host_lane_assignment_options': 1
733+
},
734+
2: {
735+
'host_electrical_interface_id': 'CAUI-4 C2M (Annex 83E)',
736+
'module_media_interface_id': 'Active Cable assembly with BER < 5x10^-5',
737+
'media_lane_count': 4,
738+
'host_lane_count': 4,
739+
'host_lane_assignment_options': 17
740+
},
741+
3: {
742+
'host_electrical_interface_id': '50GAUI-1 C2M',
743+
'module_media_interface_id': '50GBASE-SR',
744+
'media_lane_count': 1,
745+
'host_lane_count': 1,
746+
'host_lane_assignment_options': 255
747+
}
748+
}
749+
mock_xcvr_api = MagicMock()
750+
mock_xcvr_api.get_application_advertisement = MagicMock(return_value=appl_advert_dict)
751+
752+
def get_host_lane_assignment_option_side_effect(app):
753+
return appl_advert_dict[app]['host_lane_assignment_options']
754+
mock_xcvr_api.get_host_lane_assignment_option = MagicMock(side_effect=get_host_lane_assignment_option_side_effect)
755+
port_mapping = PortMapping()
756+
stop_event = threading.Event()
757+
task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event)
758+
759+
appl = task.get_cmis_application_desired(mock_xcvr_api, host_lane_count, speed)
760+
assert task.get_cmis_host_lanes_mask(mock_xcvr_api, appl, host_lane_count, subport) == expected
761+
656762
@patch('xcvrd.xcvrd.platform_chassis')
657763
@patch('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_update_event', MagicMock(return_value=(None, None)))
658764
@patch('xcvrd.xcvrd_utilities.port_mapping.handle_port_update_event', MagicMock())

0 commit comments

Comments
 (0)