Skip to content

Commit

Permalink
Add failure handling for SAI get operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Shi Su committed Jun 2, 2021
1 parent 9bf83df commit 1471170
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 54 deletions.
22 changes: 17 additions & 5 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,11 @@ void AclOrch::init(vector<TableConnector>& connectors, PortsOrch *portOrch, Mirr
else
{
SWSS_LOG_ERROR("Failed to get ACL entry priority min/max values, rv:%d", status);
throw "AclOrch initialization failure";
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
throw "AclOrch initialization failure";
}
}

queryAclActionCapability();
Expand Down Expand Up @@ -2378,7 +2382,11 @@ void AclOrch::queryAclActionCapability()
SWSS_LOG_WARN("Failed to query ACL %s action capabilities - "
"API assumed to be not implemented, using defaults",
stage_str);
initDefaultAclActionCapabilities(stage);
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
initDefaultAclActionCapabilities(stage);
}
}

// put capabilities in state DB
Expand All @@ -2390,10 +2398,14 @@ void AclOrch::queryAclActionCapability()
SWSS_LOG_WARN("Failed to query maximum ACL action count - "
"API assumed to be not implemented, using defaults capabilities for both %s and %s",
STAGE_INGRESS, STAGE_EGRESS);
for (auto stage: {ACL_STAGE_INGRESS, ACL_STAGE_EGRESS})
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
initDefaultAclActionCapabilities(stage);
putAclActionCapabilityInDB(stage);
for (auto stage: {ACL_STAGE_INGRESS, ACL_STAGE_EGRESS})
{
initDefaultAclActionCapabilities(stage);
putAclActionCapabilityInDB(stage);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions orchagent/bufferorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ void BufferOrch::initBufferConstants()
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get Maximum memory size, rv:%d", status);
// This is not a mandatory attribute so in case of failure we just return
return;
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
// This is not a mandatory attribute so in case of failure we just return
return;
}
}

vector<FieldValueTuple> fvVector;
Expand Down
6 changes: 5 additions & 1 deletion orchagent/copporch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ void CoppOrch::initDefaultTrapGroup()
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get default trap group, rv:%d", status);
throw "CoppOrch initialization failure";
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
throw "CoppOrch initialization failure";
}
}

SWSS_LOG_INFO("Get default trap group");
Expand Down
18 changes: 15 additions & 3 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ void CrmOrch::getResAvailableCounters()
break;
}
SWSS_LOG_ERROR("Failed to get switch attribute %u , rv:%d", attr.id, status);
break;
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
break;
}
}

res.second.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = attr.value.u32;
Expand Down Expand Up @@ -503,7 +507,11 @@ void CrmOrch::getResAvailableCounters()
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get switch attribute %u , rv:%d", attr.id, status);
break;
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
break;
}
}

for (uint32_t i = 0; i < attr.value.aclresource.count; i++)
Expand All @@ -527,7 +535,11 @@ void CrmOrch::getResAvailableCounters()
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get ACL table attribute %u , rv:%d", attr.id, status);
break;
task_process_status handle_status = handleSaiGetStatus(SAI_API_ACL, status);
if (handle_status != task_process_status::task_success)
{
break;
}
}

cnt.second.availableCounter = attr.value.u32;
Expand Down
36 changes: 30 additions & 6 deletions orchagent/fabricportsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ int FabricPortsOrch::getFabricPortList()
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get fabric port number, rv:%d", status);
return FABRIC_PORT_ERROR;
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
return FABRIC_PORT_ERROR;
}
}
m_fabricPortCount = attr.value.u32;
SWSS_LOG_NOTICE("Get %d fabric ports", m_fabricPortCount);
Expand All @@ -101,7 +105,11 @@ int FabricPortsOrch::getFabricPortList()
status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
throw runtime_error("FabricPortsOrch get port list failure");
task_process_status handle_status = handleSaiGetStatus(SAI_API_SWITCH, status);
if (handle_status != task_process_status::task_success)
{
throw runtime_error("FabricPortsOrch get port list failure");
}
}

