From f36f7ce6236ae97526e15f00e7688ccced7c0454 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Mon, 10 Jan 2022 22:32:39 -0800 Subject: [PATCH] Added Support for enum query capability of Nexthop Group Type. (#989) What/Why I did: Added Support for enum query capability of Nexthop Group Type. This is needed for DVS testing of Ordered ECMP Feature. Design Doc: Azure/SONiC#896 --- unittest/vslib/TestSwitchBCM56850.cpp | 61 +++++++++++++++++++++++++++ vslib/SwitchStateBase.cpp | 25 +++++++++++ vslib/SwitchStateBase.h | 5 +++ 3 files changed, 91 insertions(+) diff --git a/unittest/vslib/TestSwitchBCM56850.cpp b/unittest/vslib/TestSwitchBCM56850.cpp index df4e3d17f16e..4f7313121722 100644 --- a/unittest/vslib/TestSwitchBCM56850.cpp +++ b/unittest/vslib/TestSwitchBCM56850.cpp @@ -418,3 +418,64 @@ TEST(SwitchBCM56850, test_vlan_flood_capability) EXPECT_EQ(flood_types_found, 3); } + +TEST(SwitchBCM56850, test_nexthop_group_type_enum_values_capability) +{ + auto sc = std::make_shared(0, ""); + auto signal = std::make_shared(); + auto eventQueue = std::make_shared(signal); + + sc->m_saiSwitchType = SAI_SWITCH_TYPE_NPU; + sc->m_switchType = SAI_VS_SWITCH_TYPE_BCM56850; + sc->m_bootType = SAI_VS_BOOT_TYPE_COLD; + sc->m_useTapDevice = false; + sc->m_laneMap = LaneMap::getDefaultLaneMap(0); + sc->m_eventQueue = eventQueue; + + auto scc = std::make_shared(); + + scc->insert(sc); + + SwitchBCM56850 sw( + 0x2100000000, + std::make_shared(0, scc), + sc); + + sai_s32_list_t enum_val_cap; + int32_t list[5]; + memset(list, 0, sizeof(list)); + + enum_val_cap.count = 4; + enum_val_cap.list = list; + + EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, + SAI_OBJECT_TYPE_NEXT_HOP_GROUP, + SAI_NEXT_HOP_GROUP_ATTR_TYPE, + &enum_val_cap), + SAI_STATUS_BUFFER_OVERFLOW); + enum_val_cap.count = 5; + EXPECT_EQ(sw.queryAttrEnumValuesCapability(0x2100000000, + SAI_OBJECT_TYPE_NEXT_HOP_GROUP, + SAI_NEXT_HOP_GROUP_ATTR_TYPE, + &enum_val_cap), + SAI_STATUS_SUCCESS); + + + EXPECT_EQ(enum_val_cap.count, 5); + + int nexthop_group_types_found = 0; + + for (uint32_t i = 0; i < enum_val_cap.count; i++) + { + if (enum_val_cap.list[i] == SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP || + enum_val_cap.list[i] == SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_ORDERED_ECMP || + enum_val_cap.list[i] == SAI_NEXT_HOP_GROUP_TYPE_FINE_GRAIN_ECMP || + enum_val_cap.list[i] == SAI_NEXT_HOP_GROUP_TYPE_PROTECTION || + enum_val_cap.list[i] == SAI_NEXT_HOP_GROUP_TYPE_CLASS_BASED) + { + nexthop_group_types_found++; + } + } + + EXPECT_EQ(nexthop_group_types_found, 5); +} diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 9fd3d449ede3..7f4c99e4d4a3 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -3384,6 +3384,27 @@ sai_status_t SwitchStateBase::queryVlanfloodTypeCapability( return SAI_STATUS_SUCCESS; } +sai_status_t SwitchStateBase::queryNextHopGroupTypeCapability( + _Inout_ sai_s32_list_t *enum_values_capability) +{ + SWSS_LOG_ENTER(); + + if (enum_values_capability->count < 5) + { + return SAI_STATUS_BUFFER_OVERFLOW; + } + + enum_values_capability->count = 5; + enum_values_capability->list[0] = SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP; + enum_values_capability->list[1] = SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_ORDERED_ECMP; + enum_values_capability->list[2] = SAI_NEXT_HOP_GROUP_TYPE_FINE_GRAIN_ECMP; + enum_values_capability->list[3] = SAI_NEXT_HOP_GROUP_TYPE_PROTECTION; + enum_values_capability->list[4] = SAI_NEXT_HOP_GROUP_TYPE_CLASS_BASED; + + return SAI_STATUS_SUCCESS; +} + + sai_status_t SwitchStateBase::queryAttrEnumValuesCapability( _In_ sai_object_id_t switch_id, _In_ sai_object_type_t object_type, @@ -3402,5 +3423,9 @@ sai_status_t SwitchStateBase::queryAttrEnumValuesCapability( { return queryVlanfloodTypeCapability(enum_values_capability); } + else if (object_type == SAI_OBJECT_TYPE_NEXT_HOP_GROUP && attr_id == SAI_NEXT_HOP_GROUP_ATTR_TYPE) + { + return queryNextHopGroupTypeCapability(enum_values_capability); + } return SAI_STATUS_NOT_SUPPORTED; } diff --git a/vslib/SwitchStateBase.h b/vslib/SwitchStateBase.h index 4ddca8fb3f6b..4ca0c234523f 100644 --- a/vslib/SwitchStateBase.h +++ b/vslib/SwitchStateBase.h @@ -650,6 +650,11 @@ namespace saivs virtual sai_status_t queryVlanfloodTypeCapability( _Inout_ sai_s32_list_t *enum_values_capability); + virtual sai_status_t queryNextHopGroupTypeCapability( + _Inout_ sai_s32_list_t *enum_values_capability); + + + public: // TODO private std::set m_fdb_info_set;