Skip to content

Commit

Permalink
remove crm acl_counters when acl_table removed (#918)
Browse files Browse the repository at this point in the history
* fix bad parameter for gCrmOrch->incCrmAclUsedCounter in qosorch

* fix VS test failure for test_crm.py::test_CrmAcl FAILED

* remove crm acl_counters when acl_table removed

Signed-off-by: Jared.Liu <Jared.Liu@nephosinc.com>

* add test case for remove crm acl_counters when acl_table removed #918
  • Loading branch information
JaredLius authored and prsunny committed Jul 3, 2019
1 parent 5a33f89 commit 80fcada
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 16 additions & 9 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,28 @@ void CrmOrch::decCrmAclUsedCounter(CrmResourceType resource, sai_acl_stage_t sta
{
m_resourcesMap.at(resource).countersMap[getCrmAclKey(stage, point)].usedCounter--;

// Remove ACL table related counters
// remove acl_entry and acl_counter in this acl table
if (resource == CrmResourceType::CRM_ACL_TABLE)
{
auto & cntMap = m_resourcesMap.at(CrmResourceType::CRM_ACL_TABLE).countersMap;
for (auto it = cntMap.begin(); it != cntMap.end();)
for (auto &resourcesMap : m_resourcesMap)
{
if (it->second.id == oid)
if ((resourcesMap.first == (CrmResourceType::CRM_ACL_ENTRY))
|| (resourcesMap.first == (CrmResourceType::CRM_ACL_COUNTER)))
{
it = cntMap.erase(it);
}
else
{
++it;
auto &cntMap = resourcesMap.second.countersMap;
for (auto it = cntMap.begin(); it != cntMap.end(); ++it)
{
if (it->second.id == oid)
{
cntMap.erase(it);
break;
}
}
}
}

// remove ACL_TABLE_STATS in crm database
m_countersCrmTable->del(getCrmAclTableKey(oid));
}
}
catch (...)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def test_CrmAcl(dvs, testlog):
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)

dvs.runcmd("crm config polling interval 1")
time.sleep(1)

bind_ports = ["Ethernet0", "Ethernet4"]

Expand Down Expand Up @@ -615,3 +616,7 @@ def test_CrmAcl(dvs, testlog):
table_used_counter = new_table_used_counter - old_table_used_counter
assert table_used_counter == 0

counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0)
crm_stats_table = swsscommon.Table(counters_db, 'CRM')
keys = crm_stats_table.getKeys()
assert key not in keys

0 comments on commit 80fcada

Please sign in to comment.