Skip to content

Commit 6b263b8

Browse files
authored
[FC] Support Policer Counter (#1533)
Added the implantation for policer counter - Support in POLICER group and sai_serialize functions Unit Tests: Included unit tests to add and remove policer counter.
1 parent e53489e commit 6b263b8

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

meta/SaiSerialize.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,14 @@ std::string sai_serialize_counter_stat(
11061106
return sai_serialize_enum(counter, &sai_metadata_enum_sai_counter_stat_t);
11071107
}
11081108

1109+
std::string sai_serialize_policer_stat(
1110+
_In_ const sai_policer_stat_t counter)
1111+
{
1112+
SWSS_LOG_ENTER();
1113+
1114+
return sai_serialize_enum(counter, &sai_metadata_enum_sai_policer_stat_t);
1115+
}
1116+
11091117
std::string sai_serialize_queue_attr(
11101118
_In_ const sai_queue_attr_t attr)
11111119
{

meta/sai_serialize.h

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ std::string sai_serialize_tunnel_stat(
140140
std::string sai_serialize_counter_stat(
141141
_In_ const sai_counter_stat_t counter);
142142

143+
std::string sai_serialize_policer_stat(
144+
_In_ const sai_policer_stat_t counter);
145+
143146
std::string sai_serialize_queue_attr(
144147
_In_ const sai_queue_attr_t attr);
145148

syncd/FlexCounter.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static const std::string COUNTER_TYPE_TUNNEL = "Tunnel Counter";
2828
static const std::string COUNTER_TYPE_BUFFER_POOL = "Buffer Pool Counter";
2929
static const std::string COUNTER_TYPE_ENI = "DASH ENI Counter";
3030
static const std::string COUNTER_TYPE_METER_BUCKET = "DASH Meter Bucket Counter";
31+
static const std::string COUNTER_TYPE_POLICER = "Policer Counter";
3132
static const std::string ATTR_TYPE_QUEUE = "Queue Attribute";
3233
static const std::string ATTR_TYPE_PG = "Priority Group Attribute";
3334
static const std::string ATTR_TYPE_MACSEC_SA = "MACSEC SA Attribute";
@@ -164,6 +165,14 @@ std::string serializeStat(
164165
return sai_serialize_port_stat(stat);
165166
}
166167

168+
template <>
169+
std::string serializeStat(
170+
_In_ const sai_policer_stat_t stat)
171+
{
172+
SWSS_LOG_ENTER();
173+
return sai_serialize_policer_stat(stat);
174+
}
175+
167176
template <>
168177
std::string serializeStat(
169178
_In_ const sai_queue_stat_t stat)
@@ -270,6 +279,15 @@ void deserializeStat(
270279
sai_deserialize_port_stat(name, stat);
271280
}
272281

282+
template <>
283+
void deserializeStat(
284+
_In_ const char* name,
285+
_Out_ sai_policer_stat_t *stat)
286+
{
287+
SWSS_LOG_ENTER();
288+
sai_deserialize_policer_stat(name, stat);
289+
}
290+
273291
template <>
274292
void deserializeStat(
275293
_In_ const char* name,
@@ -1714,6 +1732,10 @@ std::shared_ptr<BaseCounterContext> FlexCounter::createCounterContext(
17141732
{
17151733
return std::make_shared<AttrContext<sai_acl_counter_attr_t>>(context_name, SAI_OBJECT_TYPE_ACL_COUNTER, m_vendorSai.get(), m_statsMode);
17161734
}
1735+
else if (context_name == COUNTER_TYPE_POLICER)
1736+
{
1737+
return std::make_shared<CounterContext<sai_policer_stat_t>>(context_name, SAI_OBJECT_TYPE_POLICER, m_vendorSai.get(), m_statsMode);
1738+
}
17171739

17181740
SWSS_LOG_THROW("Invalid counter type %s", context_name.c_str());
17191741
// GCC 8.3 requires a return value here
@@ -1992,6 +2014,13 @@ void FlexCounter::removeCounter(
19922014
removeDataFromCountersDB(vid, ":TRAP");
19932015
}
19942016
}
2017+
else if (objectType == SAI_OBJECT_TYPE_POLICER)
2018+
{
2019+
if (hasCounterContext(COUNTER_TYPE_POLICER))
2020+
{
2021+
getCounterContext(COUNTER_TYPE_POLICER)->removeObject(vid);
2022+
}
2023+
}
19952024
else
19962025
{
19972026
SWSS_LOG_ERROR("Object type for removal not supported, %s",
@@ -2126,6 +2155,14 @@ void FlexCounter::addCounter(
21262155
idStrings,
21272156
"");
21282157
}
2158+
else if (objectType == SAI_OBJECT_TYPE_POLICER && field == POLICER_COUNTER_ID_LIST)
2159+
{
2160+
getCounterContext(COUNTER_TYPE_POLICER)->addObject(
2161+
vid,
2162+
rid,
2163+
idStrings,
2164+
"");
2165+
}
21292166
else if (objectType == SAI_OBJECT_TYPE_BUFFER_POOL && field == BUFFER_POOL_COUNTER_ID_LIST)
21302167
{
21312168
counterIds = idStrings;

unittest/syncd/TestFlexCounter.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,18 @@ TEST(FlexCounter, bulkCounter)
745745
{"10", "20"},
746746
counterVerifyFunc,
747747
false);
748+
749+
testAddRemoveCounter(
750+
2,
751+
SAI_OBJECT_TYPE_POLICER,
752+
POLICER_COUNTER_ID_LIST,
753+
{"SAI_POLICER_STAT_PACKETS", "SAI_POLICER_STAT_ATTR_BYTES",
754+
"SAI_POLICER_STAT_GREEN_PACKETS", "SAI_POLICER_STAT_GREEN_BYTES",
755+
"SAI_POLICER_STAT_YELLOW_PACKETS", "SAI_POLICER_STAT_YELLOW_BYTES",
756+
"SAI_POLICER_STAT_RED_PACKETS", "SAI_POLICER_STAT_RED_BYTES"},
757+
{"100", "200", "300", "400", "500", "600", "700", "800"},
758+
counterVerifyFunc,
759+
false);
748760
// buffer pool stats does not support bulk
749761
EXPECT_EQ(false, clearCalled);
750762
}

0 commit comments

Comments
 (0)