Skip to content

Commit cf12bdf

Browse files
jipanyanglguohan
authored andcommitted
Remove AclTableGroup upon removal of port/lag/vlan (#751)
* Remove AclTableGroup upon removal of port/lag/vlan Signed-off-by: Jipan Yang <jipan.yang@alibaba-inc.com>
1 parent 5779c1a commit cf12bdf

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

orchagent/portsorch.cpp

+49-2
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
784784

785785
setPort(port.m_alias, port);
786786

787-
gCrmOrch->incCrmAclUsedCounter(CrmResourceType::CRM_ACL_GROUP, ingress ? SAI_ACL_STAGE_INGRESS : SAI_ACL_STAGE_EGRESS, SAI_ACL_BIND_POINT_TYPE_PORT);
787+
gCrmOrch->incCrmAclUsedCounter(CrmResourceType::CRM_ACL_GROUP, ingress ? SAI_ACL_STAGE_INGRESS : SAI_ACL_STAGE_EGRESS, bind_type);
788788

789789
switch (port.m_type)
790790
{
@@ -1264,7 +1264,7 @@ bool PortsOrch::removePort(sai_object_id_t port_id)
12641264
SWSS_LOG_ERROR("Failed to remove port %lx, rv:%d", port_id, status);
12651265
return false;
12661266
}
1267-
1267+
removeAclTableGroup(p);
12681268
SWSS_LOG_NOTICE("Remove port %lx", port_id);
12691269

12701270
return true;
@@ -2602,6 +2602,8 @@ bool PortsOrch::removeVlan(Port vlan)
26022602
return false;
26032603
}
26042604

2605+
removeAclTableGroup(vlan);
2606+
26052607
SWSS_LOG_NOTICE("Remove VLAN %s vid:%hu", vlan.m_alias.c_str(),
26062608
vlan.m_vlan_info.vlan_id);
26072609

@@ -2778,6 +2780,8 @@ bool PortsOrch::removeLag(Port lag)
27782780
return false;
27792781
}
27802782

2783+
removeAclTableGroup(lag);
2784+
27812785
SWSS_LOG_NOTICE("Remove LAG %s lid:%lx", lag.m_alias.c_str(), lag.m_lag_id);
27822786

27832787
m_portList.erase(lag.m_alias);
@@ -3178,3 +3182,46 @@ bool PortsOrch::getPortOperStatus(const Port& port, sai_port_oper_status_t& stat
31783182
return true;
31793183
}
31803184

3185+
bool PortsOrch::removeAclTableGroup(const Port &p)
3186+
{
3187+
sai_acl_bind_point_type_t bind_type;
3188+
switch (p.m_type)
3189+
{
3190+
case Port::PHY:
3191+
bind_type = SAI_ACL_BIND_POINT_TYPE_PORT;
3192+
break;
3193+
case Port::LAG:
3194+
bind_type = SAI_ACL_BIND_POINT_TYPE_LAG;
3195+
break;
3196+
case Port::VLAN:
3197+
bind_type = SAI_ACL_BIND_POINT_TYPE_VLAN;
3198+
break;
3199+
default:
3200+
// Dealing with port, lag and vlan for now.
3201+
return true;
3202+
}
3203+
sai_status_t ret;
3204+
if (p.m_ingress_acl_table_group_id != 0)
3205+
{
3206+
ret = sai_acl_api->remove_acl_table_group(p.m_ingress_acl_table_group_id);
3207+
if (ret != SAI_STATUS_SUCCESS)
3208+
{
3209+
SWSS_LOG_ERROR("Failed to remove ingress acl table group for %s", p.m_alias.c_str());
3210+
return false;
3211+
}
3212+
gCrmOrch->decCrmAclUsedCounter(CrmResourceType::CRM_ACL_GROUP, SAI_ACL_STAGE_INGRESS, bind_type, p.m_ingress_acl_table_group_id);
3213+
}
3214+
3215+
if (p.m_egress_acl_table_group_id != 0)
3216+
{
3217+
ret = sai_acl_api->remove_acl_table_group(p.m_egress_acl_table_group_id);
3218+
if (ret != SAI_STATUS_SUCCESS)
3219+
{
3220+
SWSS_LOG_ERROR("Failed to remove egress acl table group for %s", p.m_alias.c_str());
3221+
return false;
3222+
}
3223+
gCrmOrch->decCrmAclUsedCounter(CrmResourceType::CRM_ACL_GROUP, SAI_ACL_STAGE_EGRESS, bind_type, p.m_egress_acl_table_group_id);
3224+
}
3225+
return true;
3226+
}
3227+

orchagent/portsorch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class PortsOrch : public Orch, public Subject
8181
void generatePriorityGroupMap();
8282

8383
void refreshPortStatus();
84-
84+
bool removeAclTableGroup(const Port &p);
8585
private:
8686
unique_ptr<Table> m_counterTable;
8787
unique_ptr<Table> m_portTable;

tests/test_acl_portchannel.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,22 @@ def check_asic_table_absent(self, dvs):
127127
# Second create ACL table
128128
def test_PortChannelAfterAcl(self, dvs):
129129
self.setup_db(dvs)
130+
dvs.runcmd("crm config polling interval 1")
131+
time.sleep(2)
130132

133+
used_counter = dvs.getCrmCounterValue('ACL_STATS:INGRESS:LAG', 'crm_stats_acl_group_used')
131134
# create port channel
132135
self.create_port_channel(dvs, "PortChannel01")
133136

134137
# create ACL table
135138
self.create_acl_table(dvs, "LAG_ACL_TABLE", "PortChannel01")
136139

137-
time.sleep(1)
140+
time.sleep(2)
138141

142+
new_used_counter = dvs.getCrmCounterValue('ACL_STATS:INGRESS:LAG', 'crm_stats_acl_group_used')
143+
if used_counter is None:
144+
used_counter = 0
145+
assert new_used_counter - used_counter == 1
139146
# check ASIC table
140147
self.check_asic_table_existed(dvs)
141148

@@ -145,6 +152,14 @@ def test_PortChannelAfterAcl(self, dvs):
145152
# remove port channel
146153
self.remove_port_channel(dvs, "PortChannel01")
147154

155+
time.sleep(2)
156+
new_new_used_counter = dvs.getCrmCounterValue('ACL_STATS:INGRESS:LAG', 'crm_stats_acl_group_used')
157+
if new_new_used_counter is None:
158+
new_new_used_counter = 0
159+
assert new_used_counter - new_new_used_counter == 1
160+
# slow down crm polling
161+
dvs.runcmd("crm config polling interval 10000")
162+
148163
# Frist create ACL table
149164
# Second create port channel
150165
def test_PortChannelBeforeAcl(self, dvs):

0 commit comments

Comments
 (0)