From 9b9d3306080e25568dd89261de87beac01738a0a Mon Sep 17 00:00:00 2001 From: Vivek Date: Mon, 16 Sep 2024 17:00:21 -0500 Subject: [PATCH] Add support for DASH ENI Counters (#1418) * Add support for DASH ENI Counters * Fix whitespace error --- meta/SaiSerialize.cpp | 8 ++ meta/sai_serialize.h | 3 + syncd/FlexCounter.cpp | 39 ++++++++++ unittest/syncd/TestFlexCounter.cpp | 118 +++++++++++++++++++++-------- 4 files changed, 138 insertions(+), 30 deletions(-) diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 53960a001..dd268f26a 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -1041,6 +1041,14 @@ std::string sai_serialize_buffer_pool_stat( return sai_serialize_enum(counter, &sai_metadata_enum_sai_buffer_pool_stat_t); } +std::string sai_serialize_eni_stat( + _In_ const sai_eni_stat_t counter) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(counter, &sai_metadata_enum_sai_eni_stat_t); +} + std::string sai_serialize_tunnel_stat( _In_ const sai_tunnel_stat_t counter) { diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index 5e149c409..d74d753e7 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -122,6 +122,9 @@ std::string sai_serialize_ingress_priority_group_attr( std::string sai_serialize_buffer_pool_stat( _In_ const sai_buffer_pool_stat_t counter); +std::string sai_serialize_eni_stat( + _In_ const sai_eni_stat_t counter); + std::string sai_serialize_tunnel_stat( _In_ const sai_tunnel_stat_t counter); diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index 4352efded..54443ed87 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -26,6 +26,7 @@ static const std::string COUNTER_TYPE_MACSEC_SA = "MACSEC SA Counter"; static const std::string COUNTER_TYPE_FLOW = "Flow Counter"; 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 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"; @@ -219,6 +220,14 @@ std::string serializeStat( return sai_serialize_buffer_pool_stat(stat); } +template <> +std::string serializeStat( + _In_ const sai_eni_stat_t stat) +{ + SWSS_LOG_ENTER(); + return sai_serialize_eni_stat(stat); +} + template void deserializeStat( _In_ const char* name, @@ -318,6 +327,15 @@ void deserializeStat( sai_deserialize_buffer_pool_stat(name, stat); } +template <> +void deserializeStat( + _In_ const char* name, + _Out_ sai_eni_stat_t *stat) +{ + SWSS_LOG_ENTER(); + sai_deserialize_eni_stat(name, stat); +} + template void deserializeAttr( _In_ const std::string& name, @@ -1297,6 +1315,12 @@ std::shared_ptr FlexCounter::createCounterContext( context->always_check_supported_counters = true; return context; } + else if (context_name == COUNTER_TYPE_ENI) + { + auto context = std::make_shared>(context_name, (sai_object_type_t)SAI_OBJECT_TYPE_ENI, m_vendorSai.get(), m_statsMode); + context->always_check_supported_counters = true; + return context; + } else if (context_name == ATTR_TYPE_QUEUE) { return std::make_shared>(context_name, SAI_OBJECT_TYPE_QUEUE, m_vendorSai.get(), m_statsMode); @@ -1572,6 +1596,13 @@ void FlexCounter::removeCounter( getCounterContext(COUNTER_TYPE_TUNNEL)->removeObject(vid); } } + else if (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_ENI) + { + if (hasCounterContext(COUNTER_TYPE_ENI)) + { + getCounterContext(COUNTER_TYPE_ENI)->removeObject(vid); + } + } else if (objectType == SAI_OBJECT_TYPE_COUNTER) { if (hasCounterContext(COUNTER_TYPE_FLOW)) @@ -1730,6 +1761,14 @@ void FlexCounter::addCounter( idStrings, ""); } + else if (objectType == (sai_object_type_t)SAI_OBJECT_TYPE_ENI && field == ENI_COUNTER_ID_LIST) + { + getCounterContext(COUNTER_TYPE_ENI)->addObject( + vid, + rid, + idStrings, + ""); + } else { SWSS_LOG_ERROR("Object type and field combination is not supported, object type %s, field %s", diff --git a/unittest/syncd/TestFlexCounter.cpp b/unittest/syncd/TestFlexCounter.cpp index 482fc6c1c..1e81e3458 100644 --- a/unittest/syncd/TestFlexCounter.cpp +++ b/unittest/syncd/TestFlexCounter.cpp @@ -1,10 +1,13 @@ #include "FlexCounter.h" #include "MockableSaiInterface.h" #include "MockHelper.h" - +#include "VirtualObjectIdManager.h" +#include "NumberOidIndexGenerator.h" +#include #include - +using namespace saimeta; +using namespace sairedis; using namespace syncd; using namespace std; @@ -39,8 +42,42 @@ std::string toOid(T value) std::shared_ptr sai(new MockableSaiInterface()); typedef std::function& counterIdNames, const std::vector& expectedValues)> VerifyStatsFunc; +std::vector generateOids( + unsigned int numOid, + sai_object_type_t object_type) +{ + SWSS_LOG_ENTER(); + + std::vector object_ids; + if (!numOid) + return object_ids; + + auto scc = std::make_shared(); + for (unsigned int i = 0; i < numOid; i++){ + auto hw_info = "asic" + std::to_string(i); + scc->insert(std::make_shared(i, hw_info)); + } + + auto vidManager = VirtualObjectIdManager(0, scc, std::make_shared()); + if (object_type == SAI_OBJECT_TYPE_SWITCH) + { + for (unsigned int i = 0; i < numOid; i++){ + auto hw_info = "asic" + std::to_string(i); + object_ids.push_back(vidManager.allocateNewSwitchObjectId(hw_info)); + } + } + else + { + auto sid = vidManager.allocateNewSwitchObjectId("asic0"); + for (unsigned int i = 0; i < numOid; i++){ + object_ids.push_back(vidManager.allocateNewObjectId(object_type, sid)); + } + } + return object_ids; +} + void testAddRemoveCounter( - const std::vector& object_ids, + unsigned int numOid, sai_object_type_t object_type, const std::string& counterIdFieldName, const std::vector& counterIdNames, @@ -55,6 +92,9 @@ void testAddRemoveCounter( test_syncd::mockVidManagerObjectTypeQuery(object_type); + std::vector object_ids = generateOids(numOid, object_type); + EXPECT_EQ(object_ids.size(), numOid); + std::vector values; values.emplace_back(POLL_INTERVAL_FIELD, "1000"); values.emplace_back(FLEX_COUNTER_STATUS_FIELD, "enable"); @@ -136,7 +176,7 @@ TEST(FlexCounter, addRemoveCounter) }; testAddRemoveCounter( - {sai_object_id_t(0x54000000000000)}, + 1, SAI_OBJECT_TYPE_COUNTER, FLOW_COUNTER_ID_LIST, {"SAI_COUNTER_STAT_PACKETS", "SAI_COUNTER_STAT_BYTES"}, @@ -145,7 +185,7 @@ TEST(FlexCounter, addRemoveCounter) true); testAddRemoveCounter( - {sai_object_id_t(0x5a000000000000)}, + 1, SAI_OBJECT_TYPE_MACSEC_FLOW, MACSEC_FLOW_COUNTER_ID_LIST, {"SAI_MACSEC_FLOW_STAT_CONTROL_PKTS", "SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED"}, @@ -154,7 +194,7 @@ TEST(FlexCounter, addRemoveCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x5c000000000000)}, + 1, SAI_OBJECT_TYPE_MACSEC_SA, MACSEC_SA_COUNTER_ID_LIST, {"SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED", "SAI_MACSEC_SA_STAT_OCTETS_PROTECTED"}, @@ -163,7 +203,7 @@ TEST(FlexCounter, addRemoveCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x1000000000000)}, + 1, SAI_OBJECT_TYPE_PORT, PORT_COUNTER_ID_LIST, {"SAI_PORT_STAT_IF_IN_OCTETS", "SAI_PORT_STAT_IF_IN_UCAST_PKTS"}, @@ -172,7 +212,7 @@ TEST(FlexCounter, addRemoveCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x1000000000000)}, + 1, SAI_OBJECT_TYPE_PORT, PORT_DEBUG_COUNTER_ID_LIST, {"SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS", "SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"}, @@ -187,7 +227,7 @@ TEST(FlexCounter, addRemoveCounter) }; testAddRemoveCounter( - {sai_object_id_t(0x15000000000000)}, + 1, SAI_OBJECT_TYPE_QUEUE, QUEUE_COUNTER_ID_LIST, {"SAI_QUEUE_STAT_PACKETS", "SAI_QUEUE_STAT_BYTES"}, @@ -198,7 +238,7 @@ TEST(FlexCounter, addRemoveCounter) EXPECT_EQ(true, clearCalled); testAddRemoveCounter( - {sai_object_id_t(0x1a000000000000)}, + 1, SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP, PG_COUNTER_ID_LIST, {"SAI_INGRESS_PRIORITY_GROUP_STAT_PACKETS", "SAI_INGRESS_PRIORITY_GROUP_STAT_BYTES"}, @@ -207,7 +247,7 @@ TEST(FlexCounter, addRemoveCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x6000000000000)}, + 1, SAI_OBJECT_TYPE_ROUTER_INTERFACE, RIF_COUNTER_ID_LIST, {"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS", "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS"}, @@ -216,7 +256,7 @@ TEST(FlexCounter, addRemoveCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x21000000000000)}, + 1, SAI_OBJECT_TYPE_SWITCH, SWITCH_DEBUG_COUNTER_ID_LIST, {"SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS", "SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"}, @@ -225,7 +265,7 @@ TEST(FlexCounter, addRemoveCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x2a000000000000)}, + 1, SAI_OBJECT_TYPE_TUNNEL, TUNNEL_COUNTER_ID_LIST, {"SAI_TUNNEL_STAT_IN_OCTETS", "SAI_TUNNEL_STAT_IN_PACKETS"}, @@ -233,9 +273,18 @@ TEST(FlexCounter, addRemoveCounter) counterVerifyFunc, false); + testAddRemoveCounter( + 1, + (sai_object_type_t)SAI_OBJECT_TYPE_ENI, + ENI_COUNTER_ID_LIST, + {"SAI_ENI_STAT_FLOW_CREATED", "SAI_ENI_STAT_FLOW_CREATE_FAILED", "SAI_ENI_STAT_FLOW_DELETED", "SAI_ENI_STAT_FLOW_DELETE_FAILED"}, + {"100", "200", "300", "400"}, + counterVerifyFunc, + false); + clearCalled = false; testAddRemoveCounter( - {sai_object_id_t(0x18000000000000)}, + 1, SAI_OBJECT_TYPE_BUFFER_POOL, BUFFER_POOL_COUNTER_ID_LIST, {"SAI_BUFFER_POOL_STAT_CURR_OCCUPANCY_BYTES", "SAI_BUFFER_POOL_STAT_WATERMARK_BYTES"}, @@ -256,7 +305,7 @@ TEST(FlexCounter, addRemoveCounter) }; testAddRemoveCounter( - {sai_object_id_t(0x15000000000000)}, + 1, SAI_OBJECT_TYPE_QUEUE, QUEUE_ATTR_ID_LIST, {"SAI_QUEUE_ATTR_PAUSE_STATUS"}, @@ -276,7 +325,7 @@ TEST(FlexCounter, addRemoveCounter) }; testAddRemoveCounter( - {sai_object_id_t(0x1a000000000000)}, + 1, SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP, PG_ATTR_ID_LIST, {"SAI_INGRESS_PRIORITY_GROUP_ATTR_PORT"}, @@ -300,7 +349,7 @@ TEST(FlexCounter, addRemoveCounter) }; testAddRemoveCounter( - {sai_object_id_t(0x5c000000000000)}, + 1, SAI_OBJECT_TYPE_MACSEC_SA, MACSEC_SA_ATTR_ID_LIST, {"SAI_MACSEC_SA_ATTR_CONFIGURED_EGRESS_XPN", "SAI_MACSEC_SA_ATTR_AN"}, @@ -320,7 +369,7 @@ TEST(FlexCounter, addRemoveCounter) }; testAddRemoveCounter( - {sai_object_id_t(0x9000000000000)}, + 1, SAI_OBJECT_TYPE_ACL_COUNTER, ACL_COUNTER_ATTR_ID_LIST, {"SAI_ACL_COUNTER_ATTR_PACKETS"}, @@ -373,7 +422,7 @@ TEST(FlexCounter, queryCounterCapability) }; testAddRemoveCounter( - {sai_object_id_t(0x1000000000000)}, + 1, SAI_OBJECT_TYPE_PORT, PORT_COUNTER_ID_LIST, {"SAI_PORT_STAT_IF_IN_OCTETS", "SAI_PORT_STAT_IF_IN_UCAST_PKTS"}, @@ -586,7 +635,7 @@ TEST(FlexCounter, bulkCounter) }; testAddRemoveCounter( - {sai_object_id_t(0x54000000000000), sai_object_id_t(0x54000000000001)}, + 2, SAI_OBJECT_TYPE_COUNTER, FLOW_COUNTER_ID_LIST, {"SAI_COUNTER_STAT_PACKETS", "SAI_COUNTER_STAT_BYTES"}, @@ -595,7 +644,7 @@ TEST(FlexCounter, bulkCounter) true); testAddRemoveCounter( - {sai_object_id_t(0x5a000000000000), sai_object_id_t(0x5a000000000001)}, + 2, SAI_OBJECT_TYPE_MACSEC_FLOW, MACSEC_FLOW_COUNTER_ID_LIST, {"SAI_MACSEC_FLOW_STAT_CONTROL_PKTS", "SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED"}, @@ -604,7 +653,7 @@ TEST(FlexCounter, bulkCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x5c000000000000), sai_object_id_t(0x5c000000000001)}, + 2, SAI_OBJECT_TYPE_MACSEC_SA, MACSEC_SA_COUNTER_ID_LIST, {"SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED", "SAI_MACSEC_SA_STAT_OCTETS_PROTECTED"}, @@ -613,7 +662,7 @@ TEST(FlexCounter, bulkCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x1000000000000), sai_object_id_t(0x1000000000001)}, + 2, SAI_OBJECT_TYPE_PORT, PORT_COUNTER_ID_LIST, {"SAI_PORT_STAT_IF_IN_OCTETS", "SAI_PORT_STAT_IF_IN_UCAST_PKTS"}, @@ -622,7 +671,7 @@ TEST(FlexCounter, bulkCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x1000000000000), sai_object_id_t(0x1000000000001)}, + 2, SAI_OBJECT_TYPE_PORT, PORT_DEBUG_COUNTER_ID_LIST, {"SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS", "SAI_PORT_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"}, @@ -631,7 +680,7 @@ TEST(FlexCounter, bulkCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x15000000000000), sai_object_id_t(0x15000000000001)}, + 2, SAI_OBJECT_TYPE_QUEUE, QUEUE_COUNTER_ID_LIST, {"SAI_QUEUE_STAT_PACKETS", "SAI_QUEUE_STAT_BYTES"}, @@ -642,7 +691,7 @@ TEST(FlexCounter, bulkCounter) EXPECT_EQ(true, clearCalled); testAddRemoveCounter( - {sai_object_id_t(0x1a000000000000), sai_object_id_t(0x1a000000000001)}, + 2, SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP, PG_COUNTER_ID_LIST, {"SAI_INGRESS_PRIORITY_GROUP_STAT_PACKETS", "SAI_INGRESS_PRIORITY_GROUP_STAT_BYTES"}, @@ -651,7 +700,7 @@ TEST(FlexCounter, bulkCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x6000000000000), sai_object_id_t(0x6000000000001)}, + 2, SAI_OBJECT_TYPE_ROUTER_INTERFACE, RIF_COUNTER_ID_LIST, {"SAI_ROUTER_INTERFACE_STAT_IN_OCTETS", "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS"}, @@ -660,7 +709,7 @@ TEST(FlexCounter, bulkCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x21000000000000), sai_object_id_t(0x21000000000001)}, + 2, SAI_OBJECT_TYPE_SWITCH, SWITCH_DEBUG_COUNTER_ID_LIST, {"SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_0_DROPPED_PKTS", "SAI_SWITCH_STAT_IN_CONFIGURED_DROP_REASONS_1_DROPPED_PKTS"}, @@ -669,7 +718,7 @@ TEST(FlexCounter, bulkCounter) false); testAddRemoveCounter( - {sai_object_id_t(0x2a000000000000), sai_object_id_t(0x2a000000000001)}, + 2, SAI_OBJECT_TYPE_TUNNEL, TUNNEL_COUNTER_ID_LIST, {"SAI_TUNNEL_STAT_IN_OCTETS", "SAI_TUNNEL_STAT_IN_PACKETS"}, @@ -677,9 +726,18 @@ TEST(FlexCounter, bulkCounter) counterVerifyFunc, false); + testAddRemoveCounter( + 2, + (sai_object_type_t)SAI_OBJECT_TYPE_ENI, + ENI_COUNTER_ID_LIST, + {"SAI_ENI_STAT_FLOW_CREATED", "SAI_ENI_STAT_FLOW_CREATE_FAILED", "SAI_ENI_STAT_FLOW_DELETED", "SAI_ENI_STAT_FLOW_DELETE_FAILED"}, + {"100", "200", "300", "400"}, + counterVerifyFunc, + false); + clearCalled = false; testAddRemoveCounter( - {sai_object_id_t(0x18000000000000), sai_object_id_t(0x18000000000001)}, + 2, SAI_OBJECT_TYPE_BUFFER_POOL, BUFFER_POOL_COUNTER_ID_LIST, {"SAI_BUFFER_POOL_STAT_CURR_OCCUPANCY_BYTES", "SAI_BUFFER_POOL_STAT_WATERMARK_BYTES"},