Skip to content

Commit

Permalink
Clean-up virtual switch implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
daall committed Oct 30, 2019
1 parent 2fb3152 commit 961dbb4
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions vslib/src/sai_vs_debug_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include "sai_vs_state.h"
#include <unordered_set>

const int maxDebugCounters = 32;

static std::unordered_set<uint32_t> indices;

static uint32_t get_index()
{
SWSS_LOG_ENTER();

for (uint32_t i = 0; i < 32; i++)
for (uint32_t i = 0; i < maxDebugCounters; i++)
{
if (indices.find(i) == indices.end())
{
Expand All @@ -21,35 +23,42 @@ static uint32_t get_index()
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)
_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 */
auto index = get_index();

if (index > maxDebugCounters)
{
SWSS_LOG_ERROR("Cannot create any more debug counters");
return SAI_STATUS_FAILURE;
}

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));
static_cast<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();
attr.value.u32 = 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)
_In_ sai_object_id_t debug_counter_id)
{
MUTEX();
SWSS_LOG_ENTER();
Expand All @@ -58,16 +67,10 @@ sai_status_t vs_remove_debug_counter(
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(
CHECK_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;
}
&vs_generic_remove));

indices.erase(attr.value.u32);

Expand All @@ -77,8 +80,6 @@ sai_status_t vs_remove_debug_counter(
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)
};

0 comments on commit 961dbb4

Please sign in to comment.