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..56f539086 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -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) @@ -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, @@ -1712,6 +1729,13 @@ 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) + { + SWSS_LOG_INFO("createCounterContext counter type %s", context_name.c_str()); + auto context = std::make_shared>(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 @@ -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", @@ -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; diff --git a/unittest/syncd/TestFlexCounter.cpp b/unittest/syncd/TestFlexCounter.cpp index e5d374e17..0a175e5f6 100644 --- a/unittest/syncd/TestFlexCounter.cpp +++ b/unittest/syncd/TestFlexCounter.cpp @@ -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)