diff --git a/vslib/src/sai_vs_debug_counter.cpp b/vslib/src/sai_vs_debug_counter.cpp index 20c0c22c8..a5d9a9ded 100644 --- a/vslib/src/sai_vs_debug_counter.cpp +++ b/vslib/src/sai_vs_debug_counter.cpp @@ -1,7 +1,81 @@ #include "sai_vs.h" #include "sai_vs_internal.h" +#include "sai_vs_state.h" +#include -VS_GENERIC_QUAD(DEBUG_COUNTER,debug_counter); +static std::unordered_set 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) diff --git a/vslib/src/sai_vs_interfacequery.cpp b/vslib/src/sai_vs_interfacequery.cpp index 60605055e..3f875e1da 100644 --- a/vslib/src/sai_vs_interfacequery.cpp +++ b/vslib/src/sai_vs_interfacequery.cpp @@ -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); diff --git a/vslib/src/sai_vs_switch_BCM56850.cpp b/vslib/src/sai_vs_switch_BCM56850.cpp index 922a99360..ba9106dcf 100644 --- a/vslib/src/sai_vs_switch_BCM56850.cpp +++ b/vslib/src/sai_vs_switch_BCM56850.cpp @@ -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); diff --git a/vslib/src/sai_vs_switch_MLNX2700.cpp b/vslib/src/sai_vs_switch_MLNX2700.cpp index 8a710097f..58d8aeb98 100644 --- a/vslib/src/sai_vs_switch_MLNX2700.cpp +++ b/vslib/src/sai_vs_switch_MLNX2700.cpp @@ -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);