From 12410d9c173d771af29bf0cfb9f54fe3179966d0 Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Mon, 9 Oct 2023 17:00:02 +0300 Subject: [PATCH] [hash]: Extend VS lib with ECMP/LAG hash algorithm. Signed-off-by: Nazarii Hnydyn --- unittest/vslib/TestSwitchStateBase.cpp | 36 ++++++++++++++++++++++++++ vslib/SwitchStateBase.cpp | 28 ++++++++++++++++++++ vslib/SwitchStateBase.h | 3 +++ 3 files changed, 67 insertions(+) diff --git a/unittest/vslib/TestSwitchStateBase.cpp b/unittest/vslib/TestSwitchStateBase.cpp index bb5ac18b6..7772f6731 100644 --- a/unittest/vslib/TestSwitchStateBase.cpp +++ b/unittest/vslib/TestSwitchStateBase.cpp @@ -138,6 +138,42 @@ TEST_F(SwitchStateBaseTest, switchHashCapabilitiesGet) ASSERT_EQ(hfSet1, hfSet2); } +TEST_F(SwitchStateBaseTest, switchHashAlgorithmCapabilitiesGet) +{ + sai_s32_list_t data = { .count = 0, .list = nullptr }; + + auto status = m_ss->queryAttrEnumValuesCapability( + m_swid, SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM, &data + ); + ASSERT_EQ(status, SAI_STATUS_BUFFER_OVERFLOW); + + std::vector haList(data.count); + data.list = haList.data(); + + status = m_ss->queryAttrEnumValuesCapability( + m_swid, SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM, &data + ); + ASSERT_EQ(status, SAI_STATUS_SUCCESS); + + const std::set haSet1 = { + SAI_HASH_ALGORITHM_CRC, + SAI_HASH_ALGORITHM_XOR, + SAI_HASH_ALGORITHM_RANDOM, + SAI_HASH_ALGORITHM_CRC_32LO, + SAI_HASH_ALGORITHM_CRC_32HI, + SAI_HASH_ALGORITHM_CRC_CCITT, + SAI_HASH_ALGORITHM_CRC_XOR + }; + + std::set haSet2; + + std::transform( + haList.cbegin(), haList.cend(), std::inserter(haSet2, haSet2.begin()), + [](sai_int32_t value) { return static_cast(value); } + ); + ASSERT_EQ(haSet1, haSet2); +} + //Test the following function: //sai_status_t initialize_voq_switch_objects( // _In_ uint32_t attr_count, diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index 7ec74a493..d07910734 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -3736,6 +3736,29 @@ sai_status_t SwitchStateBase::queryHashNativeHashFieldListCapability( return SAI_STATUS_SUCCESS; } +sai_status_t SwitchStateBase::querySwitchHashAlgorithmCapability( + _Inout_ sai_s32_list_t *enum_values_capability) +{ + SWSS_LOG_ENTER(); + + if (enum_values_capability->count < 7) + { + enum_values_capability->count = 7; + return SAI_STATUS_BUFFER_OVERFLOW; + } + + enum_values_capability->count = 7; + enum_values_capability->list[0] = SAI_HASH_ALGORITHM_CRC; + enum_values_capability->list[1] = SAI_HASH_ALGORITHM_XOR; + enum_values_capability->list[2] = SAI_HASH_ALGORITHM_RANDOM; + enum_values_capability->list[3] = SAI_HASH_ALGORITHM_CRC_32LO; + enum_values_capability->list[4] = SAI_HASH_ALGORITHM_CRC_32HI; + enum_values_capability->list[5] = SAI_HASH_ALGORITHM_CRC_CCITT; + enum_values_capability->list[6] = SAI_HASH_ALGORITHM_CRC_XOR; + + return SAI_STATUS_SUCCESS; +} + sai_status_t SwitchStateBase::queryAttrEnumValuesCapability( _In_ sai_object_id_t switch_id, _In_ sai_object_type_t object_type, @@ -3762,6 +3785,11 @@ sai_status_t SwitchStateBase::queryAttrEnumValuesCapability( { return queryHashNativeHashFieldListCapability(enum_values_capability); } + else if (object_type == SAI_OBJECT_TYPE_SWITCH && (attr_id == SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_ALGORITHM || + attr_id == SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_ALGORITHM)) + { + return querySwitchHashAlgorithmCapability(enum_values_capability); + } return SAI_STATUS_NOT_SUPPORTED; } diff --git a/vslib/SwitchStateBase.h b/vslib/SwitchStateBase.h index 3d489efe8..7051acc06 100644 --- a/vslib/SwitchStateBase.h +++ b/vslib/SwitchStateBase.h @@ -695,6 +695,9 @@ namespace saivs virtual sai_status_t queryHashNativeHashFieldListCapability( _Inout_ sai_s32_list_t *enum_values_capability); + virtual sai_status_t querySwitchHashAlgorithmCapability( + _Inout_ sai_s32_list_t *enum_values_capability); + virtual sai_status_t queryPortAutonegFecOverrideSupportCapability( _Out_ sai_attr_capability_t *attr_capability);