Skip to content

Commit

Permalink
Improve vslib support for debug counters
Browse files Browse the repository at this point in the history
  • Loading branch information
daall committed Oct 25, 2019
1 parent 12a65f3 commit 89b4dc0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
76 changes: 75 additions & 1 deletion vslib/src/sai_vs_debug_counter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,81 @@
#include "sai_vs.h"
#include "sai_vs_internal.h"
#include "sai_vs_state.h"
#include <unordered_set>

VS_GENERIC_QUAD(DEBUG_COUNTER,debug_counter);
static std::unordered_set<uint32_t> indices;

static uint32_t get_index()
{
for (uint32_t i = 0; i < 32; i++)
{
if (indices.find(i) == indices.end())
{
indices.insert(i);
return i;
}
}

return UINT32_MAX;
}

// VS_GENERIC_QUAD(DEBUG_COUNTER,debug_counter);
sai_status_t vs_create_debug_counter(
_Out_ sai_object_id_t *debug_counter_id,
_In_ sai_object_id_t switch_id,
_In_ uint32_t attr_count,
_In_ const sai_attribute_t *attr_list)
{
MUTEX();
SWSS_LOG_ENTER();

/* create debug counter */
CHECK_STATUS(meta_sai_create_oid(
(sai_object_type_t)SAI_OBJECT_TYPE_DEBUG_COUNTER,
debug_counter_id,
switch_id,
attr_count,
attr_list,
&vs_generic_create));

sai_attribute_t attr;
attr.id = SAI_DEBUG_COUNTER_ATTR_INDEX;
attr.value.u32 = get_index();
CHECK_STATUS(vs_generic_set(SAI_OBJECT_TYPE_DEBUG_COUNTER, *debug_counter_id, &attr));

return SAI_STATUS_SUCCESS;
}

sai_status_t vs_remove_debug_counter(
_In_ sai_object_id_t debug_counter_id)
{
MUTEX();
SWSS_LOG_ENTER();

sai_attribute_t attr;
attr.id = SAI_DEBUG_COUNTER_ATTR_INDEX;
CHECK_STATUS(vs_generic_get(SAI_OBJECT_TYPE_DEBUG_COUNTER, debug_counter_id, 1, &attr));

sai_status_t status = meta_sai_remove_oid(
(sai_object_type_t)SAI_OBJECT_TYPE_DEBUG_COUNTER,
debug_counter_id,
&vs_generic_remove);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to remove debug counter: %s", sai_serialize_object_id(debug_counter_id).c_str());
return status;
}

indices.erase(attr.value.u32);

return SAI_STATUS_SUCCESS;
}

VS_GET(DEBUG_COUNTER,debug_counter);
VS_SET(DEBUG_COUNTER,debug_counter);

// VS_GENERIC_QUAD(DEBUG_COUNTER,debug_counter);

const sai_debug_counter_api_t vs_debug_counter_api = {
VS_GENERIC_QUAD_API(debug_counter)
Expand Down
1 change: 1 addition & 0 deletions vslib/src/sai_vs_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ sai_status_t sai_api_query(
API_CASE(VIRTUAL_ROUTER,virtual_router);
API_CASE(VLAN,vlan);
API_CASE(WRED,wred);
API_CASE(DEBUG_COUNTER,debug_counter);

default:
SWSS_LOG_ERROR("Invalid API type %d", sai_api_id);
Expand Down
5 changes: 5 additions & 0 deletions vslib/src/sai_vs_switch_BCM56850.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,11 @@ sai_status_t refresh_read_only_BCM56850(
return refresh_vlan_member_list(meta, object_id, switch_id);
}

if (meta->objecttype == SAI_OBJECT_TYPE_DEBUG_COUNTER && meta->attrid == SAI_DEBUG_COUNTER_ATTR_INDEX)
{
return SAI_STATUS_SUCCESS;
}

if (meta_unittests_enabled())
{
SWSS_LOG_NOTICE("unittests enabled, SET could be performed on %s, not recalculating", meta->attridname);
Expand Down
5 changes: 5 additions & 0 deletions vslib/src/sai_vs_switch_MLNX2700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,11 @@ sai_status_t refresh_read_only_MLNX2700(
return refresh_vlan_member_list(meta, object_id, switch_id);
}

if (meta->objecttype == SAI_OBJECT_TYPE_DEBUG_COUNTER && meta->attrid == SAI_DEBUG_COUNTER_ATTR_INDEX)
{
return SAI_STATUS_SUCCESS;
}

if (meta_unittests_enabled())
{
SWSS_LOG_NOTICE("unittests enabled, SET could be performed on %s, not recalculating", meta->attridname);
Expand Down

0 comments on commit 89b4dc0

Please sign in to comment.