From a6d60f2ed0b0059be6014e2aba7b57f4dd7387a0 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Fri, 15 Feb 2019 00:48:59 -0800 Subject: [PATCH] Create egress ACL table group during the PFCWD stats list installment (#787) * Create egress table group during the PFCWD stats list installment Signed-off-by: Wenda * Introduce function bindAclTableGroup() to create and bind ACL table group to a port, which can be physical, vlan, or lag Signed-off-by: Wenda * Rename function to createBindAclTableGroup() Signed-off-by: Wenda Ni * Check the validity of ACL table oid Signed-off-by: Wenda Ni --- orchagent/pfcwdorch.cpp | 4 +++ orchagent/portsorch.cpp | 63 +++++++++++++++++++++++++++-------------- orchagent/portsorch.h | 1 + 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index 032b821b6060..e0283bfeee29 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -525,6 +525,10 @@ void PfcWdSwOrch::registerInWdDb(const Port& port, PfcWdOrch::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 diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index e479092b8011..aa98ea3fc345 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -706,19 +706,16 @@ 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)) { @@ -726,15 +723,16 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_ 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; @@ -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); @@ -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); @@ -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; @@ -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; @@ -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; @@ -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 member_attrs; @@ -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; } diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index fd2d7636363c..cee20eeb1f4e 100644 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -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);