diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index a48abfe238ed..41f68dfc20e5 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -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 (...) diff --git a/tests/test_crm.py b/tests/test_crm.py index 7eb95b47e084..bd4db74c5f52 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -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"] @@ -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