From 533b9518089c60bead7677c3aa4b62dfbd7af4f2 Mon Sep 17 00:00:00 2001 From: shiraez Date: Tue, 16 Jul 2024 19:44:06 +0300 Subject: [PATCH 1/5] policer counter support syncd --- meta/SaiSerialize.cpp | 8 ++++++++ meta/sai_serialize.h | 3 +++ syncd/FlexCounter.cpp | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+) 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..8143cabcf 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -1712,6 +1712,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 +1997,14 @@ void FlexCounter::removeCounter( removeDataFromCountersDB(vid, ":TRAP"); } } + else if (objectType == SAI_OBJECT_TYPE_POLICER) + { + if (hasCounterContext(COUNTER_TYPE_POLICER)) + { + getCounterContext(COUNTER_TYPE_POLICER)->removeObject(vid); + // removeDataFromCountersDB(vid, ":POLICER"); + } + } else { SWSS_LOG_ERROR("Object type for removal not supported, %s", @@ -2124,6 +2139,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; From df39c5729ee1778ffc053230f751a6e3d96fac17 Mon Sep 17 00:00:00 2001 From: shiraez Date: Tue, 30 Jul 2024 13:06:14 +0300 Subject: [PATCH 2/5] deserializeStat and serializeStat policer --- syncd/FlexCounter.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index 8143cabcf..f36b2f392 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, From 3b4c9175390c9a3ee98a58f6a141e2410a719782 Mon Sep 17 00:00:00 2001 From: shiraez Date: Tue, 10 Dec 2024 17:49:23 +0200 Subject: [PATCH 3/5] flex counter tests --- unittest/syncd/TestFlexCounter.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) From bd8b431c922b6628a8c0e419e32ace4c514352ff Mon Sep 17 00:00:00 2001 From: shiraez Date: Thu, 12 Dec 2024 13:02:43 +0200 Subject: [PATCH 4/5] clean code --- syncd/FlexCounter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index f36b2f392..56f539086 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -2019,7 +2019,6 @@ void FlexCounter::removeCounter( if (hasCounterContext(COUNTER_TYPE_POLICER)) { getCounterContext(COUNTER_TYPE_POLICER)->removeObject(vid); - // removeDataFromCountersDB(vid, ":POLICER"); } } else From 757c74768e62686438787ebb85f9cedf0ac6a935 Mon Sep 17 00:00:00 2001 From: shiraez Date: Wed, 18 Dec 2024 18:21:18 +0200 Subject: [PATCH 5/5] Fix tests --- syncd/FlexCounter.cpp | 6 ++---- unittest/syncd/TestFlexCounter.cpp | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index 56f539086..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"; @@ -1731,10 +1732,7 @@ std::shared_ptr FlexCounter::createCounterContext( } 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; + 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()); diff --git a/unittest/syncd/TestFlexCounter.cpp b/unittest/syncd/TestFlexCounter.cpp index 0a175e5f6..cdcc1d20e 100644 --- a/unittest/syncd/TestFlexCounter.cpp +++ b/unittest/syncd/TestFlexCounter.cpp @@ -430,18 +430,6 @@ 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) @@ -757,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); }