From a304007275eb1c84d36d25ffb7fb9f5c15321ac8 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 28 Mar 2019 11:00:16 -0700 Subject: [PATCH] Allow ACL entry creation without ACL counter (#818) Signed-off-by: Wenda Ni --- orchagent/aclorch.cpp | 36 ++++++++++++++++++++++++------------ orchagent/aclorch.h | 9 ++++++--- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index ea49824f8aaf..d79f8213c6d1 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -122,7 +122,7 @@ inline string trim(const std::string& str, const std::string& whitespace = " \t" return str.substr(strBegin, strRange); } -AclRule::AclRule(AclOrch *aclOrch, string rule, string table, acl_table_type_t type) : +AclRule::AclRule(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) : m_pAclOrch(aclOrch), m_id(rule), m_tableId(table), @@ -130,7 +130,8 @@ AclRule::AclRule(AclOrch *aclOrch, string rule, string table, acl_table_type_t t m_tableOid(SAI_NULL_OBJECT_ID), m_ruleOid(SAI_NULL_OBJECT_ID), m_counterOid(SAI_NULL_OBJECT_ID), - m_priority(0) + m_priority(0), + m_createCounter(createCounter) { m_tableOid = aclOrch->getTableById(m_tableId); } @@ -393,7 +394,7 @@ bool AclRule::create() sai_attribute_t attr; sai_status_t status; - if (!createCounter()) + if (m_createCounter && !createCounter()) { return false; } @@ -414,10 +415,13 @@ bool AclRule::create() rule_attrs.push_back(attr); // add reference to the counter - attr.id = SAI_ACL_ENTRY_ATTR_ACTION_COUNTER; - attr.value.aclaction.parameter.oid = m_counterOid; - attr.value.aclaction.enable = true; - rule_attrs.push_back(attr); + if (m_createCounter) + { + attr.id = SAI_ACL_ENTRY_ATTR_ACTION_COUNTER; + attr.value.aclaction.parameter.oid = m_counterOid; + attr.value.aclaction.enable = true; + rule_attrs.push_back(attr); + } // store matches for (auto it : m_matches) @@ -528,7 +532,10 @@ bool AclRule::remove() decreaseNextHopRefCount(); res = removeRanges(); - res &= removeCounter(); + if (m_createCounter) + { + res &= removeCounter(); + } return res; } @@ -537,6 +544,11 @@ AclRuleCounters AclRule::getCounters() { SWSS_LOG_ENTER(); + if (!m_createCounter) + { + return AclRuleCounters(); + } + sai_attribute_t counter_attr[2]; counter_attr[0].id = SAI_ACL_COUNTER_ATTR_PACKETS; counter_attr[1].id = SAI_ACL_COUNTER_ATTR_BYTES; @@ -693,8 +705,8 @@ bool AclRule::removeCounter() return true; } -AclRuleL3::AclRuleL3(AclOrch *aclOrch, string rule, string table, acl_table_type_t type) : - AclRule(aclOrch, rule, table, type) +AclRuleL3::AclRuleL3(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) : + AclRule(aclOrch, rule, table, type, createCounter) { } @@ -862,8 +874,8 @@ void AclRuleL3::update(SubjectType, void *) } -AclRulePfcwd::AclRulePfcwd(AclOrch *aclOrch, string rule, string table, acl_table_type_t type) : - AclRuleL3(aclOrch, rule, table, type) +AclRulePfcwd::AclRulePfcwd(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) : + AclRuleL3(aclOrch, rule, table, type, createCounter) { } diff --git a/orchagent/aclorch.h b/orchagent/aclorch.h index 5d609dac4e69..1be9704508ec 100644 --- a/orchagent/aclorch.h +++ b/orchagent/aclorch.h @@ -159,7 +159,7 @@ struct AclRuleCounters class AclRule { public: - AclRule(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type); + AclRule(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type, bool createCounter = true); virtual bool validateAddPriority(string attr_name, string attr_value); virtual bool validateAddMatch(string attr_name, string attr_value); virtual bool validateAddAction(string attr_name, string attr_value) = 0; @@ -218,12 +218,15 @@ class AclRule vector m_inPorts; vector m_outPorts; + +private: + bool m_createCounter; }; class AclRuleL3: public AclRule { public: - AclRuleL3(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type); + AclRuleL3(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type, bool createCounter = true); bool validateAddAction(string attr_name, string attr_value); bool validateAddMatch(string attr_name, string attr_value); @@ -243,7 +246,7 @@ class AclRuleL3V6: public AclRuleL3 class AclRulePfcwd: public AclRuleL3 { public: - AclRulePfcwd(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type); + AclRulePfcwd(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type, bool createCounter = false); bool validateAddMatch(string attr_name, string attr_value); };