Skip to content

Commit

Permalink
Create egress ACL table group during the PFCWD stats list installment (
Browse files Browse the repository at this point in the history
…#787)

* Create egress table group during the PFCWD stats list installment

Signed-off-by: Wenda <[email protected]>

* Introduce function bindAclTableGroup() to create and bind ACL table
group to a port, which can be physical, vlan, or lag

Signed-off-by: Wenda <[email protected]>

* Rename function to createBindAclTableGroup()

Signed-off-by: Wenda Ni <[email protected]>

* Check the validity of ACL table oid

Signed-off-by: Wenda Ni <[email protected]>
  • Loading branch information
wendani authored and lguohan committed Feb 15, 2019
1 parent 52de963 commit a6d60f2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
4 changes: 4 additions & 0 deletions orchagent/pfcwdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ void PfcWdSwOrch<DropHandler, ForwardHandler>::registerInWdDb(const Port& port,
PfcWdOrch<DropHandler, ForwardHandler>::getCountersTable(),
sai_serialize_object_id(queueId));
}

// Create egress ACL table group for each port of pfcwd's interest
sai_object_id_t groupId;
gPortsOrch->createBindAclTableGroup(port.m_port_id, groupId, ACL_STAGE_EGRESS);
}

template <typename DropHandler, typename ForwardHandler>
Expand Down
63 changes: 42 additions & 21 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,35 +706,33 @@ bool PortsOrch::setPortPfcAsym(Port &port, string pfc_asym)
return true;
}

bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_object_id_t &group_member_oid, acl_stage_type_t acl_stage)
bool PortsOrch::createBindAclTableGroup(sai_object_id_t id, sai_object_id_t &group_oid, acl_stage_type_t acl_stage)
{
SWSS_LOG_ENTER();

if (acl_stage == ACL_STAGE_UNKNOWN)
{
SWSS_LOG_ERROR("Unknown ACL stage for ACL table %lx", table_oid);
SWSS_LOG_ERROR("unknown ACL stage for table group creation");
return false;
}

sai_status_t status;
sai_object_id_t groupOid;

Port port;
if (!getPort(id, port))
{
SWSS_LOG_ERROR("Failed to get port by port ID %lx", id);
return false;
}

if (acl_stage == ACL_STAGE_INGRESS && port.m_ingress_acl_table_group_id != 0)
sai_status_t status;
if ((acl_stage == ACL_STAGE_INGRESS) && (port.m_ingress_acl_table_group_id != 0))
{
groupOid = port.m_ingress_acl_table_group_id;
group_oid = port.m_ingress_acl_table_group_id;
}
else if (acl_stage == ACL_STAGE_EGRESS && port.m_egress_acl_table_group_id != 0)
else if ((acl_stage == ACL_STAGE_EGRESS) && (port.m_egress_acl_table_group_id != 0))
{
groupOid = port.m_egress_acl_table_group_id;
group_oid = port.m_egress_acl_table_group_id;
}
// If port ACL table group does not exist, create one
// Port ACL table group does not exist, create one
else if (acl_stage == ACL_STAGE_INGRESS or acl_stage == ACL_STAGE_EGRESS)
{
bool ingress = acl_stage == ACL_STAGE_INGRESS ? true : false;
Expand Down Expand Up @@ -775,7 +773,7 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
group_attr.value.s32 = SAI_ACL_TABLE_GROUP_TYPE_PARALLEL;
group_attrs.push_back(group_attr);

status = sai_acl_api->create_acl_table_group(&groupOid, gSwitchId, (uint32_t)group_attrs.size(), group_attrs.data());
status = sai_acl_api->create_acl_table_group(&group_oid, gSwitchId, (uint32_t)group_attrs.size(), group_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create ACL table group, rv:%d", status);
Expand All @@ -784,11 +782,11 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_

if (ingress)
{
port.m_ingress_acl_table_group_id = groupOid;
port.m_ingress_acl_table_group_id = group_oid;
}
else
{
port.m_egress_acl_table_group_id = groupOid;
port.m_egress_acl_table_group_id = group_oid;
}

setPort(port.m_alias, port);
Expand All @@ -802,13 +800,13 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
// Bind this ACL group to physical port
sai_attribute_t port_attr;
port_attr.id = ingress ? SAI_PORT_ATTR_INGRESS_ACL : SAI_PORT_ATTR_EGRESS_ACL;
port_attr.value.oid = groupOid;
port_attr.value.oid = group_oid;

status = sai_port_api->set_port_attribute(port.m_port_id, &port_attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to bind port %s to ACL table group %lx, rv:%d",
port.m_alias.c_str(), groupOid, status);
port.m_alias.c_str(), group_oid, status);
return status;
}
break;
Expand All @@ -818,13 +816,13 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
// Bind this ACL group to LAG
sai_attribute_t lag_attr;
lag_attr.id = ingress ? SAI_LAG_ATTR_INGRESS_ACL : SAI_LAG_ATTR_EGRESS_ACL;
lag_attr.value.oid = groupOid;
lag_attr.value.oid = group_oid;

status = sai_lag_api->set_lag_attribute(port.m_lag_id, &lag_attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to bind LAG %s to ACL table group %lx, rv:%d",
port.m_alias.c_str(), groupOid, status);
port.m_alias.c_str(), group_oid, status);
return status;
}
break;
Expand All @@ -834,13 +832,13 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
// Bind this ACL group to VLAN
sai_attribute_t vlan_attr;
vlan_attr.id = ingress ? SAI_VLAN_ATTR_INGRESS_ACL : SAI_VLAN_ATTR_EGRESS_ACL;
vlan_attr.value.oid = groupOid;
vlan_attr.value.oid = group_oid;

