Skip to content

Commit

Permalink
Allow ACL entry creation without ACL counter (#818)
Browse files Browse the repository at this point in the history
Signed-off-by: Wenda Ni <wenni@microsoft.com>
  • Loading branch information
wendani authored and lguohan committed Mar 28, 2019
1 parent 60a8a0d commit a304007
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
36 changes: 24 additions & 12 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,16 @@ 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),
m_tableType(type),
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);
}
Expand Down Expand Up @@ -393,7 +394,7 @@ bool AclRule::create()
sai_attribute_t attr;
sai_status_t status;

if (!createCounter())
if (m_createCounter && !createCounter())
{
return false;
}
Expand All @@ -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)
Expand Down Expand Up @@ -528,7 +532,10 @@ bool AclRule::remove()
decreaseNextHopRefCount();

res = removeRanges();
res &= removeCounter();
if (m_createCounter)
{
res &= removeCounter();
}

return res;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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)
{
}

Expand Down
9 changes: 6 additions & 3 deletions orchagent/aclorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -218,12 +218,15 @@ class AclRule

vector<sai_object_id_t> m_inPorts;
vector<sai_object_id_t> 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);
Expand All @@ -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);
};

Expand Down

0 comments on commit a304007

Please sign in to comment.