Skip to content

Commit a304007

Browse files
wendanilguohan
authored andcommitted
Allow ACL entry creation without ACL counter (#818)
Signed-off-by: Wenda Ni <wenni@microsoft.com>
1 parent 60a8a0d commit a304007

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

orchagent/aclorch.cpp

+24-12
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,16 @@ inline string trim(const std::string& str, const std::string& whitespace = " \t"
122122
return str.substr(strBegin, strRange);
123123
}
124124

125-
AclRule::AclRule(AclOrch *aclOrch, string rule, string table, acl_table_type_t type) :
125+
AclRule::AclRule(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) :
126126
m_pAclOrch(aclOrch),
127127
m_id(rule),
128128
m_tableId(table),
129129
m_tableType(type),
130130
m_tableOid(SAI_NULL_OBJECT_ID),
131131
m_ruleOid(SAI_NULL_OBJECT_ID),
132132
m_counterOid(SAI_NULL_OBJECT_ID),
133-
m_priority(0)
133+
m_priority(0),
134+
m_createCounter(createCounter)
134135
{
135136
m_tableOid = aclOrch->getTableById(m_tableId);
136137
}
@@ -393,7 +394,7 @@ bool AclRule::create()
393394
sai_attribute_t attr;
394395
sai_status_t status;
395396

396-
if (!createCounter())
397+
if (m_createCounter && !createCounter())
397398
{
398399
return false;
399400
}
@@ -414,10 +415,13 @@ bool AclRule::create()
414415
rule_attrs.push_back(attr);
415416

416417
// add reference to the counter
417-
attr.id = SAI_ACL_ENTRY_ATTR_ACTION_COUNTER;
418-
attr.value.aclaction.parameter.oid = m_counterOid;
419-
attr.value.aclaction.enable = true;
420-
rule_attrs.push_back(attr);
418+
if (m_createCounter)
419+
{
420+
attr.id = SAI_ACL_ENTRY_ATTR_ACTION_COUNTER;
421+
attr.value.aclaction.parameter.oid = m_counterOid;
422+
attr.value.aclaction.enable = true;
423+
rule_attrs.push_back(attr);
424+
}
421425

422426
// store matches
423427
for (auto it : m_matches)
@@ -528,7 +532,10 @@ bool AclRule::remove()
528532
decreaseNextHopRefCount();
529533

530534
res = removeRanges();
531-
res &= removeCounter();
535+
if (m_createCounter)
536+
{
537+
res &= removeCounter();
538+
}
532539

533540
return res;
534541
}
@@ -537,6 +544,11 @@ AclRuleCounters AclRule::getCounters()
537544
{
538545
SWSS_LOG_ENTER();
539546

547+
if (!m_createCounter)
548+
{
549+
return AclRuleCounters();
550+
}
551+
540552
sai_attribute_t counter_attr[2];
541553
counter_attr[0].id = SAI_ACL_COUNTER_ATTR_PACKETS;
542554
counter_attr[1].id = SAI_ACL_COUNTER_ATTR_BYTES;
@@ -693,8 +705,8 @@ bool AclRule::removeCounter()
693705
return true;
694706
}
695707

696-
AclRuleL3::AclRuleL3(AclOrch *aclOrch, string rule, string table, acl_table_type_t type) :
697-
AclRule(aclOrch, rule, table, type)
708+
AclRuleL3::AclRuleL3(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) :
709+
AclRule(aclOrch, rule, table, type, createCounter)
698710
{
699711
}
700712

@@ -862,8 +874,8 @@ void AclRuleL3::update(SubjectType, void *)
862874
}
863875

864876

865-
AclRulePfcwd::AclRulePfcwd(AclOrch *aclOrch, string rule, string table, acl_table_type_t type) :
866-
AclRuleL3(aclOrch, rule, table, type)
877+
AclRulePfcwd::AclRulePfcwd(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) :
878+
AclRuleL3(aclOrch, rule, table, type, createCounter)
867879
{
868880
}
869881

orchagent/aclorch.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct AclRuleCounters
159159
class AclRule
160160
{
161161
public:
162-
AclRule(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type);
162+
AclRule(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type, bool createCounter = true);
163163
virtual bool validateAddPriority(string attr_name, string attr_value);
164164
virtual bool validateAddMatch(string attr_name, string attr_value);
165165
virtual bool validateAddAction(string attr_name, string attr_value) = 0;
@@ -218,12 +218,15 @@ class AclRule
218218

219219
vector<sai_object_id_t> m_inPorts;
220220
vector<sai_object_id_t> m_outPorts;
221+
222+
private:
223+
bool m_createCounter;
221224
};
222225

223226
class AclRuleL3: public AclRule
224227
{
225228
public:
226-
AclRuleL3(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type);
229+
AclRuleL3(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type, bool createCounter = true);
227230

228231
bool validateAddAction(string attr_name, string attr_value);
229232
bool validateAddMatch(string attr_name, string attr_value);
@@ -243,7 +246,7 @@ class AclRuleL3V6: public AclRuleL3
243246
class AclRulePfcwd: public AclRuleL3
244247
{
245248
public:
246-
AclRulePfcwd(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type);
249+
AclRulePfcwd(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type, bool createCounter = false);
247250
bool validateAddMatch(string attr_name, string attr_value);
248251
};
249252

0 commit comments

Comments
 (0)