Skip to content

Commit

Permalink
[portsorch]: Remove duplicate local variables - port (sonic-net#690)
Browse files Browse the repository at this point in the history
Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng authored and lguohan committed Nov 19, 2018
1 parent 28dc042 commit 63d8ebc
Showing 1 changed file with 61 additions and 59 deletions.
120 changes: 61 additions & 59 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ bool PortsOrch::getPortByBridgePortId(sai_object_id_t bridge_port_id, Port &port
return false;
}

// TODO: move this into AclOrch
bool PortsOrch::getAclBindPortId(string alias, sai_object_id_t &port_id)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -651,21 +652,20 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_

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 ACL table %lx", table_oid);
return false;
}

sai_status_t status;
sai_object_id_t groupOid;

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

auto &port = m_portList.find(p.m_alias)->second;

if (acl_stage == ACL_STAGE_INGRESS && port.m_ingress_acl_table_group_id != 0)
{
groupOid = port.m_ingress_acl_table_group_id;
Expand All @@ -674,19 +674,14 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
{
groupOid = port.m_egress_acl_table_group_id;
}
// If 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;
// If port ACL table group does not exist, create one

Port p;
if (!getPort(id, p))
{
return false;
}

sai_acl_bind_point_type_t bind_type;
switch (p.m_type) {
switch (port.m_type)
{
case Port::PHY:
bind_type = SAI_ACL_BIND_POINT_TYPE_PORT;
break;
Expand All @@ -697,7 +692,8 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
bind_type = SAI_ACL_BIND_POINT_TYPE_VLAN;
break;
default:
SWSS_LOG_ERROR("Failed to bind ACL table to port %s with unknown type %d", p.m_alias.c_str(), p.m_type);
SWSS_LOG_ERROR("Failed to bind ACL table to port %s with unknown type %d",
port.m_alias.c_str(), port.m_type);
return false;
}

Expand Down Expand Up @@ -735,60 +731,65 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
port.m_egress_acl_table_group_id = groupOid;
}

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);

switch (port.m_type)
{
case Port::PHY:
{
// 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;

status = sai_port_api->set_port_attribute(port.m_port_id, &port_attr);
if (status != SAI_STATUS_SUCCESS)
case Port::PHY:
{
SWSS_LOG_ERROR("Failed to bind port %s to ACL table group %lx, rv:%d",
port.m_alias.c_str(), groupOid, status);
return status;
}
break;
}
case Port::LAG:
{
// 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;
// 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;

status = sai_lag_api->set_lag_attribute(port.m_lag_id, &lag_attr);
if (status != SAI_STATUS_SUCCESS)
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);
return status;
}
break;
}
case Port::LAG:
{
SWSS_LOG_ERROR("Failed to bind LAG %s to ACL table group %lx, rv:%d",
port.m_alias.c_str(), groupOid, status);
return status;
// 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;

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);
return status;
}
break;
}
break;
}
case Port::VLAN:
// 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;
case Port::VLAN:
{
// 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;

status = sai_vlan_api->set_vlan_attribute(port.m_vlan_info.vlan_oid, &vlan_attr);
if (status != SAI_STATUS_SUCCESS)
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);
return status;
}
break;
}
default:
{
SWSS_LOG_ERROR("Failed to bind VLAN %s to ACL table group %lx, rv:%d",
port.m_alias.c_str(), groupOid, status);
return status;
SWSS_LOG_ERROR("Failed to bind %s port with type %d", port.m_alias.c_str(), port.m_type);
return SAI_STATUS_FAILURE;
}

break;
default:
SWSS_LOG_ERROR("Failed to bind %s port with type %d", port.m_alias.c_str(), port.m_type);
return SAI_STATUS_FAILURE;
}

SWSS_LOG_NOTICE("Create ACL table group and bind port %s to it", port.m_alias.c_str());
Expand All @@ -811,7 +812,8 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_
member_attrs.push_back(member_attr);

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) {
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);
return false;
Expand Down Expand Up @@ -2994,4 +2996,4 @@ void PortsOrch::refreshPortStatus()
updatePortOperStatus(p, status);
}
}
}
}

0 comments on commit 63d8ebc

Please sign in to comment.