status = sai_vlan_api->set_vlan_attribute(port.m_vlan_info.vlan_oid, &vlan_attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to bind VLAN %s to ACL table group %lx, rv:%d",
port.m_alias.c_str(), groupOid, status);
port.m_alias.c_str(), group_oid, status);
return status;
}
break;
Expand All @@ -855,6 +853,29 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
SWSS_LOG_NOTICE("Create ACL table group and bind port %s to it", port.m_alias.c_str());
}

return true;
}

bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_object_id_t &group_member_oid, acl_stage_type_t acl_stage)
{
SWSS_LOG_ENTER();

if (table_oid == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_ERROR("Invalid ACL table %lx", table_oid);
return false;
}

sai_status_t status;
sai_object_id_t groupOid;

// Create an ACL table group and bind to port
if (!createBindAclTableGroup(id, groupOid, acl_stage))
{
SWSS_LOG_ERROR("Fail to create or bind to port %lx ACL table group", id);
return false;
}

// Create an ACL group member with table_oid and groupOid
vector<sai_attribute_t> member_attrs;

Expand All @@ -874,8 +895,8 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
status = sai_acl_api->create_acl_table_group_member(&group_member_oid, gSwitchId, (uint32_t)member_attrs.size(), member_attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create member in ACL table group %lx for ACL table group %lx, rv:%d",
table_oid, groupOid, status);
SWSS_LOG_ERROR("Failed to create member in ACL table group %lx for ACL table %lx, rv:%d",
groupOid, table_oid, status);
return false;
}

Expand Down
1 change: 1 addition & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class PortsOrch : public Orch, public Subject

bool setHostIntfsOperStatus(const Port& port, bool up) const;
void updateDbPortOperStatus(const Port& port, sai_port_oper_status_t status) const;
bool createBindAclTableGroup(sai_object_id_t id, sai_object_id_t &group_oid, acl_stage_type_t acl_stage = ACL_STAGE_EGRESS);
bool bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_object_id_t &group_member_oid, acl_stage_type_t acl_stage = ACL_STAGE_INGRESS);

bool getPortPfc(sai_object_id_t portId, uint8_t *pfc_bitmask);
Expand Down

0 comments on commit a6d60f2

Please sign in to comment.