diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 0916cac02..d27438205 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -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) { diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index 0ef79e9cb..5e9c95e7e 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -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); diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index f907f4f07..426391a6b 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -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"; @@ -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) @@ -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, @@ -1712,6 +1730,10 @@ std::shared_ptr FlexCounter::createCounterContext( { return std::make_shared>(context_name, SAI_OBJECT_TYPE_ACL_COUNTER, m_vendorSai.get(), m_statsMode); } + else if (context_name == COUNTER_TYPE_POLICER) + { + return std::make_shared>(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 @@ -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", @@ -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; diff --git a/unittest/syncd/TestFlexCounter.cpp b/unittest/syncd/TestFlexCounter.cpp index e5d374e17..cdcc1d20e 100644 --- a/unittest/syncd/TestFlexCounter.cpp +++ b/unittest/syncd/TestFlexCounter.cpp @@ -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); }