Skip to content

Commit

Permalink
[hash]: Extend VS lib with ECMP/LAG hash algorithm.
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn <[email protected]>
  • Loading branch information
nazariig committed Nov 15, 2023
1 parent c532600 commit 2b85de0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
36 changes: 36 additions & 0 deletions unittest/vslib/TestSwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sai_int32_t> 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<sai_hash_algorithm_t> 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<sai_hash_algorithm_t> haSet2;

std::transform(
haList.cbegin(), haList.cend(), std::inserter(haSet2, haSet2.begin()),
[](sai_int32_t value) { return static_cast<sai_hash_algorithm_t>(value); }
);
ASSERT_EQ(haSet1, haSet2);
}

//Test the following function:
//sai_status_t initialize_voq_switch_objects(
// _In_ uint32_t attr_count,
Expand Down
28 changes: 28 additions & 0 deletions vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions vslib/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 2b85de0

Please sign in to comment.