From 828cccfe0eac4d7684c907a4460a2a70db5a9a93 Mon Sep 17 00:00:00 2001 From: Volodymyr Samotiy Date: Tue, 1 Mar 2022 02:49:32 +0200 Subject: [PATCH] [crm] Use sai_object_type_get_availability() API to get counters (#2098) *Aligned supported CRM resources with the newest way to get counters using sai_object_type_get_availability() API. Signed-off-by: Volodymyr Samotiy --- orchagent/crmorch.cpp | 249 +++++++++++++++++++----------------------- orchagent/crmorch.h | 1 + 2 files changed, 111 insertions(+), 139 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 7895bc38a4cd..a7e897f822ff 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -66,6 +66,26 @@ const map 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 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 }, @@ -73,6 +93,22 @@ const map crmResSaiAvailAttrMap = { CrmResourceType::CRM_NEXTHOP_GROUP_MAP, SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MAP }, }; +const map 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 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 crmThreshTypeResMap = { { "ipv4_route_threshold_type", CrmResourceType::CRM_IPV4_ROUTE }, @@ -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(availCount); + + return true; +} + void CrmOrch::getResAvailableCounters() { SWSS_LOG_ENTER(); @@ -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; } @@ -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(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(availCount); - - break; - } - - case CrmResourceType::CRM_MPLS_NEXTHOP: - { - sai_object_type_t objType = static_cast(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(availCount); - - break; - } - - case CrmResourceType::CRM_SRV6_MY_SID_ENTRY: - { - sai_object_type_t objType = static_cast(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(availCount); - - break; - } - - case CrmResourceType::CRM_SRV6_NEXTHOP: - { - sai_object_type_t objType = static_cast(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(availCount); - - break; - } - default: SWSS_LOG_ERROR("Failed to get CRM resource type %u. Unknown resource type.\n", static_cast(res.first)); return; diff --git a/orchagent/crmorch.h b/orchagent/crmorch.h index 345caa2cf6b0..f63e2a31c26d 100644 --- a/orchagent/crmorch.h +++ b/orchagent/crmorch.h @@ -98,6 +98,7 @@ class CrmOrch : public Orch void doTask(Consumer &consumer); void handleSetCommand(const std::string& key, const std::vector& data); void doTask(swss::SelectableTimer &timer); + bool getResAvailability(CrmResourceType type, CrmResourceEntry &res); void getResAvailableCounters(); void updateCrmCountersTable(); void checkCrmThresholds();