for (i = 0; i < m_fabricPortCount; i++)
Expand All @@ -113,7 +121,11 @@ int FabricPortsOrch::getFabricPortList()
status = sai_port_api->get_port_attribute(fabric_port_list[i], 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
throw runtime_error("FabricPortsOrch get port lane failure");
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
if (handle_status != task_process_status::task_success)
{
throw runtime_error("FabricPortsOrch get port lane failure");
}
}
int lane = attr.value.u32list.list[0];
m_fabricLanePortMap[lane] = fabric_port_list[i];
Expand Down Expand Up @@ -198,7 +210,11 @@ void FabricPortsOrch::updateFabricPortState()
{
// Port may not be ready for query
SWSS_LOG_ERROR("Failed to get fabric port (%d) status, rv:%d", lane, status);
return;
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
if (handle_status != task_process_status::task_success)
{
return;
}
}

if (m_portStatus.find(lane) != m_portStatus.end() &&
Expand All @@ -215,15 +231,23 @@ void FabricPortsOrch::updateFabricPortState()
status = sai_port_api->get_port_attribute(port, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
throw runtime_error("FabricPortsOrch get remote id failure");
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
if (handle_status != task_process_status::task_success)
{
throw runtime_error("FabricPortsOrch get remote id failure");
}
}
remote_peer = attr.value.u32;

attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED_PORT_INDEX;
status = sai_port_api->get_port_attribute(port, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
throw runtime_error("FabricPortsOrch get remote port index failure");
task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status);
if (handle_status != task_process_status::task_success)
{
throw runtime_error("FabricPortsOrch get remote port index failure");
}
}
remote_port = attr.value.u32;
}
Expand Down
6 changes: 5 additions & 1 deletion orchagent/fdborch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,11 @@ bool FdbOrch::getPort(const MacAddress& mac, uint16_t vlan, Port& port)
{
SWSS_LOG_ERROR("Failed to get bridge port ID for FDB entry %s, rv:%d",
mac.to_string().c_str(), status);
return false;
task_process_status handle_status = handleSaiGetStatus(SAI_API_FDB, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

if (!m_portsOrch->getPortByBridgePortId(attr.value.oid, port))
Expand Down
10 changes: 7 additions & 3 deletions orchagent/fgnhgorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,15 @@ bool FgNhgOrch::createFineGrainedNextHopGroup(FGNextHopGroupEntry &syncd_fg_rout
{
SWSS_LOG_ERROR("Failed to query next hop group %s SAI_NEXT_HOP_GROUP_ATTR_REAL_SIZE, rv:%d",
nextHops.to_string().c_str(), status);
if (!removeFineGrainedNextHopGroup(&syncd_fg_route_entry))
task_process_status handle_status = handleSaiGetStatus(SAI_API_NEXT_HOP_GROUP, status);
if (handle_status != task_process_status::task_success)
{
SWSS_LOG_ERROR("Failed to clean-up after next hop group real_size query failure");
if (!removeFineGrainedNextHopGroup(&syncd_fg_route_entry))
{
SWSS_LOG_ERROR("Failed to clean-up after next hop group real_size query failure");
}
return parseHandleSaiStatusFailure(handle_status);
}
return false;
}
fgNhgEntry->real_bucket_size = nhg_attr.value.u32;
}
Expand Down
15 changes: 10 additions & 5 deletions orchagent/macsecorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,15 +838,20 @@ bool MACsecOrch::initMACsecObject(sai_object_id_t switch_id)
attrs.clear();
attr.id = SAI_MACSEC_ATTR_SCI_IN_INGRESS_MACSEC_ACL;
attrs.push_back(attr);
if (sai_macsec_api->get_macsec_attribute(
macsec_obj.first->second.m_ingress_id,
static_cast<uint32_t>(attrs.size()),
attrs.data()) != SAI_STATUS_SUCCESS)
status = sai_macsec_api->get_macsec_attribute(
macsec_obj.first->second.m_ingress_id,
static_cast<uint32_t>(attrs.size()),
attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN(
"Cannot get MACsec attribution SAI_MACSEC_ATTR_SCI_IN_INGRESS_MACSEC_ACL at the switch 0x%" PRIx64,
switch_id);
return false;
task_process_status handle_status = handleSaiGetStatus(SAI_API_MACSEC, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
macsec_obj.first->second.m_sci_in_ingress_macsec_acl = attrs.front().value.booldata;

Expand Down
53 changes: 53 additions & 0 deletions orchagent/natorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ NatOrch::NatOrch(DBConnector *appDb, DBConnector *stateDb, vector<table_name_wit
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_NOTICE("Failed to get the SNAT available entry count, rv:%d", status);
handleSaiGetStatus(SAI_API_SWITCH, status);
}
else
{
Expand Down Expand Up @@ -3598,6 +3599,7 @@ bool NatOrch::getNatCounters(const NatEntry::iterator &iter)
{
SWSS_LOG_ERROR("Failed to get Counters for SNAT entry [src-ip %s], bytes = %" PRIu64 ", pkts = %" PRIu64 "", ipAddr.to_string().c_str(),
nat_entry_attr[0].value.u64, nat_entry_attr[1].value.u64);
handleSaiGetStatus(SAI_API_NAT, status);
}
else
{
Expand Down Expand Up @@ -3664,6 +3666,7 @@ bool NatOrch::getTwiceNatCounters(const TwiceNatEntry::iterator &iter)
SWSS_LOG_ERROR("Failed to get Counters for Twice NAT entry [src-ip %s, dst-ip %s], bytes = %" PRIu64 ", pkts = %" PRIu64 "",
key.src_ip.to_string().c_str(), key.dst_ip.to_string().c_str(),
nat_entry_attr[0].value.u64, nat_entry_attr[1].value.u64);
handleSaiGetStatus(SAI_API_NAT, status);
}
else
{
Expand Down Expand Up @@ -3817,6 +3820,7 @@ bool NatOrch::getNaptCounters(const NaptEntry::iterator &iter)
SWSS_LOG_ERROR("Failed to get Counters for SNAPT entry for [proto %s, src-ip %s, src-port %d], bytes = %" PRIu64 ", pkts = %" PRIu64 "",
naptKey.prototype.c_str(), naptKey.ip_address.to_string().c_str(), naptKey.l4_port,
nat_entry_attr[0].value.u64, nat_entry_attr[1].value.u64);
handleSaiGetStatus(SAI_API_NAT, status);
}
else
{
Expand Down Expand Up @@ -3893,6 +3897,7 @@ bool NatOrch::getTwiceNaptCounters(const TwiceNaptEntry::iterator &iter)
SWSS_LOG_DEBUG("Failed to get Counters for Twice NAPT entry for [proto %s, src ip %s, src port %d, dst ip %s, dst port %d], as not yet added to HW",
key.prototype.c_str(), key.src_ip.to_string().c_str(), key.src_l4_port, key.dst_ip.to_string().c_str(),
key.dst_l4_port);
handleSaiGetStatus(SAI_API_NAT, status);
}
else
{
Expand Down Expand Up @@ -4296,6 +4301,22 @@ bool NatOrch::checkIfNatEntryIsActive(const NatEntry::iterator &iter, time_t now
return 1;
}
}
else
{
task_process_status handle_status = handleSaiGetStatus(SAI_API_NAT, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
}
}
else
{
task_process_status handle_status = handleSaiGetStatus(SAI_API_NAT, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
return 0;
Expand Down Expand Up @@ -4410,6 +4431,22 @@ bool NatOrch::checkIfNaptEntryIsActive(const NaptEntry::iterator &iter, time_t n
return 1;
}
}
else
{
task_process_status handle_status = handleSaiGetStatus(SAI_API_NAT, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
}
}
else
{
task_process_status handle_status = handleSaiGetStatus(SAI_API_NAT, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
return 0;
Expand Down Expand Up @@ -4466,6 +4503,14 @@ bool NatOrch::checkIfTwiceNatEntryIsActive(const TwiceNatEntry::iterator &iter,
return 1;
}
}
else
{
task_process_status handle_status = handleSaiGetStatus(SAI_API_NAT, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
return 0;
}

Expand Down Expand Up @@ -4528,6 +4573,14 @@ bool NatOrch::checkIfTwiceNaptEntryIsActive(const TwiceNaptEntry::iterator &iter
return 1;
}
}
else
{
task_process_status handle_status = handleSaiGetStatus(SAI_API_NAT, status);
if (handle_status != task_process_status::task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}
return 0;
}

Expand Down
6 changes: 5 additions & 1 deletion orchagent/neighorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,11 @@ void NeighOrch::voqSyncAddNeigh(string &alias, IpAddress &ip_address, const MacA
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get neighbor attribute for %s on %s, rv:%d", ip_address.to_string().c_str(), alias.c_str(), status);
return;
task_process_status handle_status = handleSaiGetStatus(SAI_API_NEIGHBOR, status);
if (handle_status != task_process_status::task_success)
{
return;
}
}

if (!attr.value.u32)
Expand Down
Loading

0 comments on commit 1471170

Please sign in to comment.