Skip to content

Commit

Permalink
[crm] Use sai_object_type_get_availability() API to get counters (son…
Browse files Browse the repository at this point in the history
…ic-net#2098)

*Aligned supported CRM resources with the newest way to get counters using sai_object_type_get_availability() API.
Signed-off-by: Volodymyr Samotiy <[email protected]>
  • Loading branch information
volodymyrsamotiy authored and preetham-singh committed Aug 6, 2022
1 parent 3eead24 commit 5b9df1c
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 139 deletions.
249 changes: 110 additions & 139 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,49 @@ const map<CrmResourceType, uint32_t> crmResSaiAvailAttrMap =
{ CrmResourceType::CRM_IPMC_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_IPMC_ENTRY},
{ CrmResourceType::CRM_SNAT_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY },
{ CrmResourceType::CRM_DNAT_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY },
};

const map<CrmResourceType, sai_object_type_t> crmResSaiObjAttrMap =
{
{ CrmResourceType::CRM_IPV4_ROUTE, SAI_OBJECT_TYPE_ROUTE_ENTRY },
{ CrmResourceType::CRM_IPV6_ROUTE, SAI_OBJECT_TYPE_ROUTE_ENTRY },
{ CrmResourceType::CRM_IPV4_NEXTHOP, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_IPV6_NEXTHOP, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_IPV4_NEIGHBOR, SAI_OBJECT_TYPE_NEIGHBOR_ENTRY },
{ CrmResourceType::CRM_IPV6_NEIGHBOR, SAI_OBJECT_TYPE_NEIGHBOR_ENTRY },
{ CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_NEXTHOP_GROUP, SAI_OBJECT_TYPE_NEXT_HOP_GROUP },
{ CrmResourceType::CRM_ACL_TABLE, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_ACL_GROUP, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_ACL_ENTRY, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_ACL_COUNTER, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_FDB_ENTRY, SAI_OBJECT_TYPE_FDB_ENTRY },
{ CrmResourceType::CRM_IPMC_ENTRY, SAI_OBJECT_TYPE_NULL},
{ CrmResourceType::CRM_SNAT_ENTRY, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_DNAT_ENTRY, SAI_OBJECT_TYPE_NULL },
{ CrmResourceType::CRM_MPLS_INSEG, SAI_OBJECT_TYPE_INSEG_ENTRY },
{ CrmResourceType::CRM_MPLS_NEXTHOP, SAI_OBJECT_TYPE_NEXT_HOP },
{ CrmResourceType::CRM_SRV6_MY_SID_ENTRY, SAI_OBJECT_TYPE_MY_SID_ENTRY },
{ CrmResourceType::CRM_SRV6_NEXTHOP, SAI_OBJECT_TYPE_NEXT_HOP },
{ CrmResourceType::CRM_NEXTHOP_GROUP_MAP, SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MAP },
};

const map<CrmResourceType, sai_attr_id_t> crmResAddrFamilyAttrMap =
{
{ CrmResourceType::CRM_IPV4_ROUTE, SAI_ROUTE_ENTRY_ATTR_IP_ADDR_FAMILY },
{ CrmResourceType::CRM_IPV6_ROUTE, SAI_ROUTE_ENTRY_ATTR_IP_ADDR_FAMILY },
{ CrmResourceType::CRM_IPV4_NEIGHBOR, SAI_NEIGHBOR_ENTRY_ATTR_IP_ADDR_FAMILY },
{ CrmResourceType::CRM_IPV6_NEIGHBOR, SAI_NEIGHBOR_ENTRY_ATTR_IP_ADDR_FAMILY },
};

const map<CrmResourceType, sai_ip_addr_family_t> crmResAddrFamilyValMap =
{
{ CrmResourceType::CRM_IPV4_ROUTE, SAI_IP_ADDR_FAMILY_IPV4 },
{ CrmResourceType::CRM_IPV6_ROUTE, SAI_IP_ADDR_FAMILY_IPV6 },
{ CrmResourceType::CRM_IPV4_NEIGHBOR, SAI_IP_ADDR_FAMILY_IPV4 },
{ CrmResourceType::CRM_IPV6_NEIGHBOR, SAI_IP_ADDR_FAMILY_IPV6 },
};

