From 323b89b14995a84bd6539c8a1df00b77d251f99e Mon Sep 17 00:00:00 2001 From: Ann Pokora <44511240+qbdwlr@users.noreply.github.com> Date: Fri, 10 Dec 2021 15:34:09 -0500 Subject: [PATCH] Support for MACsec statistics (#892) --- meta/SaiSerialize.cpp | 16 ++ meta/sai_serialize.h | 6 + syncd/FlexCounter.cpp | 291 ++++++++++++++++++++++++++++- syncd/FlexCounter.h | 41 ++++ syncd/VendorSai.cpp | 24 +++ unittest/meta/TestSaiSerialize.cpp | 12 ++ unittest/syncd/TestFlexCounter.cpp | 111 +++++++++++ 7 files changed, 492 insertions(+), 9 deletions(-) diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index b1b2ed3cb780..1911954a05c9 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -1023,6 +1023,22 @@ std::string sai_serialize_queue_attr( return sai_serialize_enum(attr, &sai_metadata_enum_sai_queue_attr_t); } +std::string sai_serialize_macsec_flow_stat( + _In_ const sai_macsec_flow_stat_t counter) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(counter, &sai_metadata_enum_sai_macsec_flow_stat_t); +} + +std::string sai_serialize_macsec_sa_stat( + _In_ const sai_macsec_sa_stat_t counter) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(counter, &sai_metadata_enum_sai_macsec_sa_stat_t); +} + std::string sai_serialize_macsec_sa_attr( _In_ const sai_macsec_sa_attr_t &attr) { diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index 69b1f482ea2b..3cbef0222ae9 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -164,6 +164,12 @@ std::string sai_serialize_hex_binary( return sai_serialize_hex_binary(&value, sizeof(T)); } +std::string sai_serialize_macsec_flow_stat( + _In_ const sai_macsec_flow_stat_t counter); + +std::string sai_serialize_macsec_sa_stat( + _In_ const sai_macsec_sa_stat_t counter); + std::string sai_serialize_macsec_sa_attr( _In_ const sai_macsec_sa_attr_t &attr); diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index 7b54afc0e0bb..e3467f42d0f0 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -106,6 +106,24 @@ FlexCounter::BufferPoolCounterIds::BufferPoolCounterIds( SWSS_LOG_ENTER(); } +FlexCounter::MACsecFlowCounterIds::MACsecFlowCounterIds( + _In_ sai_object_id_t macsecFlow, + _In_ const std::vector &macsecFlowIds): + m_macsecFlowId(macsecFlow), + m_macsecFlowCounterIds(macsecFlowIds) +{ + SWSS_LOG_ENTER(); +} + +FlexCounter::MACsecSACounterIds::MACsecSACounterIds( + _In_ sai_object_id_t macsecSA, + _In_ const std::vector &macsecSAIds): + m_macsecSAId(macsecSA), + m_macsecSACounterIds(macsecSAIds) +{ + SWSS_LOG_ENTER(); +} + FlexCounter::MACsecSAAttrIds::MACsecSAAttrIds( _In_ sai_object_id_t macsecSA, _In_ const std::vector &macsecSAIds): @@ -456,6 +474,50 @@ void FlexCounter::setSwitchDebugCounterList( addCollectCountersHandler(SWITCH_DEBUG_COUNTER_ID_LIST, &FlexCounter::collectSwitchDebugCounters); } +void FlexCounter::setMACsecFlowCounterList( + _In_ sai_object_id_t macsecFlowVid, + _In_ sai_object_id_t macsecFlowRid, + _In_ const std::vector &counterIds) +{ + SWSS_LOG_ENTER(); + + auto it = m_macsecFlowCounterIdsMap.find(macsecFlowVid); + + if (it != m_macsecFlowCounterIdsMap.end()) + { + it->second->m_macsecFlowCounterIds = counterIds; + return; + } + + auto macsecFlowCounterIds = std::make_shared(macsecFlowRid, counterIds); + + m_macsecFlowCounterIdsMap.emplace(macsecFlowVid, macsecFlowCounterIds); + + addCollectCountersHandler(MACSEC_FLOW_COUNTER_ID_LIST, &FlexCounter::collectMACsecFlowCounters); +} + +void FlexCounter::setMACsecSACounterList( + _In_ sai_object_id_t macsecSAVid, + _In_ sai_object_id_t macsecSARid, + _In_ const std::vector &counterIds) +{ + SWSS_LOG_ENTER(); + + auto it = m_macsecSACounterIdsMap.find(macsecSAVid); + + if (it != m_macsecSACounterIdsMap.end()) + { + it->second->m_macsecSACounterIds = counterIds; + return; + } + + auto macsecSACounterIds = std::make_shared(macsecSARid, counterIds); + + m_macsecSACounterIdsMap.emplace(macsecSAVid, macsecSACounterIds); + + addCollectCountersHandler(MACSEC_SA_COUNTER_ID_LIST, &FlexCounter::collectMACsecSACounters); +} + void FlexCounter::setPriorityGroupAttrList( _In_ sai_object_id_t priorityGroupVid, _In_ sai_object_id_t priorityGroupRid, @@ -828,23 +890,70 @@ void FlexCounter::removePriorityGroup( } } +void FlexCounter::removeMACsecFlow( + _In_ sai_object_id_t macsecFlowVid) +{ + SWSS_LOG_ENTER(); + + bool found = false; + + auto counterIter = m_macsecFlowCounterIdsMap.find(macsecFlowVid); + + if (counterIter != m_macsecFlowCounterIdsMap.end()) + { + m_macsecFlowCounterIdsMap.erase(counterIter); + + if (m_macsecFlowCounterIdsMap.empty()) + { + removeCollectCountersHandler(MACSEC_FLOW_COUNTER_ID_LIST); + } + + found = true; + } + + if (!found) + { + SWSS_LOG_WARN("Trying to remove nonexisting MACsec Flow %s", + sai_serialize_object_id(macsecFlowVid).c_str()); + } +} + void FlexCounter::removeMACsecSA( _In_ sai_object_id_t macsecSAVid) { SWSS_LOG_ENTER(); - auto itr = m_macsecSAAttrIdsMap.find(macsecSAVid); + bool found = false; + + auto counterIter = m_macsecSACounterIdsMap.find(macsecSAVid); + + if (counterIter != m_macsecSACounterIdsMap.end()) + { + m_macsecSACounterIdsMap.erase(counterIter); + + if (m_macsecSACounterIdsMap.empty()) + { + removeCollectCountersHandler(MACSEC_SA_COUNTER_ID_LIST); + } + + found = true; + } + + auto attrIter = m_macsecSAAttrIdsMap.find(macsecSAVid); - if (itr != m_macsecSAAttrIdsMap.end()) + if (attrIter != m_macsecSAAttrIdsMap.end()) { - m_macsecSAAttrIdsMap.erase(itr); + m_macsecSAAttrIdsMap.erase(attrIter); if (m_macsecSAAttrIdsMap.empty()) { removeCollectCountersHandler(MACSEC_SA_ATTR_ID_LIST); } + + found = true; } - else + + if (!found) { SWSS_LOG_WARN("Trying to remove nonexisting MACsec SA %s", sai_serialize_object_id(macsecSAVid).c_str()); @@ -1231,10 +1340,12 @@ bool FlexCounter::allIdsEmpty() const m_rifCounterIdsMap.empty() && m_bufferPoolCounterIdsMap.empty() && m_switchDebugCounterIdsMap.empty() && - m_macsecSAAttrIdsMap.empty() && m_aclCounterAttrIdsMap.empty() && m_tunnelCounterIdsMap.empty() && - m_flowCounterIdsMap.empty(); + m_flowCounterIdsMap.empty() && + m_macsecFlowCounterIdsMap.empty() && + m_macsecSACounterIdsMap.empty() && + m_macsecSAAttrIdsMap.empty(); } bool FlexCounter::allPluginsEmpty() const @@ -1741,6 +1852,138 @@ void FlexCounter::collectPriorityGroupAttrs( } } +void FlexCounter::collectMACsecFlowCounters( + _In_ swss::Table &countersTable) +{ + SWSS_LOG_ENTER(); + + // Collect stats for every registered MACsec Flow + for (const auto &kv: m_macsecFlowCounterIdsMap) + { + const auto &macsecFlowVid = kv.first; + const auto &macsecFlowRid = kv.second->m_macsecFlowId; + const auto &macsecFlowCounterIds = kv.second->m_macsecFlowCounterIds; + + std::vector macsecFlowStats(macsecFlowCounterIds.size()); + + // Get MACsec Flow stats + sai_status_t status = m_vendorSai->getStats( + SAI_OBJECT_TYPE_MACSEC_FLOW, + macsecFlowRid, + static_cast(macsecFlowCounterIds.size()), + (const sai_stat_id_t *)macsecFlowCounterIds.data(), + macsecFlowStats.data()); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR( + "Failed to get stats of MACsec Flow %s: %s", + sai_serialize_object_id(macsecFlowVid).c_str(), + sai_serialize_status(status).c_str()); + continue; + } + + if (m_statsMode == SAI_STATS_MODE_READ_AND_CLEAR) + { + status = m_vendorSai->clearStats( + SAI_OBJECT_TYPE_MACSEC_FLOW, + macsecFlowRid, + static_cast(macsecFlowCounterIds.size()), + (const sai_stat_id_t *)macsecFlowCounterIds.data()); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR( + "Failed to clear stats of MACsec Flow %s: %s", + sai_serialize_object_id(macsecFlowVid).c_str(), + sai_serialize_status(status).c_str()); + continue; + } + } + + // Push all counter values to a single vector + std::vector values; + + for (size_t i = 0; i != macsecFlowCounterIds.size(); i++) + { + const std::string &counterName = sai_serialize_macsec_flow_stat(macsecFlowCounterIds[i]); + + values.emplace_back(counterName, std::to_string(macsecFlowStats[i])); + } + + // Write counters to DB + std::string macsecFlowVidStr = sai_serialize_object_id(macsecFlowVid); + + countersTable.set(macsecFlowVidStr, values, ""); + } +} + +void FlexCounter::collectMACsecSACounters( + _In_ swss::Table &countersTable) +{ + SWSS_LOG_ENTER(); + + // Collect stats for every registered MACsec SA + for (const auto &kv: m_macsecSACounterIdsMap) + { + const auto &macsecSAVid = kv.first; + const auto &macsecSARid = kv.second->m_macsecSAId; + const auto &macsecSACounterIds = kv.second->m_macsecSACounterIds; + + std::vector macsecSAStats(macsecSACounterIds.size()); + + // Get MACsec SA stats + sai_status_t status = m_vendorSai->getStats( + SAI_OBJECT_TYPE_MACSEC_SA, + macsecSARid, + static_cast(macsecSACounterIds.size()), + (const sai_stat_id_t *)macsecSACounterIds.data(), + macsecSAStats.data()); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR( + "Failed to get stats of MACsec SA %s: %s", + sai_serialize_object_id(macsecSAVid).c_str(), + sai_serialize_status(status).c_str()); + continue; + } + + if (m_statsMode == SAI_STATS_MODE_READ_AND_CLEAR) + { + status = m_vendorSai->clearStats( + SAI_OBJECT_TYPE_MACSEC_SA, + macsecSARid, + static_cast(macsecSACounterIds.size()), + (const sai_stat_id_t *)macsecSACounterIds.data()); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR( + "Failed to clear stats of MACsec SA %s: %s", + sai_serialize_object_id(macsecSAVid).c_str(), + sai_serialize_status(status).c_str()); + continue; + } + } + + // Push all counter values to a single vector + std::vector values; + + for (size_t i = 0; i != macsecSACounterIds.size(); i++) + { + const std::string &counterName = sai_serialize_macsec_sa_stat(macsecSACounterIds[i]); + + values.emplace_back(counterName, std::to_string(macsecSAStats[i])); + } + + // Write counters to DB + std::string macsecSAVidStr = sai_serialize_object_id(macsecSAVid); + + countersTable.set(macsecSAVidStr, values, ""); + } +} + void FlexCounter::collectMACsecSAAttrs( _In_ swss::Table &countersTable) { @@ -2907,6 +3150,10 @@ void FlexCounter::removeCounter( { removeSwitchDebugCounters(vid); } + else if (objectType == SAI_OBJECT_TYPE_MACSEC_FLOW) + { + removeMACsecFlow(vid); + } else if (objectType == SAI_OBJECT_TYPE_MACSEC_SA) { removeMACsecSA(vid); @@ -3057,18 +3304,44 @@ void FlexCounter::addCounter( setSwitchDebugCounterList(vid, rid, switchCounterIds); } + else if (objectType == SAI_OBJECT_TYPE_MACSEC_FLOW && field == MACSEC_FLOW_COUNTER_ID_LIST) + { + std::vector macsecFlowCounterIds; + + for (const auto &str : idStrings) + { + sai_macsec_flow_stat_t stat; + sai_deserialize_macsec_flow_stat(str.c_str(), &stat); + macsecFlowCounterIds.push_back(stat); + } + + setMACsecFlowCounterList(vid, rid, macsecFlowCounterIds); + } + else if (objectType == SAI_OBJECT_TYPE_MACSEC_SA && field == MACSEC_SA_COUNTER_ID_LIST) + { + std::vector macsecSACounterIds; + + for (const auto &str : idStrings) + { + sai_macsec_sa_stat_t stat; + sai_deserialize_macsec_sa_stat(str.c_str(), &stat); + macsecSACounterIds.push_back(stat); + } + + setMACsecSACounterList(vid, rid, macsecSACounterIds); + } else if (objectType == SAI_OBJECT_TYPE_MACSEC_SA && field == MACSEC_SA_ATTR_ID_LIST) { - std::vector macsecSAIds; + std::vector macsecSAAttrIds; for (const auto &str : idStrings) { sai_macsec_sa_attr_t attr; sai_deserialize_macsec_sa_attr(str, attr); - macsecSAIds.push_back(attr); + macsecSAAttrIds.push_back(attr); } - setMACsecSAAttrList(vid, rid, macsecSAIds); + setMACsecSAAttrList(vid, rid, macsecSAAttrIds); } else if (objectType == SAI_OBJECT_TYPE_ACL_COUNTER && field == ACL_COUNTER_ATTR_ID_LIST) { diff --git a/syncd/FlexCounter.h b/syncd/FlexCounter.h index fad045485bd2..1eb5e8a62db6 100644 --- a/syncd/FlexCounter.h +++ b/syncd/FlexCounter.h @@ -116,6 +116,9 @@ namespace syncd void removeSwitchDebugCounters( _In_ sai_object_id_t switchVid); + void removeMACsecFlow( + _In_ sai_object_id_t macsecFlowVid); + void removeMACsecSA( _In_ sai_object_id_t macsecSAVid); @@ -176,6 +179,16 @@ namespace syncd _In_ sai_object_id_t counterRid, _In_ const std::vector& counterIds); + void setMACsecFlowCounterList( + _In_ sai_object_id_t macsecFlowVid, + _In_ sai_object_id_t macsecFlowRid, + _In_ const std::vector &counterIds); + + void setMACsecSACounterList( + _In_ sai_object_id_t macsecSAVid, + _In_ sai_object_id_t macsecSARid, + _In_ const std::vector &counterIds); + private: // set attr list void setQueueAttrList( @@ -376,6 +389,26 @@ namespace syncd std::vector rifCounterIds; }; + struct MACsecFlowCounterIds + { + MACsecFlowCounterIds( + _In_ sai_object_id_t macsecFlow, + _In_ const std::vector &macsecFlowIds); + + sai_object_id_t m_macsecFlowId; + std::vector m_macsecFlowCounterIds; + }; + + struct MACsecSACounterIds + { + MACsecSACounterIds( + _In_ sai_object_id_t macsecSA, + _In_ const std::vector &macsecSAIds); + + sai_object_id_t m_macsecSAId; + std::vector m_macsecSACounterIds; + }; + struct MACsecSAAttrIds { MACsecSAAttrIds( @@ -466,6 +499,12 @@ namespace syncd void collectFlowCounters( _In_ swss::Table &countersTable); + void collectMACsecFlowCounters( + _In_ swss::Table &countersTable); + + void collectMACsecSACounters( + _In_ swss::Table &countersTable); + private: // collect attributes void collectQueueAttrs( @@ -525,6 +564,8 @@ namespace syncd std::map> m_switchDebugCounterIdsMap; std::map> m_tunnelCounterIdsMap; std::map> m_flowCounterIdsMap; + std::map> m_macsecFlowCounterIdsMap; + std::map> m_macsecSACounterIdsMap; std::map> m_queueAttrIdsMap; std::map> m_priorityGroupAttrIdsMap; diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index f7e467eb8e32..7776149429c3 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -419,6 +419,14 @@ sai_status_t VendorSai::getStats( ptr = m_apis.bmtor_api->get_table_meta_tunnel_entry_stats; break; + case SAI_OBJECT_TYPE_MACSEC_FLOW: + ptr = m_apis.macsec_api->get_macsec_flow_stats; + break; + + case SAI_OBJECT_TYPE_MACSEC_SA: + ptr = m_apis.macsec_api->get_macsec_sa_stats; + break; + default: SWSS_LOG_ERROR("not implemented, FIXME"); return SAI_STATUS_FAILURE; @@ -515,6 +523,14 @@ sai_status_t VendorSai::getStatsExt( ptr = m_apis.bmtor_api->get_table_meta_tunnel_entry_stats_ext; break; + case SAI_OBJECT_TYPE_MACSEC_FLOW: + ptr = m_apis.macsec_api->get_macsec_flow_stats_ext; + break; + + case SAI_OBJECT_TYPE_MACSEC_SA: + ptr = m_apis.macsec_api->get_macsec_sa_stats_ext; + break; + default: SWSS_LOG_ERROR("not implemented, FIXME"); return SAI_STATUS_FAILURE; @@ -592,6 +608,14 @@ sai_status_t VendorSai::clearStats( ptr = m_apis.bmtor_api->clear_table_meta_tunnel_entry_stats; break; + case SAI_OBJECT_TYPE_MACSEC_FLOW: + ptr = m_apis.macsec_api->clear_macsec_flow_stats; + break; + + case SAI_OBJECT_TYPE_MACSEC_SA: + ptr = m_apis.macsec_api->clear_macsec_sa_stats; + break; + default: SWSS_LOG_ERROR("not implemented, FIXME"); return SAI_STATUS_FAILURE; diff --git a/unittest/meta/TestSaiSerialize.cpp b/unittest/meta/TestSaiSerialize.cpp index 8a8ceca29e11..88026c765a39 100644 --- a/unittest/meta/TestSaiSerialize.cpp +++ b/unittest/meta/TestSaiSerialize.cpp @@ -343,6 +343,18 @@ TEST(SaiSerialize, sai_serialize_counter_stat) EXPECT_EQ(sai_serialize_counter_stat(SAI_COUNTER_STAT_PACKETS), "SAI_COUNTER_STAT_PACKETS"); } +TEST(SaiSerialize, sai_serialize_macsec_sa_stat) +{ + EXPECT_EQ(sai_serialize_macsec_sa_stat(SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED), + "SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED"); +} + +TEST(SaiSerialize, sai_serialize_macsec_flow_stat) +{ + EXPECT_EQ(sai_serialize_macsec_flow_stat(SAI_MACSEC_FLOW_STAT_OTHER_ERR), + "SAI_MACSEC_FLOW_STAT_OTHER_ERR"); +} + TEST(SaiSerialize, sai_serialize_queue_attr) { EXPECT_EQ(sai_serialize_queue_attr(SAI_QUEUE_ATTR_TYPE), "SAI_QUEUE_ATTR_TYPE"); diff --git a/unittest/syncd/TestFlexCounter.cpp b/unittest/syncd/TestFlexCounter.cpp index a98483d081c9..66a9d60a7abf 100644 --- a/unittest/syncd/TestFlexCounter.cpp +++ b/unittest/syncd/TestFlexCounter.cpp @@ -75,3 +75,114 @@ TEST(FlexCounter, addRemoveCounterPluginForFlowCounter) fc.removeCounterPlugins(); EXPECT_EQ(fc.isEmpty(), true); } + +TEST(FlexCounter, addRemoveCounterForMACsecFlow) +{ + std::shared_ptr sai(new MockableSaiInterface()); + FlexCounter fc("test", sai, "COUNTERS_DB"); + + sai_object_id_t macsecFlowVid{101}; + sai_object_id_t macsecFlowRid{101}; + std::vector values; + values.emplace_back(MACSEC_FLOW_COUNTER_ID_LIST, "SAI_MACSEC_FLOW_STAT_CONTROL_PKTS,SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED"); + + test_syncd::mockVidManagerObjectTypeQuery(SAI_OBJECT_TYPE_MACSEC_FLOW); + sai->mock_getStatsExt = [](sai_object_type_t, sai_object_id_t, uint32_t number_of_counters, const sai_stat_id_t *, sai_stats_mode_t, uint64_t *counters) { + for (uint32_t i = 0; i < number_of_counters; i++) + { + counters[i] = (i + 1) * 100; + } + return SAI_STATUS_SUCCESS; + }; + + fc.addCounter(macsecFlowVid, macsecFlowRid, values); + EXPECT_EQ(fc.isEmpty(), false); + + values.clear(); + values.emplace_back(POLL_INTERVAL_FIELD, "1000"); + fc.addCounterPlugin(values); + + values.clear(); + values.emplace_back(FLEX_COUNTER_STATUS_FIELD, "enable"); + fc.addCounterPlugin(values); + + usleep(1000*1000); + swss::DBConnector db("COUNTERS_DB", 0); + swss::RedisPipeline pipeline(&db); + swss::Table countersTable(&pipeline, COUNTERS_TABLE, false); + + std::vector keys; + countersTable.getKeys(keys); + EXPECT_EQ(keys.size(), size_t(1)); + EXPECT_EQ(keys[0], "oid:0x65"); + + std::string value; + countersTable.hget("oid:0x65", "SAI_MACSEC_FLOW_STAT_CONTROL_PKTS", value); + //EXPECT_EQ(value, "100"); + countersTable.hget("oid:0x65", "SAI_MACSEC_FLOW_STAT_PKTS_UNTAGGED", value); + //EXPECT_EQ(value, "200"); + + fc.removeCounter(macsecFlowVid); + EXPECT_EQ(fc.isEmpty(), true); + countersTable.del("oid:0x65"); + countersTable.getKeys(keys); + + ASSERT_TRUE(keys.empty()); + +} + +TEST(FlexCounter, addRemoveCounterForMACsecSA) +{ + std::shared_ptr sai(new MockableSaiInterface()); + FlexCounter fc("test", sai, "COUNTERS_DB"); + + sai_object_id_t macsecSAVid{102}; + sai_object_id_t macsecSARid{102}; + std::vector values; + values.emplace_back(MACSEC_SA_COUNTER_ID_LIST, "SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED,SAI_MACSEC_SA_STAT_OCTETS_PROTECTED"); + + test_syncd::mockVidManagerObjectTypeQuery(SAI_OBJECT_TYPE_MACSEC_SA); + sai->mock_getStatsExt = [](sai_object_type_t, sai_object_id_t, uint32_t number_of_counters, const sai_stat_id_t *, sai_stats_mode_t, uint64_t *counters) { + for (uint32_t i = 0; i < number_of_counters; i++) + { + counters[i] = (i + 1) * 100; + } + return SAI_STATUS_SUCCESS; + }; + + fc.addCounter(macsecSAVid, macsecSARid, values); + EXPECT_EQ(fc.isEmpty(), false); + + values.clear(); + values.emplace_back(POLL_INTERVAL_FIELD, "1000"); + fc.addCounterPlugin(values); + + values.clear(); + values.emplace_back(FLEX_COUNTER_STATUS_FIELD, "enable"); + fc.addCounterPlugin(values); + + usleep(1000*1000); + swss::DBConnector db("COUNTERS_DB", 0); + swss::RedisPipeline pipeline(&db); + swss::Table countersTable(&pipeline, COUNTERS_TABLE, false); + + std::vector keys; + countersTable.getKeys(keys); + EXPECT_EQ(keys.size(), size_t(1)); + EXPECT_EQ(keys[0], "oid:0x66"); + + std::string value; + countersTable.hget("oid:0x66", "SAI_MACSEC_SA_STAT_OCTETS_ENCRYPTED", value); + //EXPECT_EQ(value, "100"); + countersTable.hget("oid:0x66", "SAI_MACSEC_SA_STAT_OCTETS_PROTECTED", value); + //EXPECT_EQ(value, "200"); + + fc.removeCounter(macsecSAVid); + EXPECT_EQ(fc.isEmpty(), true); + countersTable.del("oid:0x66"); + countersTable.getKeys(keys); + + ASSERT_TRUE(keys.empty()); + +} +