diff --git a/meta/SaiSerialize.cpp b/meta/SaiSerialize.cpp index 2a3b22c15..c07880062 100644 --- a/meta/SaiSerialize.cpp +++ b/meta/SaiSerialize.cpp @@ -1023,6 +1023,14 @@ std::string sai_serialize_macsec_sa_attr( return sai_serialize_enum(attr, &sai_metadata_enum_sai_macsec_sa_attr_t); } +std::string sai_serialize_acl_counter_attr( + _In_ const sai_acl_counter_attr_t &attr) +{ + SWSS_LOG_ENTER(); + + return sai_serialize_enum(attr, &sai_metadata_enum_sai_acl_counter_attr_t); +} + std::string sai_serialize_switch_oper_status( _In_ sai_object_id_t switch_id, _In_ sai_switch_oper_status_t status) @@ -4192,6 +4200,15 @@ void sai_deserialize_macsec_sa_attr( sai_deserialize_enum(s, &sai_metadata_enum_sai_macsec_sa_attr_t, (int32_t&)attr); } +void sai_deserialize_acl_counter_attr( + _In_ const std::string& s, + _Out_ sai_acl_counter_attr_t& attr) +{ + SWSS_LOG_ENTER(); + + sai_deserialize_enum(s, &sai_metadata_enum_sai_acl_counter_attr_t, (int32_t&)attr); +} + // sairedis void sai_deserialize( diff --git a/meta/sai_serialize.h b/meta/sai_serialize.h index 646501ea6..2471609c8 100644 --- a/meta/sai_serialize.h +++ b/meta/sai_serialize.h @@ -164,6 +164,9 @@ std::string sai_serialize_hex_binary( std::string sai_serialize_macsec_sa_attr( _In_ const sai_macsec_sa_attr_t &attr); +std::string sai_serialize_acl_counter_attr( + _In_ const sai_acl_counter_attr_t &attr); + std::string sai_serialize_switch_oper_status( _In_ sai_object_id_t switch_id, _In_ sai_switch_oper_status_t status); @@ -433,6 +436,10 @@ void sai_deserialize_macsec_sa_attr( _In_ const std::string& s, _Out_ sai_macsec_sa_attr_t& attr); +void sai_deserialize_acl_counter_attr( + _In_ const std::string& s, + _Out_ sai_acl_counter_attr_t& attr); + // sairedis void sai_deserialize( diff --git a/syncd/FlexCounter.cpp b/syncd/FlexCounter.cpp index 929eb7860..30852a6e0 100644 --- a/syncd/FlexCounter.cpp +++ b/syncd/FlexCounter.cpp @@ -114,6 +114,15 @@ FlexCounter::MACsecSAAttrIds::MACsecSAAttrIds( // empty intentionally } +FlexCounter::AclCounterAttrIds::AclCounterAttrIds( + _In_ sai_object_id_t aclCounter, + _In_ const std::vector &aclCounterIds): + m_aclCounterId(aclCounter), + m_aclCounterAttrIds(aclCounterIds) +{ + SWSS_LOG_ENTER(); +} + FlexCounter::TunnelCounterIds::TunnelCounterIds( _In_ sai_object_id_t tunnelRid, _In_ const std::vector &tunnelIds): @@ -479,6 +488,28 @@ void FlexCounter::setMACsecSAAttrList( addCollectCountersHandler(MACSEC_SA_ATTR_ID_LIST, &FlexCounter::collectMACsecSAAttrs); } +void FlexCounter::setAclCounterAttrList( + _In_ sai_object_id_t aclCounterVid, + _In_ sai_object_id_t aclCounterRid, + _In_ const std::vector &attrIds) +{ + SWSS_LOG_ENTER(); + + auto it = m_aclCounterAttrIdsMap.find(aclCounterVid); + + if (it != m_aclCounterAttrIdsMap.end()) + { + it->second->m_aclCounterAttrIds = attrIds; + return; + } + + auto aclCounterAttrIds = std::make_shared(aclCounterRid, attrIds); + + m_aclCounterAttrIdsMap.emplace(aclCounterVid, aclCounterAttrIds); + + addCollectCountersHandler(ACL_COUNTER_ATTR_ID_LIST, &FlexCounter::collectAclCounterAttrs); +} + void FlexCounter::setRifCounterList( _In_ sai_object_id_t rifVid, _In_ sai_object_id_t rifRid, @@ -770,6 +801,29 @@ void FlexCounter::removeMACsecSA( } } +void FlexCounter::removeAclCounter( + _In_ sai_object_id_t aclCounterVid) +{ + SWSS_LOG_ENTER(); + + auto itr = m_aclCounterAttrIdsMap.find(aclCounterVid); + + if (itr != m_aclCounterAttrIdsMap.end()) + { + m_aclCounterAttrIdsMap.erase(itr); + + if (m_aclCounterAttrIdsMap.empty()) + { + removeCollectCountersHandler(ACL_COUNTER_ATTR_ID_LIST); + } + } + else + { + SWSS_LOG_WARN("Trying to remove nonexisting ACL counter %s", + sai_serialize_object_id(aclCounterVid).c_str()); + } +} + void FlexCounter::removeRif( _In_ sai_object_id_t rifVid) { @@ -1075,6 +1129,7 @@ bool FlexCounter::allIdsEmpty() const m_bufferPoolCounterIdsMap.empty() && m_switchDebugCounterIdsMap.empty() && m_macsecSAAttrIdsMap.empty() && + m_aclCounterAttrIdsMap.empty() && m_tunnelCounterIdsMap.empty(); } @@ -1588,6 +1643,58 @@ void FlexCounter::collectMACsecSAAttrs( } } +void FlexCounter::collectAclCounterAttrs( + _In_ swss::Table &countersTable) +{ + SWSS_LOG_ENTER(); + + for (const auto &kv: m_aclCounterAttrIdsMap) + { + const auto &aclCounterVid = kv.first; + const auto &aclCounterRid = kv.second->m_aclCounterId; + const auto &aclCounterAttrIds = kv.second->m_aclCounterAttrIds; + + std::vector aclCounterAttrs(aclCounterAttrIds.size()); + + for (size_t i = 0; i < aclCounterAttrIds.size(); i++) + { + aclCounterAttrs[i].id = aclCounterAttrIds[i]; + } + + sai_status_t status = m_vendorSai->get( + SAI_OBJECT_TYPE_ACL_COUNTER, + aclCounterRid, + static_cast(aclCounterAttrs.size()), + aclCounterAttrs.data()); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_WARN( + "Failed to get attr of ACL counter %s: %s", + sai_serialize_object_id(aclCounterVid).c_str(), + sai_serialize_status(status).c_str()); + continue; + } + + std::vector values; + + for (const auto& aclCounterAttr : aclCounterAttrs) + { + auto meta = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_ACL_COUNTER, aclCounterAttr.id); + if (!meta) + { + SWSS_LOG_THROW("Failed to get metadata for SAI_OBJECT_TYPE_ACL_COUNTER"); + } + values.emplace_back(meta->attridname, sai_serialize_attr_value(*meta, aclCounterAttr)); + } + + // Write counters to DB + auto aclCounterVidStr = sai_serialize_object_id(aclCounterVid); + + countersTable.set(aclCounterVidStr, values); + } +} + void FlexCounter::collectRifCounters( _In_ swss::Table &countersTable) { @@ -2607,6 +2714,10 @@ void FlexCounter::removeCounter( { removeMACsecSA(vid); } + else if (objectType == SAI_OBJECT_TYPE_ACL_COUNTER) + { + removeAclCounter(vid); + } else if (objectType == SAI_OBJECT_TYPE_TUNNEL) { removeTunnel(vid); @@ -2758,6 +2869,19 @@ void FlexCounter::addCounter( setMACsecSAAttrList(vid, rid, macsecSAIds); } + else if (objectType == SAI_OBJECT_TYPE_ACL_COUNTER && field == ACL_COUNTER_ATTR_ID_LIST) + { + std::vector aclCounterIds; + + for (const auto &str : idStrings) + { + sai_acl_counter_attr_t attr{}; + sai_deserialize_acl_counter_attr(str, attr); + aclCounterIds.push_back(attr); + } + + setAclCounterAttrList(vid, rid, aclCounterIds); + } else if (objectType == SAI_OBJECT_TYPE_BUFFER_POOL && field == BUFFER_POOL_COUNTER_ID_LIST) { counterIds = idStrings; diff --git a/syncd/FlexCounter.h b/syncd/FlexCounter.h index 3f302798d..e8e88fa91 100644 --- a/syncd/FlexCounter.h +++ b/syncd/FlexCounter.h @@ -115,6 +115,9 @@ namespace syncd void removeMACsecSA( _In_ sai_object_id_t macsecSAVid); + void removeAclCounter( + _In_ sai_object_id_t aclCounterVid); + void removeTunnel( _In_ sai_object_id_t tunnelVid); @@ -178,6 +181,11 @@ namespace syncd _In_ sai_object_id_t macsecSARid, _In_ const std::vector &attrIds); + void setAclCounterAttrList( + _In_ sai_object_id_t aclCounterVid, + _In_ sai_object_id_t aclCounterRid, + _In_ const std::vector &attrIds); + private: // is counter supported bool isPortCounterSupported( @@ -362,6 +370,16 @@ namespace syncd std::vector m_macsecSAAttrIds; }; + struct AclCounterAttrIds + { + AclCounterAttrIds( + _In_ sai_object_id_t aclCounter, + _In_ const std::vector &aclCounterIds); + + sai_object_id_t m_aclCounterId; + std::vector m_aclCounterAttrIds; + }; + struct TunnelCounterIds { TunnelCounterIds( @@ -371,6 +389,7 @@ namespace syncd sai_object_id_t m_tunnelId; std::vector m_tunnelCounterIds; }; + private: void collectCounters( @@ -429,6 +448,9 @@ namespace syncd void collectMACsecSAAttrs( _In_ swss::Table &countersTable); + void collectAclCounterAttrs( + _In_ swss::Table &countersTable); + private: void addCollectCountersHandler( @@ -466,11 +488,10 @@ namespace syncd std::map> m_bufferPoolCounterIdsMap; std::map> m_switchDebugCounterIdsMap; std::map> m_tunnelCounterIdsMap; - std::map> m_queueAttrIdsMap; std::map> m_priorityGroupAttrIdsMap; - std::map> m_macsecSAAttrIdsMap; + std::map> m_aclCounterAttrIdsMap; private: