Docker Container Over MLNX-OS Example

Version 2

    This post contains Python a command example for the ALL PORT COUNTER DUMP module. Python command syntax is very similar to the switch SDK APIs. You can learn more about each command and its parameters by reading the Switch API Reference Manual.

    The example below demonstrates the configuration of different port attributes.

     

    #!/usr/bin/env python

     

    import sys, errno

    import os

     

    from python_sdk_api.sx_api import *

    from test_infra_common import *

     

    ERR_FILE_LOCATION = '/tmp/python_err_log.txt'

     

    file_exist = os.path.isfile(ERR_FILE_LOCATION)

    sys.stderr = open(ERR_FILE_LOCATION, 'w')

    if not file_exist:

      os.chmod(ERR_FILE_LOCATION, 0o777);

      

    old_stdout = redirect_stdout()

    rc, handle = sx_api_open(None)

    sys.stdout = os.fdopen(old_stdout, 'w')

    if (rc != SX_STATUS_SUCCESS):

      print "Failed to open api handle.\nPlease check that SDK is running."

      sys.exit(errno.EACCES)

     

    device_info_cnt_p = new_uint32_t_p()

    uint32_t_p_assign(device_info_cnt_p, 0)

    rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9asx_api_port_device_list_get(handle, None, device_info_cnt_p)

    if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9asx_api_port_device_list_get failed, rc = %d" % (rc)

      exit()

    device_info_cnt = uint32_t_p_value(device_info_cnt_p)

    device_info_list_p = new_sx_device_info_t_arr(device_info_cnt)

    rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9asx_api_port_device_list_get(handle, device_info_list_p, device_info_cnt_p)

    if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9afile://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a8547e671b86adfa81b8914bc6d4a7c9asx_api_port_device_list_get failed, rc = %d" % (rc)

      exit()

    device_info_cnt = uint32_t_p_value(device_info_cnt_p)

     

    swid_cnt_p = new_uint32_t_p()

    uint32_t_p_assign(swid_cnt_p, 0);

    rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2sx_api_port_swid_list_get(handle, None, swid_cnt_p)

    if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2sx_api_port_swid_list_get failed, rc = %d" % (rc)

      exit()

    swid_cnt = uint32_t_p_value(swid_cnt_p)

    swid_list_p = new_sx_swid_t_arr(swid_cnt)

    rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2sx_api_port_swid_list_get(handle, swid_list_p, swid_cnt_p)

    if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ae9f581acd6ea7e53fa000614c679a3a2sx_api_port_swid_list_get failed, rc = %d" % (rc)

      exit()

    swid_cnt = uint32_t_p_value(swid_cnt_p)

     

    cnt_802_dot_3 = sx_port_cntr_ieee_802_dot_3_t()

    cntr_rfc_2863 = sx_port_cntr_rfc_2863_t()

    cntr_rfc_2819 = sx_port_cntr_rfc_2819_t()

    cntr_rfc_3635 = sx_port_cntr_rfc_3635_t()

    cntr_cli = sx_port_cntr_cli_t()

    cntr_perf = sx_port_cntr_perf_t()

    cntr_discard = sx_port_cntr_discard_t()

    cntr_prio = sx_port_cntr_prio_t()

    cntr_tc = sx_port_traffic_cntr_t()

    cntr_buff = sx_port_cntr_buff_t()

     

    for i in range(0, device_info_cnt):

      device_info = sx_device_info_t_arr_getitem(device_info_list_p, i)

      device_id = device_info.dev_id

      print "\nDevice %d" % (device_id)

      print "-----------------------"

      for j in range(0, swid_cnt):

      swid = sx_swid_t_arr_getitem(swid_list_p, j)

      print "\nSWID %d" % (swid)

      print "-----------------------"

      port_cnt_p = new_uint32_t_p()

      uint32_t_p_assign(port_cnt_p, 0)

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7sx_api_port_device_get(handle, device_id , swid, None, port_cnt_p)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7sx_api_port_device_get failed, rc = %d" % (rc)

      exit()

      port_cnt = uint32_t_p_value(port_cnt_p)

      port_attributes_list = new_sx_port_attributes_t_arr(port_cnt)

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7sx_api_port_device_get(handle, device_id , swid, port_attributes_list, port_cnt_p)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af2183e8bd9f2b4301c20dbc281152eb7sx_api_port_device_get failed, rc = %d" % (rc)

      exit()

      port_cnt = uint32_t_p_value(port_cnt_p)

      for k in range(0, port_cnt):

      port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list, k)

      log_port = port_attributes.log_port

      is_nve = check_nve(int(log_port))

      is_vport = check_vport(int(log_port))

      if is_nve or is_vport:

      continue

     

      print "\nPort 0x%x - IEEE 802.3 Counters Group" % (log_port)

      print "=================================================="

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ab1da148241d2e8b5a7c3061995926d5dsx_api_port_counter_ieee_802_dot_3_get(handle, SX_ACCESS_CMD_READ, log_port, cnt_802_dot_3)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ab1da148241d2e8b5a7c3061995926d5dsx_api_port_counter_ieee_802_dot_3_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cnt_802_dot_3)

     

      print "\nPort 0x%x - RFC 2863 Counters Group" % (log_port)

      print "=================================================="

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a3164c4dd6434ee771f6b2e38020bf82csx_api_port_counter_rfc_2863_get(handle, SX_ACCESS_CMD_READ, log_port, cntr_rfc_2863)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a3164c4dd6434ee771f6b2e38020bf82csx_api_port_counter_rfc_2863_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_rfc_2863)

     

      print "\nPort 0x%x - RFC 2819 Counters Group" % (log_port)

      print "=================================================="

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ac4d9e0a2e66d1fde42fce0c0ce24e3bbsx_api_port_counter_rfc_2819_get(handle, SX_ACCESS_CMD_READ, log_port, cntr_rfc_2819)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#ac4d9e0a2e66d1fde42fce0c0ce24e3bbsx_api_port_counter_rfc_2819_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_rfc_2819)

     

      print "\nPort 0x%x - RFC 3635 Counters Group" % (log_port)

      print "=================================================="

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af164c75be838e07f152274206ce2b346sx_api_port_counter_rfc_3635_get(handle, SX_ACCESS_CMD_READ, log_port, cntr_rfc_3635)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#af164c75be838e07f152274206ce2b346sx_api_port_counter_rfc_3635_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_rfc_3635)

     

      print "\nPort 0x%x - CLI Counters Group" % (log_port)

      print "=================================================="

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a20cb565fd4a0ebd4916f36ecf7125decsx_api_port_counter_cli_get(handle, SX_ACCESS_CMD_READ, log_port, cntr_cli)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a20cb565fd4a0ebd4916f36ecf7125decsx_api_port_counter_cli_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_cli)

     

      print "\nPort 0x%x - EXTENDED Counters Group" % (log_port)

      print "=================================================="

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#aa5328e02b80e20924b025b3142ca546esx_api_port_counter_perf_get(handle, SX_ACCESS_CMD_READ, log_port, SX_PORT_PRIO_ID_0, cntr_perf)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#aa5328e02b80e20924b025b3142ca546esx_api_port_counter_perf_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_perf)

     

      print "\nPort 0x%x - DISCARD Counters Group" % (log_port)

      print "=================================================="

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a5ea8fac313cd4a57dae8547c4fe676d7sx_api_port_counter_discard_get(handle, SX_ACCESS_CMD_READ, log_port, cntr_discard)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a5ea8fac313cd4a57dae8547c4fe676d7sx_api_port_counter_discard_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_discard)

     

      print "\nPort 0x%x - PER PRIO Counters Group" % (log_port)

      print "=================================================="

      for prio in range(SX_PORT_PRIO_ID_MIN, SX_PORT_PRIO_ID_MAX+1):

      print "\nPrio %d" % (prio)

      print "----------------------"

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a508d4c802af65d7ca579e82f74a97cf2sx_api_port_counter_prio_get(handle, SX_ACCESS_CMD_READ, log_port, prio, cntr_prio)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a508d4c802af65d7ca579e82f74a97cf2sx_api_port_counter_prio_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_prio)

     

      print "\nPort 0x%x - PER TC Counters Group" % (log_port)

      print "=================================================="

      for tc in range(SX_PORT_TC_ID_MIN, SX_PORT_TC_ID_MAX+1):

      print "\nTC %d" % (tc)

      print "----------------------"

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a48f6e4fc57d5892dba61185154c66446sx_api_port_counter_tc_get(handle, SX_ACCESS_CMD_READ, log_port, tc, cntr_tc)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#a48f6e4fc57d5892dba61185154c66446sx_api_port_counter_tc_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_tc)

     

      print "\nPort 0x%x - PER BUFF Counters Group" % (log_port)

      print "=================================================="

      for buf in range(0, RM_API_COS_BUFFERS_NUM):

      print "\nBuff %d" % (buf)

      print "----------------------"

      rc = file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#aa0e6a9a3d90145c303b61bca3541c0c1sx_api_port_counter_buff_get(handle, SX_ACCESS_CMD_READ, log_port, buf, cntr_buff)

      if rc != SX_STATUS_SUCCESS:

      print "file://l2/sw_system_release/sx_sdk_eth/last_api_ref_guide__master/sdk/html/sx__api__port_8h.html#aa0e6a9a3d90145c303b61bca3541c0c1sx_api_port_counter_buff_get failed, rc = %d" % (rc)

      exit()

      print_all_attr_from_a_struct(cntr_buff)