@@ -114,6 +114,15 @@ FlexCounter::MACsecSAAttrIds::MACsecSAAttrIds(
114
114
// empty intentionally
115
115
}
116
116
117
+ FlexCounter::AclCounterAttrIds::AclCounterAttrIds (
118
+ _In_ sai_object_id_t aclCounter,
119
+ _In_ const std::vector<sai_acl_counter_attr_t > &aclCounterIds):
120
+ m_aclCounterId(aclCounter),
121
+ m_aclCounterAttrIds(aclCounterIds)
122
+ {
123
+ SWSS_LOG_ENTER ();
124
+ }
125
+
117
126
FlexCounter::TunnelCounterIds::TunnelCounterIds (
118
127
_In_ sai_object_id_t tunnelRid,
119
128
_In_ const std::vector<sai_tunnel_stat_t > &tunnelIds):
@@ -479,6 +488,28 @@ void FlexCounter::setMACsecSAAttrList(
479
488
addCollectCountersHandler (MACSEC_SA_ATTR_ID_LIST, &FlexCounter::collectMACsecSAAttrs);
480
489
}
481
490
491
+ void FlexCounter::setAclCounterAttrList (
492
+ _In_ sai_object_id_t aclCounterVid,
493
+ _In_ sai_object_id_t aclCounterRid,
494
+ _In_ const std::vector<sai_acl_counter_attr_t > &attrIds)
495
+ {
496
+ SWSS_LOG_ENTER ();
497
+
498
+ auto it = m_aclCounterAttrIdsMap.find (aclCounterVid);
499
+
500
+ if (it != m_aclCounterAttrIdsMap.end ())
501
+ {
502
+ it->second ->m_aclCounterAttrIds = attrIds;
503
+ return ;
504
+ }
505
+
506
+ auto aclCounterAttrIds = std::make_shared<AclCounterAttrIds>(aclCounterRid, attrIds);
507
+
508
+ m_aclCounterAttrIdsMap.emplace (aclCounterVid, aclCounterAttrIds);
509
+
510
+ addCollectCountersHandler (ACL_COUNTER_ATTR_ID_LIST, &FlexCounter::collectAclCounterAttrs);
511
+ }
512
+
482
513
void FlexCounter::setRifCounterList (
483
514
_In_ sai_object_id_t rifVid,
484
515
_In_ sai_object_id_t rifRid,
@@ -770,6 +801,29 @@ void FlexCounter::removeMACsecSA(
770
801
}
771
802
}
772
803
804
+ void FlexCounter::removeAclCounter (
805
+ _In_ sai_object_id_t aclCounterVid)
806
+ {
807
+ SWSS_LOG_ENTER ();
808
+
809
+ auto itr = m_aclCounterAttrIdsMap.find (aclCounterVid);
810
+
811
+ if (itr != m_aclCounterAttrIdsMap.end ())
812
+ {
813
+ m_aclCounterAttrIdsMap.erase (itr);
814
+
815
+ if (m_aclCounterAttrIdsMap.empty ())
816
+ {
817
+ removeCollectCountersHandler (ACL_COUNTER_ATTR_ID_LIST);
818
+ }
819
+ }
820
+ else
821
+ {
822
+ SWSS_LOG_WARN (" Trying to remove nonexisting ACL counter %s" ,
823
+ sai_serialize_object_id (aclCounterVid).c_str ());
824
+ }
825
+ }
826
+
773
827
void FlexCounter::removeRif (
774
828
_In_ sai_object_id_t rifVid)
775
829
{
@@ -1075,6 +1129,7 @@ bool FlexCounter::allIdsEmpty() const
1075
1129
m_bufferPoolCounterIdsMap.empty () &&
1076
1130
m_switchDebugCounterIdsMap.empty () &&
1077
1131
m_macsecSAAttrIdsMap.empty () &&
1132
+ m_aclCounterAttrIdsMap.empty () &&
1078
1133
m_tunnelCounterIdsMap.empty ();
1079
1134
}
1080
1135
@@ -1588,6 +1643,58 @@ void FlexCounter::collectMACsecSAAttrs(
1588
1643
}
1589
1644
}
1590
1645
1646
+ void FlexCounter::collectAclCounterAttrs (
1647
+ _In_ swss::Table &countersTable)
1648
+ {
1649
+ SWSS_LOG_ENTER ();
1650
+
1651
+ for (const auto &kv: m_aclCounterAttrIdsMap)
1652
+ {
1653
+ const auto &aclCounterVid = kv.first ;
1654
+ const auto &aclCounterRid = kv.second ->m_aclCounterId ;
1655
+ const auto &aclCounterAttrIds = kv.second ->m_aclCounterAttrIds ;
1656
+
1657
+ std::vector<sai_attribute_t > aclCounterAttrs (aclCounterAttrIds.size ());
1658
+
1659
+ for (size_t i = 0 ; i < aclCounterAttrIds.size (); i++)
1660
+ {
1661
+ aclCounterAttrs[i].id = aclCounterAttrIds[i];
1662
+ }
1663
+
1664
+ sai_status_t status = m_vendorSai->get (
1665
+ SAI_OBJECT_TYPE_ACL_COUNTER,
1666
+ aclCounterRid,
1667
+ static_cast <uint32_t >(aclCounterAttrs.size ()),
1668
+ aclCounterAttrs.data ());
1669
+
1670
+ if (status != SAI_STATUS_SUCCESS)
1671
+ {
1672
+ SWSS_LOG_WARN (
1673
+ " Failed to get attr of ACL counter %s: %s" ,
1674
+ sai_serialize_object_id (aclCounterVid).c_str (),
1675
+ sai_serialize_status (status).c_str ());
1676
+ continue ;
1677
+ }
1678
+
1679
+ std::vector<swss::FieldValueTuple> values;
1680
+
1681
+ for (const auto & aclCounterAttr : aclCounterAttrs)
1682
+ {
1683
+ auto meta = sai_metadata_get_attr_metadata (SAI_OBJECT_TYPE_ACL_COUNTER, aclCounterAttr.id );
1684
+ if (!meta)
1685
+ {
1686
+ SWSS_LOG_THROW (" Failed to get metadata for SAI_OBJECT_TYPE_ACL_COUNTER" );
1687
+ }
1688
+ values.emplace_back (meta->attridname , sai_serialize_attr_value (*meta, aclCounterAttr));
1689
+ }
1690
+
1691
+ // Write counters to DB
1692
+ auto aclCounterVidStr = sai_serialize_object_id (aclCounterVid);
1693
+
1694
+ countersTable.set (aclCounterVidStr, values);
1695
+ }
1696
+ }
1697
+
1591
1698
void FlexCounter::collectRifCounters (
1592
1699
_In_ swss::Table &countersTable)
1593
1700
{
@@ -2607,6 +2714,10 @@ void FlexCounter::removeCounter(
2607
2714
{
2608
2715
removeMACsecSA (vid);
2609
2716
}
2717
+ else if (objectType == SAI_OBJECT_TYPE_ACL_COUNTER)
2718
+ {
2719
+ removeAclCounter (vid);
2720
+ }
2610
2721
else if (objectType == SAI_OBJECT_TYPE_TUNNEL)
2611
2722
{
2612
2723
removeTunnel (vid);
@@ -2758,6 +2869,19 @@ void FlexCounter::addCounter(
2758
2869
2759
2870
setMACsecSAAttrList (vid, rid, macsecSAIds);
2760
2871
}
2872
+ else if (objectType == SAI_OBJECT_TYPE_ACL_COUNTER && field == ACL_COUNTER_ATTR_ID_LIST)
2873
+ {
2874
+ std::vector<sai_acl_counter_attr_t > aclCounterIds;
2875
+
2876
+ for (const auto &str : idStrings)
2877
+ {
2878
+ sai_acl_counter_attr_t attr{};
2879
+ sai_deserialize_acl_counter_attr (str, attr);
2880
+ aclCounterIds.push_back (attr);
2881
+ }
2882
+
2883
+ setAclCounterAttrList (vid, rid, aclCounterIds);
2884
+ }
2761
2885
else if (objectType == SAI_OBJECT_TYPE_BUFFER_POOL && field == BUFFER_POOL_COUNTER_ID_LIST)
2762
2886
{
2763
2887
counterIds = idStrings;
0 commit comments