Skip to content

Commit

Permalink
[debugcounterorch] check if counter type is supported before querying… (
Browse files Browse the repository at this point in the history
sonic-net#1789)

* [debugcounterorch] check if counter type is supported before querying object availability count
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored Jul 20, 2021
1 parent 9f0bb8d commit ed6786d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
57 changes: 57 additions & 0 deletions orchagent/debug_counter/drop_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,63 @@ unordered_set<string> DropCounter::getSupportedDropReasons(sai_debug_counter_att
return supported_drop_reasons;
}

// Returns a set of supported counter types.
unordered_set<string> DropCounter::getSupportedCounterTypes()
{
sai_status_t status = SAI_STATUS_FAILURE;

const auto& countersTypeLookup = getDebugCounterTypeLookup();
unordered_set<string> supportedCounterTypes;

sai_s32_list_t enumValuesCapabilities;
vector<int32_t> saiCounterTypes;

const auto* meta = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_DEBUG_COUNTER,
SAI_DEBUG_COUNTER_ATTR_TYPE);
if (!meta)
{
SWSS_LOG_ERROR("SAI BUG: metadata null pointer returned by "
"sai_metadata_get_attr_metadata for SAI_DEBUG_COUNTER_ATTR_TYPE");
return {};
}

if (!meta->isenum || !meta->enummetadata)
{
SWSS_LOG_ERROR("SAI BUG: SAI_DEBUG_COUNTER_ATTR_TYPE value type is not an enum");
return {};
}

saiCounterTypes.assign(meta->enummetadata->valuescount, 0);

enumValuesCapabilities.count = static_cast<uint32_t>(saiCounterTypes.size());
enumValuesCapabilities.list = saiCounterTypes.data();

status = sai_query_attribute_enum_values_capability(gSwitchId,
SAI_OBJECT_TYPE_DEBUG_COUNTER,
SAI_DEBUG_COUNTER_ATTR_TYPE,
&enumValuesCapabilities);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_NOTICE("This device does not support querying drop counters");
return {};
}

for (uint32_t i = 0; i < enumValuesCapabilities.count; i++)
{
auto enumValue = static_cast<sai_debug_counter_type_t>(enumValuesCapabilities.list[i]);
for (const auto& it: countersTypeLookup)
{
if (it.second == enumValue)
{
supportedCounterTypes.emplace(it.first);
break;
}
}
}

return supportedCounterTypes;
}

// serializeSupportedDropReasons takes a list of drop reasons and returns that
// list as a string.
//
Expand Down
1 change: 1 addition & 0 deletions orchagent/debug_counter/drop_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DropCounter : public DebugCounter

static std::unordered_set<std::string> getSupportedDropReasons(sai_debug_counter_attr_t drop_reason_type);
static std::string serializeSupportedDropReasons(std::unordered_set<std::string> drop_reasons);
static std::unordered_set<std::string> getSupportedCounterTypes();
static uint64_t getSupportedDebugCounterAmounts(sai_debug_counter_type_t counter_type);

private:
Expand Down
9 changes: 7 additions & 2 deletions orchagent/debugcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,20 @@ void DebugCounterOrch::publishDropCounterCapabilities()
{
supported_ingress_drop_reasons = DropCounter::getSupportedDropReasons(SAI_DEBUG_COUNTER_ATTR_IN_DROP_REASON_LIST);
supported_egress_drop_reasons = DropCounter::getSupportedDropReasons(SAI_DEBUG_COUNTER_ATTR_OUT_DROP_REASON_LIST);
supported_counter_types = DropCounter::getSupportedCounterTypes();

string ingress_drop_reason_str = DropCounter::serializeSupportedDropReasons(supported_ingress_drop_reasons);
string egress_drop_reason_str = DropCounter::serializeSupportedDropReasons(supported_egress_drop_reasons);

for (auto const &counter_type : DebugCounter::getDebugCounterTypeLookup())
{
string drop_reasons;

if (!supported_counter_types.count(counter_type.first))
{
continue;
}

if (counter_type.first == PORT_INGRESS_DROPS || counter_type.first == SWITCH_INGRESS_DROPS)
{
drop_reasons = ingress_drop_reason_str;
Expand All @@ -213,8 +220,6 @@ void DebugCounterOrch::publishDropCounterCapabilities()
continue;
}

supported_counter_types.emplace(counter_type.first);

vector<FieldValueTuple> fieldValues;
fieldValues.push_back(FieldValueTuple("count", num_counters));
fieldValues.push_back(FieldValueTuple("reasons", drop_reasons));
Expand Down

0 comments on commit ed6786d

Please sign in to comment.