Skip to content

Commit 432602a

Browse files
Update active application selected code in transceiver_info table aft… (#381)
* Update active application selected code in transceiver_info table after CMIS config finished successfully * code rearrangement * add tests for post_port_active_apsel_to_db() * also update host_lane_count and media_lane_count
1 parent 63bd9d8 commit 432602a

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

sonic-xcvrd/tests/test_xcvrd.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,89 @@ def get_host_lane_assignment_option_side_effect(app):
764764
appl = task.get_cmis_application_desired(mock_xcvr_api, host_lane_count, speed)
765765
assert task.get_cmis_host_lanes_mask(mock_xcvr_api, appl, host_lane_count, subport) == expected
766766

767+
def test_CmisManagerTask_post_port_active_apsel_to_db(self):
768+
mock_xcvr_api = MagicMock()
769+
mock_xcvr_api.get_active_apsel_hostlane = MagicMock(side_effect=[
770+
{
771+
'ActiveAppSelLane1': 1,
772+
'ActiveAppSelLane2': 1,
773+
'ActiveAppSelLane3': 1,
774+
'ActiveAppSelLane4': 1,
775+
'ActiveAppSelLane5': 1,
776+
'ActiveAppSelLane6': 1,
777+
'ActiveAppSelLane7': 1,
778+
'ActiveAppSelLane8': 1
779+
},
780+
{
781+
'ActiveAppSelLane1': 2,
782+
'ActiveAppSelLane2': 2,
783+
'ActiveAppSelLane3': 2,
784+
'ActiveAppSelLane4': 2,
785+
'ActiveAppSelLane5': 2,
786+
'ActiveAppSelLane6': 2,
787+
'ActiveAppSelLane7': 2,
788+
'ActiveAppSelLane8': 2
789+
},
790+
NotImplementedError
791+
])
792+
mock_xcvr_api.get_application_advertisement = MagicMock(side_effect=[
793+
{
794+
1: {
795+
'media_lane_count': 4,
796+
'host_lane_count': 8
797+
}
798+
},
799+
{
800+
2: {
801+
'media_lane_count': 1,
802+
'host_lane_count': 2
803+
}
804+
}
805+
])
806+
807+
int_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE)
808+
809+
port_mapping = PortMapping()
810+
stop_event = threading.Event()
811+
task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event)
812+
task.xcvr_table_helper.get_intf_tbl = MagicMock(return_value=int_tbl)
813+
814+
# case: partial lanes update
815+
lport = "Ethernet0"
816+
host_lanes_mask = 0xc
817+
ret = task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask)
818+
assert int_tbl.getKeys() == ["Ethernet0"]
819+
assert dict(int_tbl.mock_dict["Ethernet0"]) == {'active_apsel_hostlane3': '1',
820+
'active_apsel_hostlane4': '1',
821+
'host_lane_count': '8',
822+
'media_lane_count': '4'}
823+
# case: full lanes update
824+
lport = "Ethernet8"
825+
host_lanes_mask = 0xff
826+
task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask)
827+
assert int_tbl.getKeys() == ["Ethernet0", "Ethernet8"]
828+
assert dict(int_tbl.mock_dict["Ethernet0"]) == {'active_apsel_hostlane3': '1',
829+
'active_apsel_hostlane4': '1',
830+
'host_lane_count': '8',
831+
'media_lane_count': '4'}
832+
assert dict(int_tbl.mock_dict["Ethernet8"]) == {'active_apsel_hostlane1': '2',
833+
'active_apsel_hostlane2': '2',
834+
'active_apsel_hostlane3': '2',
835+
'active_apsel_hostlane4': '2',
836+
'active_apsel_hostlane5': '2',
837+
'active_apsel_hostlane6': '2',
838+
'active_apsel_hostlane7': '2',
839+
'active_apsel_hostlane8': '2',
840+
'host_lane_count': '2',
841+
'media_lane_count': '1'}
842+
843+
# case: NotImplementedError
844+
int_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE) # a new empty table
845+
lport = "Ethernet0"
846+
host_lanes_mask = 0xf
847+
ret = task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask)
848+
assert int_tbl.getKeys() == []
849+
767850
@patch('xcvrd.xcvrd.platform_chassis')
768851
@patch('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_update_event', MagicMock(return_value=(None, None)))
769852
@patch('xcvrd.xcvrd_utilities.port_mapping.handle_port_update_event', MagicMock())

sonic-xcvrd/xcvrd/xcvrd.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,36 @@ def configure_laser_frequency(self, api, lport, freq, grid=75):
13351335
self.log_error("{} Tuning in progress, subport selection may fail!".format(lport))
13361336
return api.set_laser_freq(freq, grid)
13371337

1338+
def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask):
1339+
try:
1340+
act_apsel = api.get_active_apsel_hostlane()
1341+
appl_advt = api.get_application_advertisement()
1342+
except NotImplementedError:
1343+
helper_logger.log_error("Required feature is not implemented")
1344+
return
1345+
1346+
tuple_list = []
1347+
for lane in range(self.CMIS_MAX_HOST_LANES):
1348+
if ((1 << lane) & host_lanes_mask) == 0:
1349+
continue
1350+
act_apsel_lane = act_apsel.get('ActiveAppSelLane{}'.format(lane + 1), 'N/A')
1351+
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1),
1352+
str(act_apsel_lane)))
1353+
1354+
# also update host_lane_count and media_lane_count
1355+
if len(tuple_list) > 0:
1356+
appl_advt_act = appl_advt.get(act_apsel_lane)
1357+
host_lane_count = appl_advt_act.get('host_lane_count', 'N/A') if appl_advt_act else 'N/A'
1358+
tuple_list.append(('host_lane_count', str(host_lane_count)))
1359+
media_lane_count = appl_advt_act.get('media_lane_count', 'N/A') if appl_advt_act else 'N/A'
1360+
tuple_list.append(('media_lane_count', str(media_lane_count)))
1361+
1362+
asic_index = self.port_mapping.get_asic_id_for_logical_port(lport)
1363+
intf_tbl = self.xcvr_table_helper.get_intf_tbl(asic_index)
1364+
fvs = swsscommon.FieldValuePairs(tuple_list)
1365+
intf_tbl.set(lport, fvs)
1366+
self.log_notice("{}: updated TRANSCEIVER_INFO_TABLE {}".format(lport, tuple_list))
1367+
13381368
def wait_for_port_config_done(self, namespace):
13391369
# Connect to APPL_DB and subscribe to PORT table notifications
13401370
appl_db = daemon_base.db_connect("APPL_DB", namespace=namespace)
@@ -1641,6 +1671,7 @@ def task_worker(self):
16411671

16421672
self.log_notice("{}: READY".format(lport))
16431673
self.port_dict[lport]['cmis_state'] = self.CMIS_STATE_READY
1674+
self.post_port_active_apsel_to_db(api, lport, host_lanes_mask)
16441675

16451676
except (NotImplementedError, AttributeError) as e:
16461677
self.log_error("{}: internal errors due to {}".format(lport, e))

0 commit comments

Comments
 (0)