[202012] [Mellanox] Fix issue: cannot lable port for logical port is logical port number larger than 64 (#13709)

- Why I did it
sfp_event.py gets a PMPE message when a cable event is available. In PMPE message, there is no label port available. Current sfp_event.py is using sx_api_port_device_get to get 64 logical ports attributes, and find the label port from those 64 attributes. However, if there are more than 64 ports, sfp_event.py might not be able to find the label port and drop the PMPE message.

- How I did it
Don't use hardcoded 64, get logical port number instead.

- How to verify it
Manual test
This commit is contained in:
Junchao-Mellanox 2023-02-23 14:27:21 +08:00 committed by GitHub
parent 73c7ced753
commit 0f47c5be59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -273,11 +273,9 @@ class sfp_event:
pkt = new_uint8_t_arr(pkt_size)
recv_info_p = new_sx_receive_info_t_p()
pmpe_t = sx_event_pmpe_t()
port_attributes_list = new_sx_port_attributes_t_arr(64)
port_cnt_p = new_uint32_t_p()
uint32_t_p_assign(port_cnt_p,64)
uint32_t_p_assign(port_cnt_p, 0)
label_port_list = []
label_port = None
module_state = 0
rc = sx_lib_host_ifc_recv(fd_p, pkt, pkt_size_p, recv_info_p)
@ -296,29 +294,44 @@ class sfp_event:
if module_state == SDK_SFP_STATE_ERR:
logger.log_error("Receive PMPE error event on module {}: status {} error type {}".format(module_id, module_state, error_type))
elif module_state == SDK_SFP_STATE_DIS:
logger.log_info("Receive PMPE disable event on module {}: status {}".format(module_id, module_state))
logger.log_notice("Receive PMPE disable event on module {}: status {}".format(module_id, module_state))
elif module_state == SDK_SFP_STATE_IN or module_state == SDK_SFP_STATE_OUT:
logger.log_info("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
logger.log_notice("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
else:
logger.log_error("Receive PMPE unknown event on module {}: status {}".format(module_id, module_state))
for i in range(port_list_size):
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
rc = sx_api_port_device_get(self.handle, 1 , 0, port_attributes_list, port_cnt_p)
# Call sx_api_port_device_get with port_cnt_p=0, SDK will return the logical port number
rc = sx_api_port_device_get(self.handle, 1, 0, None, port_cnt_p)
if rc != SX_STATUS_SUCCESS:
logger.log_error("Failed to get logical port number")
status = False
else:
port_cnt = uint32_t_p_value(port_cnt_p)
port_attributes_list = new_sx_port_attributes_t_arr(port_cnt)
rc = sx_api_port_device_get(self.handle, 1, 0, port_attributes_list, port_cnt_p)
if rc != SX_STATUS_SUCCESS:
logger.log_error("Failed to get logical port attributes")
status = False
else:
for i in range(port_list_size):
label_port = None
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
for j in range(port_cnt):
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,j)
if port_attributes.log_port == logical_port:
label_port = port_attributes.port_mapping.module_port
break
for i in range(port_cnt):
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
if port_attributes.log_port == logical_port:
label_port = port_attributes.port_mapping.module_port
break
if label_port is not None:
label_port_list.append(label_port)
if label_port is not None:
label_port_list.append(label_port)
delete_sx_port_attributes_t_arr(port_attributes_list)
delete_uint32_t_p(pkt_size_p)
delete_uint8_t_arr(pkt)
delete_sx_receive_info_t_p(recv_info_p)
delete_sx_port_attributes_t_arr(port_attributes_list)
delete_uint32_t_p(port_cnt_p)
if not label_port_list:
logger.log_error('Dropping PMPE event due to label port not found')
return status, label_port_list, module_state, error_type