Skip to content

Commit

Permalink
[acl] Refactor port OID retrieval into aclorch (sonic-net#1462)
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Allen <[email protected]>
  • Loading branch information
daall authored Oct 14, 2020
1 parent aebf566 commit dbafaad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
48 changes: 43 additions & 5 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,10 +1555,10 @@ void AclTable::update(SubjectType type, void *cntx)
}

PortUpdate *update = static_cast<PortUpdate *>(cntx);

Port &port = update->port;

sai_object_id_t bind_port_id;
if (!gPortsOrch->getAclBindPortId(port.m_alias, bind_port_id))
if (!AclOrch::getAclBindPortId(port, bind_port_id))
{
SWSS_LOG_ERROR("Failed to get port %s bind port ID",
port.m_alias.c_str());
Expand Down Expand Up @@ -2634,7 +2634,14 @@ bool AclOrch::updateAclTablePorts(AclTable &newTable, AclTable &curTable)
}
else if (curTable.portSet.find(p) != curTable.portSet.end())
{
gPortsOrch->getAclBindPortId(p, port_oid);
Port port;
if (!gPortsOrch->getPort(p, port))
{
SWSS_LOG_ERROR("Unable to retrieve OID for port %s", p.c_str());
continue;
}

getAclBindPortId(port, port_oid);
assert(port_oid != SAI_NULL_OBJECT_ID);
assert(curTable.ports.find(port_oid) != curTable.ports.end());
if (curTable.ports[port_oid] != SAI_NULL_OBJECT_ID)
Expand All @@ -2661,7 +2668,7 @@ bool AclOrch::updateAclTablePorts(AclTable &newTable, AclTable &curTable)
continue;
}

if (!gPortsOrch->getAclBindPortId(p, port_oid))
if (!getAclBindPortId(port, port_oid))
{
// We do NOT expect this to happen at all.
// If at all happens, lets catch it here!
Expand Down Expand Up @@ -3170,7 +3177,7 @@ bool AclOrch::processAclTablePorts(string portList, AclTable &aclTable)
}

sai_object_id_t bind_port_id;
if (!gPortsOrch->getAclBindPortId(alias, bind_port_id))
if (!getAclBindPortId(port, bind_port_id))
{
SWSS_LOG_ERROR("Failed to get port %s bind port ID for ACL table %s",
alias.c_str(), aclTable.id.c_str());
Expand Down Expand Up @@ -3566,3 +3573,34 @@ sai_status_t AclOrch::deleteDTelWatchListTables()

return SAI_STATUS_SUCCESS;
}

bool AclOrch::getAclBindPortId(Port &port, sai_object_id_t &port_id)
{
SWSS_LOG_ENTER();

switch (port.m_type)
{
case Port::PHY:
if (port.m_lag_member_id != SAI_NULL_OBJECT_ID)
{
SWSS_LOG_WARN("Invalid configuration. Bind table to LAG member %s is not allowed", port.m_alias.c_str());
return false;
}
else
{
port_id = port.m_port_id;
}
break;
case Port::LAG:
port_id = port.m_lag_id;
break;
case Port::VLAN:
port_id = port.m_vlan_info.vlan_oid;
break;
default:
SWSS_LOG_ERROR("Failed to process port. Incorrect port %s type %d", port.m_alias.c_str(), port.m_type);
return false;
}

return true;
}
3 changes: 3 additions & 0 deletions orchagent/aclorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ class AclOrch : public Orch, public Observer
map<acl_table_type_t, bool> m_mirrorTableCapabilities;

static sai_acl_action_type_t getAclActionFromAclEntry(sai_acl_entry_attr_t attr);

// Get the OID for the ACL bind point for a given port
static bool getAclBindPortId(Port& port, sai_object_id_t& port_id);

private:
SwitchOrch *m_switchOrch;
Expand Down
40 changes: 0 additions & 40 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,46 +609,6 @@ 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();

Port port;
if (getPort(alias, port))
{
switch (port.m_type)
{
case Port::PHY:
if (port.m_lag_member_id != SAI_NULL_OBJECT_ID)
{
SWSS_LOG_WARN("Invalid configuration. Bind table to LAG member %s is not allowed", alias.c_str());
return false;
}
else
{
port_id = port.m_port_id;
}
break;
case Port::LAG:
port_id = port.m_lag_id;
break;
case Port::VLAN:
port_id = port.m_vlan_info.vlan_oid;
break;
default:
SWSS_LOG_ERROR("Failed to process port. Incorrect port %s type %d", alias.c_str(), port.m_type);
return false;
}

return true;
}
else
{
return false;
}
}

bool PortsOrch::addSubPort(Port &port, const string &alias, const bool &adminUp, const uint32_t &mtu)
{
size_t found = alias.find(VLAN_SUB_INTERFACE_SEPARATOR);
Expand Down
1 change: 0 additions & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class PortsOrch : public Orch, public Subject
void setPort(string alias, Port port);
void getCpuPort(Port &port);
bool getVlanByVlanId(sai_vlan_id_t vlan_id, Port &vlan);
bool getAclBindPortId(string alias, sai_object_id_t &port_id);

bool setHostIntfsOperStatus(const Port& port, bool up) const;
void updateDbPortOperStatus(const Port& port, sai_port_oper_status_t status) const;
Expand Down

0 comments on commit dbafaad

Please sign in to comment.