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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions syncd/FlexCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static const std::string COUNTER_TYPE_TUNNEL = "Tunnel Counter";
static const std::string COUNTER_TYPE_BUFFER_POOL = "Buffer Pool Counter";
static const std::string COUNTER_TYPE_ENI = "DASH ENI Counter";
static const std::string COUNTER_TYPE_METER_BUCKET = "DASH Meter Bucket Counter";
static const std::string COUNTER_TYPE_POLICER = "Policer Counter";
static const std::string ATTR_TYPE_QUEUE = "Queue Attribute";
static const std::string ATTR_TYPE_PG = "Priority Group Attribute";
static const std::string ATTR_TYPE_MACSEC_SA = "MACSEC SA Attribute";
Expand Down Expand Up @@ -164,6 +165,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 +279,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 +1730,10 @@ 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)
{
return std::make_shared<CounterContext<sai_policer_stat_t>>(context_name, SAI_OBJECT_TYPE_POLICER, m_vendorSai.get(), m_statsMode);
}

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 +2012,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 +2153,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 @@ -745,6 +745,18 @@ TEST(FlexCounter, bulkCounter)
{"10", "20"},
counterVerifyFunc,
false);

testAddRemoveCounter(
2,
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);
// buffer pool stats does not support bulk
EXPECT_EQ(false, clearCalled);
}
Expand Down