Skip to content

Commit

Permalink
fix for CRM available bug (sonic-net#1699)
Browse files Browse the repository at this point in the history
Changes update switch statement in CrmOrch::getResAvailableCounters() to use CrmResourceType enum which guarantees the uniqueness of labels in the switch statement.
  • Loading branch information
qbdwlr authored Apr 9, 2021
1 parent 97f70d1 commit d8b8ca9
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,24 +442,24 @@ void CrmOrch::getResAvailableCounters()
continue;
}

sai_attribute_t attr;
attr.id = crmResSaiAvailAttrMap.at(res.first);

switch (attr.id)
switch (res.first)
{
case SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_IPMC_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_SNAT_ENTRY:
case SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY:
case CrmResourceType::CRM_IPV4_ROUTE:
case CrmResourceType::CRM_IPV6_ROUTE:
case CrmResourceType::CRM_IPV4_NEXTHOP:
case CrmResourceType::CRM_IPV6_NEXTHOP:
case CrmResourceType::CRM_IPV4_NEIGHBOR:
case CrmResourceType::CRM_IPV6_NEIGHBOR:
case CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER:
case CrmResourceType::CRM_NEXTHOP_GROUP:
case CrmResourceType::CRM_FDB_ENTRY:
case CrmResourceType::CRM_IPMC_ENTRY:
case CrmResourceType::CRM_SNAT_ENTRY:
case CrmResourceType::CRM_DNAT_ENTRY:
{
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)
{
Expand All @@ -482,9 +482,12 @@ void CrmOrch::getResAvailableCounters()
break;
}

case SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE:
case SAI_SWITCH_ATTR_AVAILABLE_ACL_TABLE_GROUP:
case CrmResourceType::CRM_ACL_TABLE:
case CrmResourceType::CRM_ACL_GROUP:
{
sai_attribute_t attr;
attr.id = crmResSaiAvailAttrMap.at(res.first);

vector<sai_acl_resource_t> resources(CRM_ACL_RESOURCE_COUNT);

attr.value.aclresource.count = CRM_ACL_RESOURCE_COUNT;
Expand Down Expand Up @@ -512,9 +515,12 @@ void CrmOrch::getResAvailableCounters()
break;
}

case SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_ENTRY:
case SAI_ACL_TABLE_ATTR_AVAILABLE_ACL_COUNTER:
case CrmResourceType::CRM_ACL_ENTRY:
case CrmResourceType::CRM_ACL_COUNTER:
{
sai_attribute_t attr;
attr.id = crmResSaiAvailAttrMap.at(res.first);

for (auto &cnt : res.second.countersMap)
{
sai_status_t status = sai_acl_api->get_acl_table_attribute(cnt.second.id, 1, &attr);
Expand All @@ -531,7 +537,7 @@ void CrmOrch::getResAvailableCounters()
}

default:
SWSS_LOG_ERROR("Failed to get CRM attribute %u. Unknown attribute.\n", attr.id);
SWSS_LOG_ERROR("Failed to get CRM resource type %u. Unknown resource type.\n", (uint32_t)res.first);
return;
}
}
Expand Down

0 comments on commit d8b8ca9

Please sign in to comment.