Skip to content

Commit

Permalink
Remove AclTableGroup upon removal of port/lag/vlan (sonic-net#751)
Browse files Browse the repository at this point in the history
* Remove AclTableGroup upon removal of port/lag/vlan

Signed-off-by: Jipan Yang <[email protected]>
  • Loading branch information
jipanyang authored and lguohan committed Jan 30, 2019
1 parent 5779c1a commit cf12bdf
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
51 changes: 49 additions & 2 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_

setPort(port.m_alias, port);

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

switch (port.m_type)
{
Expand Down Expand Up @@ -1264,7 +1264,7 @@ bool PortsOrch::removePort(sai_object_id_t port_id)
SWSS_LOG_ERROR("Failed to remove port %lx, rv:%d", port_id, status);
return false;
}

removeAclTableGroup(p);
SWSS_LOG_NOTICE("Remove port %lx", port_id);

return true;
Expand Down Expand Up @@ -2602,6 +2602,8 @@ bool PortsOrch::removeVlan(Port vlan)
return false;
}

removeAclTableGroup(vlan);

SWSS_LOG_NOTICE("Remove VLAN %s vid:%hu", vlan.m_alias.c_str(),
vlan.m_vlan_info.vlan_id);

Expand Down Expand Up @@ -2778,6 +2780,8 @@ bool PortsOrch::removeLag(Port lag)
return false;
}

removeAclTableGroup(lag);

SWSS_LOG_NOTICE("Remove LAG %s lid:%lx", lag.m_alias.c_str(), lag.m_lag_id);

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

bool PortsOrch::removeAclTableGroup(const Port &p)
{
sai_acl_bind_point_type_t bind_type;
switch (p.m_type)
{
case Port::PHY:
bind_type = SAI_ACL_BIND_POINT_TYPE_PORT;
break;
case Port::LAG:
bind_type = SAI_ACL_BIND_POINT_TYPE_LAG;
break;
case Port::VLAN:
bind_type = SAI_ACL_BIND_POINT_TYPE_VLAN;
break;
default:
// Dealing with port, lag and vlan for now.
return true;
}
sai_status_t ret;
if (p.m_ingress_acl_table_group_id != 0)
{
ret = sai_acl_api->remove_acl_table_group(p.m_ingress_acl_table_group_id);
if (ret != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove ingress acl table group for %s", p.m_alias.c_str());
return false;
}
gCrmOrch->decCrmAclUsedCounter(CrmResourceType::CRM_ACL_GROUP, SAI_ACL_STAGE_INGRESS, bind_type, p.m_ingress_acl_table_group_id);
}

if (p.m_egress_acl_table_group_id != 0)
{
ret = sai_acl_api->remove_acl_table_group(p.m_egress_acl_table_group_id);
if (ret != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to remove egress acl table group for %s", p.m_alias.c_str());
return false;
}
gCrmOrch->decCrmAclUsedCounter(CrmResourceType::CRM_ACL_GROUP, SAI_ACL_STAGE_EGRESS, bind_type, p.m_egress_acl_table_group_id);
}
return true;
}

2 changes: 1 addition & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PortsOrch : public Orch, public Subject
void generatePriorityGroupMap();

void refreshPortStatus();

bool removeAclTableGroup(const Port &p);
private:
unique_ptr<Table> m_counterTable;
unique_ptr<Table> m_portTable;
Expand Down
17 changes: 16 additions & 1 deletion tests/test_acl_portchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,22 @@ def check_asic_table_absent(self, dvs):
# Second create ACL table
def test_PortChannelAfterAcl(self, dvs):
self.setup_db(dvs)
dvs.runcmd("crm config polling interval 1")
time.sleep(2)

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

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

time.sleep(1)
time.sleep(2)

new_used_counter = dvs.getCrmCounterValue('ACL_STATS:INGRESS:LAG', 'crm_stats_acl_group_used')
if used_counter is None:
used_counter = 0
assert new_used_counter - used_counter == 1
# check ASIC table
self.check_asic_table_existed(dvs)

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

time.sleep(2)
new_new_used_counter = dvs.getCrmCounterValue('ACL_STATS:INGRESS:LAG', 'crm_stats_acl_group_used')
if new_new_used_counter is None:
new_new_used_counter = 0
assert new_used_counter - new_new_used_counter == 1
# slow down crm polling
dvs.runcmd("crm config polling interval 10000")

# Frist create ACL table
# Second create port channel
def test_PortChannelBeforeAcl(self, dvs):
Expand Down

0 comments on commit cf12bdf

Please sign in to comment.