Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FC] Support Policer Counter #1484

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions meta/SaiSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,14 @@ std::string sai_serialize_counter_stat(
return sai_serialize_enum(counter, &sai_metadata_enum_sai_counter_stat_t);
}

std::string sai_serialize_policer_stat(
_In_ const sai_policer_stat_t counter)
{
SWSS_LOG_ENTER();

return sai_serialize_enum(counter, &sai_metadata_enum_sai_policer_stat_t);
}

std::string sai_serialize_queue_attr(
_In_ const sai_queue_attr_t attr)
{
Expand Down
3 changes: 3 additions & 0 deletions meta/sai_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ std::string sai_serialize_tunnel_stat(
std::string sai_serialize_counter_stat(
_In_ const sai_counter_stat_t counter);

std::string sai_serialize_policer_stat(
_In_ const sai_policer_stat_t counter);

std::string sai_serialize_queue_attr(
_In_ const sai_queue_attr_t attr);

Expand Down
39 changes: 39 additions & 0 deletions syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ std::string serializeStat(
return sai_serialize_port_stat(stat);
}

template <>
std::string serializeStat(
_In_ const sai_policer_stat_t stat)
{
SWSS_LOG_ENTER();
return sai_serialize_policer_stat(stat);
}

template <>
std::string serializeStat(
_In_ const sai_queue_stat_t stat)
Expand Down Expand Up @@ -270,6 +278,15 @@ void deserializeStat(
sai_deserialize_port_stat(name, stat);
}

template <>
void deserializeStat(
_In_ const char* name,
_Out_ sai_policer_stat_t *stat)
{
SWSS_LOG_ENTER();
sai_deserialize_policer_stat(name, stat);
}

template <>
void deserializeStat(
_In_ const char* name,
Expand Down Expand Up @@ -1712,6 +1729,13 @@ std::shared_ptr<BaseCounterContext> FlexCounter::createCounterContext(
{
return std::make_shared<AttrContext<sai_acl_counter_attr_t>>(context_name, SAI_OBJECT_TYPE_ACL_COUNTER, m_vendorSai.get(), m_statsMode);
}
else if (context_name == COUNTER_TYPE_POLICER)
{
SWSS_LOG_INFO("createCounterContext counter type %s", context_name.c_str());
auto context = std::make_shared<CounterContext<sai_policer_stat_t>>(context_name, SAI_OBJECT_TYPE_POLICER, m_vendorSai.get(), m_statsMode);
context->always_check_supported_counters = true;
return context;
}

SWSS_LOG_THROW("Invalid counter type %s", context_name.c_str());
// GCC 8.3 requires a return value here
Expand Down Expand Up @@ -1990,6 +2014,13 @@ void FlexCounter::removeCounter(
removeDataFromCountersDB(vid, ":TRAP");
}
}
else if (objectType == SAI_OBJECT_TYPE_POLICER)
{
if (hasCounterContext(COUNTER_TYPE_POLICER))
{
getCounterContext(COUNTER_TYPE_POLICER)->removeObject(vid);
}
}
else
{
SWSS_LOG_ERROR("Object type for removal not supported, %s",
Expand Down Expand Up @@ -2124,6 +2155,14 @@ void FlexCounter::addCounter(
idStrings,
"");
}
else if (objectType == SAI_OBJECT_TYPE_POLICER && field == POLICER_COUNTER_ID_LIST)
{
getCounterContext(COUNTER_TYPE_POLICER)->addObject(
vid,
rid,
idStrings,
"");
}
else if (objectType == SAI_OBJECT_TYPE_BUFFER_POOL && field == BUFFER_POOL_COUNTER_ID_LIST)
{
counterIds = idStrings;
Expand Down
12 changes: 12 additions & 0 deletions unittest/syncd/TestFlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ TEST(FlexCounter, queryCounterCapability)
{},
counterVerifyFunc,
false);

testAddRemoveCounter(
{sai_object_id_t(0x12000000000000)},
SAI_OBJECT_TYPE_POLICER,
POLICER_COUNTER_ID_LIST,
{"SAI_POLICER_STAT_PACKETS", "SAI_POLICER_STAT_ATTR_BYTES",
"SAI_POLICER_STAT_GREEN_PACKETS", "SAI_POLICER_STAT_GREEN_BYTES",
"SAI_POLICER_STAT_YELLOW_PACKETS", "SAI_POLICER_STAT_YELLOW_BYTES",
"SAI_POLICER_STAT_RED_PACKETS", "SAI_POLICER_STAT_RED_BYTES"},
{"100", "200", "300", "400", "500", "600", "700", "800"},
counterVerifyFunc,
false);
}

TEST(FlexCounter, noSupportedCounters)
Expand Down
Loading