Skip to content

Commit

Permalink
[hash]: Extend VS lib with ECMP/LAG hash.
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn <nazariig@nvidia.com>
  • Loading branch information
nazariig committed Jan 4, 2023
1 parent 86bb828 commit f8da0c3
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lib/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,20 @@ sai_status_t RedisRemoteSaiInterface::waitForQueryAattributeEnumValuesCapability
}
else if (status == SAI_STATUS_BUFFER_OVERFLOW)
{
// TODO on sai status overflow we should populate correct count on the list
const std::vector<swss::FieldValueTuple> &values = kfvFieldsValues(kco);

if (values.size() != 1)
{
SWSS_LOG_ERROR("Invalid response from syncd: expected 1 value, received %zu", values.size());

return SAI_STATUS_FAILURE;
}

const uint32_t num_capabilities = std::stoi(fvValue(values[0]));

SWSS_LOG_ERROR("TODO need to handle SAI_STATUS_BUFFER_OVERFLOW, FIXME");
SWSS_LOG_DEBUG("Received payload: count = %u", num_capabilities);

enumValuesCapability->count = num_capabilities;
}

return status;
Expand Down
9 changes: 9 additions & 0 deletions syncd/Syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ sai_status_t Syncd::processAttrEnumValuesCapabilityQuery(

SWSS_LOG_DEBUG("Sending response: capabilities = '%s', count = %d", strCap.c_str(), enumCapList.count);
}
else if (status == SAI_STATUS_BUFFER_OVERFLOW)
{
entry =
{
swss::FieldValueTuple("ENUM_COUNT", std::to_string(enumCapList.count))
};

SWSS_LOG_DEBUG("Sending response: count = %u", enumCapList.count);
}

m_selectableChannel->set(sai_serialize_status(status), entry, REDIS_ASIC_STATE_COMMAND_ATTR_ENUM_VALUES_CAPABILITY_RESPONSE);

Expand Down
2 changes: 2 additions & 0 deletions tests/aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ EAPOL
ECN
EIO
ETERM
ecmp
ECMP
FDB
FDBs
FIXME
Expand Down
85 changes: 85 additions & 0 deletions vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,48 @@ sai_status_t SwitchStateBase::set_switch_default_attributes()
return set_switch_supported_object_types();
}

sai_status_t SwitchStateBase::create_default_hash()
{
SWSS_LOG_ENTER();

SWSS_LOG_INFO("create default hash");

// Hash defaults according to SAI headers
std::vector<sai_native_hash_field_t> hfList = {
SAI_NATIVE_HASH_FIELD_DST_MAC,
SAI_NATIVE_HASH_FIELD_SRC_MAC,
SAI_NATIVE_HASH_FIELD_ETHERTYPE,
SAI_NATIVE_HASH_FIELD_IN_PORT
};

// create and populate default ecmp hash object
sai_attribute_t attr;
attr.id = SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST;
attr.value.s32list.list = reinterpret_cast<sai_int32_t*>(hfList.data());
attr.value.s32list.count = static_cast<sai_uint32_t>(hfList.size());

CHECK_STATUS(create(SAI_OBJECT_TYPE_HASH, &m_ecmp_hash_id, m_switch_id, 1, &attr));

// set default ecmp hash on switch
attr.id = SAI_SWITCH_ATTR_ECMP_HASH;
attr.value.oid = m_ecmp_hash_id;

CHECK_STATUS(set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr));

// create and populate default lag hash object
attr.id = SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST;
attr.value.s32list.list = reinterpret_cast<sai_int32_t*>(hfList.data());
attr.value.s32list.count = static_cast<sai_uint32_t>(hfList.size());

CHECK_STATUS(create(SAI_OBJECT_TYPE_HASH, &m_lag_hash_id, m_switch_id, 1, &attr));

// set default lag hash on switch
attr.id = SAI_SWITCH_ATTR_LAG_HASH;
attr.value.oid = m_lag_hash_id;

return set(SAI_OBJECT_TYPE_SWITCH, m_switch_id, &attr);
}

