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

reset active application code as 'N/A' when port shutdown #550

Open
wants to merge 3 commits 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
31 changes: 31 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,32 @@ def test_CmisManagerTask_post_port_active_apsel_to_db(self):
'host_lane_count': '2',
'media_lane_count': '1'}

# case: partial lanes update (reset to 'N/A')
lport = "Ethernet16"
host_lanes_mask = 0xc
ret = task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask, reset_apsel=True)
assert int_tbl.getKeys() == ["Ethernet0", "Ethernet8", "Ethernet16"]
assert dict(int_tbl.mock_dict["Ethernet16"]) == {'active_apsel_hostlane3': 'N/A',
'active_apsel_hostlane4': 'N/A',
'host_lane_count': 'N/A',
'media_lane_count': 'N/A'}

# case: full lanes update (reset to 'N/A')
lport = "Ethernet32"
host_lanes_mask = 0xff
task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask, reset_apsel=True)
assert int_tbl.getKeys() == ["Ethernet0", "Ethernet8", "Ethernet16", "Ethernet32"]
assert dict(int_tbl.mock_dict["Ethernet32"]) == {'active_apsel_hostlane1': 'N/A',
'active_apsel_hostlane2': 'N/A',
'active_apsel_hostlane3': 'N/A',
'active_apsel_hostlane4': 'N/A',
'active_apsel_hostlane5': 'N/A',
'active_apsel_hostlane6': 'N/A',
'active_apsel_hostlane7': 'N/A',
'active_apsel_hostlane8': 'N/A',
'host_lane_count': 'N/A',
'media_lane_count': 'N/A'}

# case: NotImplementedError
int_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE) # a new empty table
lport = "Ethernet0"
Expand Down Expand Up @@ -2384,10 +2410,13 @@ def test_CmisManagerTask_task_worker_fastboot(self, mock_chassis, mock_get_statu
task.get_configured_laser_freq_from_db = MagicMock(return_value=193100)
task.configure_tx_output_power = MagicMock(return_value=1)
task.configure_laser_frequency = MagicMock(return_value=1)
task.post_port_active_apsel_to_db = MagicMock()

task.task_stopping_event.is_set = MagicMock(side_effect=[False, False, True])
task.task_worker()

assert mock_xcvr_api.tx_disable_channel.call_count == 1
assert task.post_port_active_apsel_to_db.call_count == 1
assert get_cmis_state_from_state_db('Ethernet0', task.xcvr_table_helper.get_status_tbl(task.port_mapping.get_asic_id_for_logical_port('Ethernet0'))) == CMIS_STATE_READY

@patch('xcvrd.xcvrd.XcvrTableHelper.get_status_tbl')
Expand Down Expand Up @@ -2519,10 +2548,12 @@ def test_CmisManagerTask_task_worker_host_tx_ready_false(self, mock_chassis, moc
task.get_configured_laser_freq_from_db = MagicMock(return_value=193100)
task.configure_tx_output_power = MagicMock(return_value=1)
task.configure_laser_frequency = MagicMock(return_value=1)
task.post_port_active_apsel_to_db = MagicMock()

task.task_stopping_event.is_set = MagicMock(side_effect=[False, False, True])
task.task_worker()

assert task.post_port_active_apsel_to_db.call_count == 1
assert mock_xcvr_api.tx_disable_channel.call_count == 1
assert get_cmis_state_from_state_db('Ethernet0', task.xcvr_table_helper.get_status_tbl(task.port_mapping.get_asic_id_for_logical_port('Ethernet0'))) == CMIS_STATE_READY

Expand Down
39 changes: 24 additions & 15 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,29 +1244,37 @@ def configure_laser_frequency(self, api, lport, freq, grid=75):
self.log_error("{} Tuning in progress, subport selection may fail!".format(lport))
return api.set_laser_freq(freq, grid)

def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask):
try:
act_apsel = api.get_active_apsel_hostlane()
appl_advt = api.get_application_advertisement()
except NotImplementedError:
helper_logger.log_error("Required feature is not implemented")
return
def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask, reset_apsel=False):
if reset_apsel == False:
try:
act_apsel = api.get_active_apsel_hostlane()
appl_advt = api.get_application_advertisement()
except NotImplementedError:
helper_logger.log_error("Required feature is not implemented")
return

tuple_list = []
for lane in range(self.CMIS_MAX_HOST_LANES):
if ((1 << lane) & host_lanes_mask) == 0:
continue
act_apsel_lane = act_apsel.get('ActiveAppSelLane{}'.format(lane + 1), 'N/A')
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1),
str(act_apsel_lane)))
if reset_apsel == False:
act_apsel_lane = act_apsel.get('ActiveAppSelLane{}'.format(lane + 1), 'N/A')
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1),
str(act_apsel_lane)))
else:
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1), 'N/A'))

# also update host_lane_count and media_lane_count
if len(tuple_list) > 0:
appl_advt_act = appl_advt.get(act_apsel_lane)
host_lane_count = appl_advt_act.get('host_lane_count', 'N/A') if appl_advt_act else 'N/A'
tuple_list.append(('host_lane_count', str(host_lane_count)))
media_lane_count = appl_advt_act.get('media_lane_count', 'N/A') if appl_advt_act else 'N/A'
tuple_list.append(('media_lane_count', str(media_lane_count)))
if reset_apsel == False:
appl_advt_act = appl_advt.get(act_apsel_lane)
host_lane_count = appl_advt_act.get('host_lane_count', 'N/A') if appl_advt_act else 'N/A'
tuple_list.append(('host_lane_count', str(host_lane_count)))
media_lane_count = appl_advt_act.get('media_lane_count', 'N/A') if appl_advt_act else 'N/A'
tuple_list.append(('media_lane_count', str(media_lane_count)))
else:
tuple_list.append(('host_lane_count', 'N/A'))
tuple_list.append(('media_lane_count', 'N/A'))

asic_index = self.port_mapping.get_asic_id_for_logical_port(lport)
intf_tbl = self.xcvr_table_helper.get_intf_tbl(asic_index)
Expand Down Expand Up @@ -1468,6 +1476,7 @@ def task_worker(self):
self.log_notice("{} Forcing Tx laser OFF".format(lport))
# Force DataPath re-init
api.tx_disable_channel(media_lanes_mask, True)
self.post_port_active_apsel_to_db(lport, host_lanes_mask, reset_apsel=True)
self.update_port_transceiver_status_table_sw_cmis_state(lport, CMIS_STATE_READY)
continue
# Configure the target output power if ZR module
Expand Down
Loading