const map<string, CrmResourceType> crmThreshTypeResMap =
{
{ "ipv4_route_threshold_type", CrmResourceType::CRM_IPV4_ROUTE },
Expand Down Expand Up @@ -464,6 +500,74 @@ void CrmOrch::doTask(SelectableTimer &timer)
checkCrmThresholds();
}

bool CrmOrch::getResAvailability(CrmResourceType type, CrmResourceEntry &res)
{
sai_attribute_t attr;
uint64_t availCount = 0;
sai_status_t status = SAI_STATUS_SUCCESS;

sai_object_type_t objType = crmResSaiObjAttrMap.at(type);

if (objType != SAI_OBJECT_TYPE_NULL)
{
uint32_t attrCount = 0;

if ((type == CrmResourceType::CRM_IPV4_ROUTE) || (type == CrmResourceType::CRM_IPV6_ROUTE) ||
(type == CrmResourceType::CRM_IPV4_NEIGHBOR) || (type == CrmResourceType::CRM_IPV6_NEIGHBOR))
{
attr.id = crmResAddrFamilyAttrMap.at(type);
attr.value.s32 = crmResAddrFamilyValMap.at(type);
attrCount = 1;
}
else if (type == CrmResourceType::CRM_MPLS_NEXTHOP)
{
attr.id = SAI_NEXT_HOP_ATTR_TYPE;
attr.value.s32 = SAI_NEXT_HOP_TYPE_MPLS;
attrCount = 1;
}
else if (type == CrmResourceType::CRM_SRV6_NEXTHOP)
{
attr.id = SAI_NEXT_HOP_ATTR_TYPE;
attr.value.s32 = SAI_NEXT_HOP_TYPE_SRV6_SIDLIST;
attrCount = 1;
}

status = sai_object_type_get_availability(gSwitchId, objType, attrCount, &attr, &availCount);
}

if ((status != SAI_STATUS_SUCCESS) || (objType == SAI_OBJECT_TYPE_NULL))
{
if (crmResSaiAvailAttrMap.find(type) != crmResSaiAvailAttrMap.end())
{
attr.id = crmResSaiAvailAttrMap.at(type);
status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr);
}

if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("CRM resource %s not supported", crmResTypeNameMap.at(type).c_str());
return false;
}

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to get availability counter for %s CRM resourse", crmResTypeNameMap.at(type).c_str());
return false;
}

availCount = attr.value.u32;
}

res.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = static_cast<uint32_t>(availCount);

return true;
}

void CrmOrch::getResAvailableCounters()
{
SWSS_LOG_ENTER();
Expand All @@ -490,33 +594,13 @@ void CrmOrch::getResAvailableCounters()
case CrmResourceType::CRM_IPMC_ENTRY:
case CrmResourceType::CRM_SNAT_ENTRY:
case CrmResourceType::CRM_DNAT_ENTRY:
case CrmResourceType::CRM_MPLS_INSEG:
case CrmResourceType::CRM_NEXTHOP_GROUP_MAP:
case CrmResourceType::CRM_SRV6_MY_SID_ENTRY:
case CrmResourceType::CRM_MPLS_NEXTHOP:
case CrmResourceType::CRM_SRV6_NEXTHOP:
{
sai_attribute_t attr;
attr.id = crmResSaiAvailAttrMap.at(res.first);

sai_status_t status = sai_switch_api->get_switch_attribute(gSwitchId, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("Switch attribute %u not supported", attr.id);
break;
}
SWSS_LOG_ERROR("Failed to get switch attribute %u , rv:%d", attr.id, status);
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;

getResAvailability(res.first, res.second);
break;
}

Expand Down Expand Up @@ -578,119 +662,6 @@ void CrmOrch::getResAvailableCounters()
break;
}