sai_status_t SwitchStateBase::set_static_crm_values()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -1608,6 +1650,7 @@ sai_status_t SwitchStateBase::initialize_default_objects(

CHECK_STATUS(set_switch_mac_address());
CHECK_STATUS(create_cpu_port());
CHECK_STATUS(create_default_hash());
CHECK_STATUS(create_default_vlan());
CHECK_STATUS(create_default_virtual_router());
CHECK_STATUS(create_default_stp_instance());
Expand Down Expand Up @@ -2262,6 +2305,10 @@ sai_status_t SwitchStateBase::refresh_read_only(
case SAI_SWITCH_ATTR_DEFAULT_1Q_BRIDGE_ID:
return SAI_STATUS_SUCCESS;

case SAI_SWITCH_ATTR_ECMP_HASH:
case SAI_SWITCH_ATTR_LAG_HASH:
return SAI_STATUS_SUCCESS;

case SAI_SWITCH_ATTR_ACL_ENTRY_MINIMUM_PRIORITY:
case SAI_SWITCH_ATTR_ACL_ENTRY_MAXIMUM_PRIORITY:
return SAI_STATUS_SUCCESS;
Expand Down Expand Up @@ -3632,6 +3679,39 @@ sai_status_t SwitchStateBase::queryNextHopGroupTypeCapability(
return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::queryHashNativeHashFieldListCapability(
_Inout_ sai_s32_list_t *enum_values_capability)
{
SWSS_LOG_ENTER();

if (enum_values_capability->count < 18)
{
enum_values_capability->count = 18;
return SAI_STATUS_BUFFER_OVERFLOW;
}

enum_values_capability->count = 18;
enum_values_capability->list[0] = SAI_NATIVE_HASH_FIELD_IN_PORT;
enum_values_capability->list[1] = SAI_NATIVE_HASH_FIELD_DST_MAC;
enum_values_capability->list[2] = SAI_NATIVE_HASH_FIELD_SRC_MAC;
enum_values_capability->list[3] = SAI_NATIVE_HASH_FIELD_ETHERTYPE;
enum_values_capability->list[4] = SAI_NATIVE_HASH_FIELD_VLAN_ID;
enum_values_capability->list[5] = SAI_NATIVE_HASH_FIELD_IP_PROTOCOL;
enum_values_capability->list[6] = SAI_NATIVE_HASH_FIELD_DST_IP;
enum_values_capability->list[7] = SAI_NATIVE_HASH_FIELD_SRC_IP;
enum_values_capability->list[8] = SAI_NATIVE_HASH_FIELD_L4_DST_PORT;
enum_values_capability->list[9] = SAI_NATIVE_HASH_FIELD_L4_SRC_PORT;
enum_values_capability->list[10] = SAI_NATIVE_HASH_FIELD_INNER_DST_MAC;
enum_values_capability->list[11] = SAI_NATIVE_HASH_FIELD_INNER_SRC_MAC;
enum_values_capability->list[12] = SAI_NATIVE_HASH_FIELD_INNER_ETHERTYPE;
enum_values_capability->list[13] = SAI_NATIVE_HASH_FIELD_INNER_IP_PROTOCOL;
enum_values_capability->list[14] = SAI_NATIVE_HASH_FIELD_INNER_DST_IP;
enum_values_capability->list[15] = SAI_NATIVE_HASH_FIELD_INNER_SRC_IP;
enum_values_capability->list[16] = SAI_NATIVE_HASH_FIELD_INNER_L4_DST_PORT;
enum_values_capability->list[17] = SAI_NATIVE_HASH_FIELD_INNER_L4_SRC_PORT;

return SAI_STATUS_SUCCESS;
}

sai_status_t SwitchStateBase::queryAttrEnumValuesCapability(
_In_ sai_object_id_t switch_id,
Expand All @@ -3655,5 +3735,10 @@ sai_status_t SwitchStateBase::queryAttrEnumValuesCapability(
{
return queryNextHopGroupTypeCapability(enum_values_capability);
}
else if (object_type == SAI_OBJECT_TYPE_HASH && attr_id == SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST)
{
return queryHashNativeHashFieldListCapability(enum_values_capability);
}

return SAI_STATUS_NOT_SUPPORTED;
}
8 changes: 7 additions & 1 deletion vslib/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace saivs

virtual sai_status_t set_switch_default_attributes();

virtual sai_status_t create_default_hash();

virtual sai_status_t create_default_vlan();

virtual sai_status_t create_cpu_port();
Expand Down Expand Up @@ -644,6 +646,9 @@ namespace saivs
sai_object_id_t m_default_bridge_port_1q_router;
sai_object_id_t m_default_vlan_id;

sai_object_id_t m_ecmp_hash_id;
sai_object_id_t m_lag_hash_id;

std::vector<sai_object_id_t> m_system_port_list;

protected:
Expand Down Expand Up @@ -681,7 +686,8 @@ namespace saivs
virtual sai_status_t queryNextHopGroupTypeCapability(
_Inout_ sai_s32_list_t *enum_values_capability);


virtual sai_status_t queryHashNativeHashFieldListCapability(
_Inout_ sai_s32_list_t *enum_values_capability);

public: // TODO private

Expand Down

0 comments on commit f8da0c3

Please sign in to comment.