case CrmResourceType::CRM_MPLS_INSEG:
case CrmResourceType::CRM_NEXTHOP_GROUP_MAP:
{
sai_object_type_t objType = static_cast<sai_object_type_t>(crmResSaiAvailAttrMap.at(res.first));
uint64_t availCount = 0;
sai_status_t status = sai_object_type_get_availability(gSwitchId, objType, 0, nullptr, &availCount);
if (status != SAI_STATUS_SUCCESS)
{
if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("CRM Resource %s not supported", crmResTypeNameMap.at(res.first).c_str());
break;
}
SWSS_LOG_ERROR("Failed to get availability for object_type %u , rv:%d", objType, status);
break;
}

res.second.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = static_cast<uint32_t>(availCount);

break;
}

case CrmResourceType::CRM_MPLS_NEXTHOP:
{
sai_object_type_t objType = static_cast<sai_object_type_t>(crmResSaiAvailAttrMap.at(res.first));
sai_attribute_t attr;
uint64_t availCount = 0;

attr.id = SAI_NEXT_HOP_ATTR_TYPE;
attr.value.s32 = SAI_NEXT_HOP_TYPE_MPLS;
sai_status_t status = sai_object_type_get_availability(gSwitchId, objType, 1, &attr, &availCount);
if (status != SAI_STATUS_SUCCESS)
{
if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("CRM Resource %s not supported", crmResTypeNameMap.at(res.first).c_str());
break;
}
SWSS_LOG_ERROR("Failed to get availability for object_type %u , rv:%d", objType, status);
break;
}

res.second.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = static_cast<uint32_t>(availCount);

break;
}

case CrmResourceType::CRM_SRV6_MY_SID_ENTRY:
{
sai_object_type_t objType = static_cast<sai_object_type_t>(crmResSaiAvailAttrMap.at(res.first));
uint64_t availCount = 0;
sai_status_t status = sai_object_type_get_availability(gSwitchId, objType, 0, nullptr, &availCount);
if (status != SAI_STATUS_SUCCESS)
{
if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("CRM Resource %s not supported", crmResTypeNameMap.at(res.first).c_str());
break;
}
SWSS_LOG_ERROR("Failed to get availability for object_type %u , rv:%d", objType, status);
break;
}

res.second.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = static_cast<uint32_t>(availCount);

break;
}

case CrmResourceType::CRM_SRV6_NEXTHOP:
{
sai_object_type_t objType = static_cast<sai_object_type_t>(crmResSaiAvailAttrMap.at(res.first));
sai_attribute_t attr;
uint64_t availCount = 0;

attr.id = SAI_NEXT_HOP_ATTR_TYPE;
attr.value.s32 = SAI_NEXT_HOP_TYPE_SRV6_SIDLIST;
sai_status_t status = sai_object_type_get_availability(gSwitchId, objType, 1, &attr, &availCount);
if (status != SAI_STATUS_SUCCESS)
{
if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("CRM Resource %s not supported", crmResTypeNameMap.at(res.first).c_str());
break;
}
SWSS_LOG_ERROR("Failed to get availability for object_type %u , rv:%d", objType, status);
break;
}

res.second.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = static_cast<uint32_t>(availCount);

break;
}

default:
SWSS_LOG_ERROR("Failed to get CRM resource type %u. Unknown resource type.\n", static_cast<uint32_t>(res.first));
return;
Expand Down
1 change: 1 addition & 0 deletions orchagent/crmorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class CrmOrch : public Orch
void doTask(Consumer &consumer);
void handleSetCommand(const std::string& key, const std::vector<swss::FieldValueTuple>& data);
void doTask(swss::SelectableTimer &timer);
bool getResAvailability(CrmResourceType type, CrmResourceEntry &res);
void getResAvailableCounters();
void updateCrmCountersTable();
void checkCrmThresholds();
Expand Down

0 comments on commit 5b9df1c

Please sign in to comment.