Skip to content

Commit

Permalink
Add libsai RedisInterface for link event damping.
Browse files Browse the repository at this point in the history
- This supports the link event damping config and algorithm set API.
- Sends the link event damping config from libsai to syncd main thread.

HLD: sonic-net/SONiC#1071

Signed-off-by: Ashish Singh <[email protected]>
  • Loading branch information
Ashish Singh committed May 10, 2024
1 parent 256ce7d commit ec5cf30
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/ClientSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ sai_status_t ClientSai::set(
SWSS_LOG_ENTER();
REDIS_CHECK_API_INITIALIZED();

if (RedisRemoteSaiInterface::isRedisAttribute(objectType, attr))
if (RedisRemoteSaiInterface::isRedisAttribute(objectType, attr) ||
RedisRemoteSaiInterface::isRedisPortAttribute(objectType, attr))
{
SWSS_LOG_ERROR("sairedis extension attributes are not supported in CLIENT mode");

Expand Down
96 changes: 96 additions & 0 deletions lib/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,83 @@ sai_status_t RedisRemoteSaiInterface::setRedisExtensionAttribute(
return SAI_STATUS_FAILURE;
}

sai_status_t RedisRemoteSaiInterface::setLinkEventDampingConfig(
_In_ sai_object_type_t objectType,
_In_ sai_object_id_t objectId,
_In_ const std::vector<swss::FieldValueTuple> &values)
{
SWSS_LOG_ENTER();

std::string key = sai_serialize_object_type(objectType) + ":" + sai_serialize_object_id(objectId);

m_communicationChannel->set(key, values, REDIS_ASIC_STATE_COMMAND_DAMPING_CONFIG_SET);

if (m_syncMode)
{
swss::KeyOpFieldsValuesTuple kco;
auto status = m_communicationChannel->wait(REDIS_ASIC_STATE_COMMAND_DAMPING_CONFIG_SET, kco);

m_recorder->recordGenericSetResponse(status);

return status;
}

return SAI_STATUS_SUCCESS;
}

sai_status_t RedisRemoteSaiInterface::setRedisPortExtensionAttribute(
_In_ sai_object_type_t objectType,
_In_ sai_object_id_t objectId,
_In_ const sai_attribute_t *attr)
{
SWSS_LOG_ENTER();

if (attr == nullptr)
{
SWSS_LOG_ERROR("attr pointer is null");

return SAI_STATUS_INVALID_PARAMETER;
}

std::string str_attr_id = sai_serialize_redis_port_attr_id(
static_cast<sai_redis_port_attr_t>(attr->id));

switch (attr->id)
{
case SAI_REDIS_PORT_ATTR_LINK_EVENT_DAMPING_ALGORITHM:
{
std::string str_attr_value = sai_serialize_redis_link_event_damping_algorithm(
static_cast<sai_redis_link_event_damping_algorithm_t>(attr->value.s32));

return setLinkEventDampingConfig(
objectType, objectId, {swss::FieldValueTuple(str_attr_id, str_attr_value)});
}
case SAI_REDIS_PORT_ATTR_LINK_EVENT_DAMPING_ALGO_AIED_CONFIG:
{
sai_redis_link_event_damping_algo_aied_config_t *config =
(sai_redis_link_event_damping_algo_aied_config_t *)attr->value.ptr;

if (config == NULL)
{
SWSS_LOG_ERROR("invalid link damping config attr value NULL");

return SAI_STATUS_INVALID_PARAMETER;
}

std::string str_attr_value = sai_serialize_redis_link_event_damping_aied_config(*config);

return setLinkEventDampingConfig(
objectType, objectId, {swss::FieldValueTuple(str_attr_id, str_attr_value)});
}
default:
break;
}

SWSS_LOG_ERROR("unknown redis port extension attribute: %d", attr->id);

return SAI_STATUS_INVALID_PARAMETER;
}

bool RedisRemoteSaiInterface::isSaiS8ListValidString(
_In_ const sai_s8_list_t &s8list)
{
Expand Down Expand Up @@ -625,6 +702,11 @@ sai_status_t RedisRemoteSaiInterface::set(
return setRedisExtensionAttribute(objectType, objectId, attr);
}

if (RedisRemoteSaiInterface::isRedisPortAttribute(objectType, attr))
{
return setRedisPortExtensionAttribute(objectType, objectId, attr);
}

auto status = set(
objectType,
sai_serialize_object_id(objectId),
Expand Down Expand Up @@ -1792,6 +1874,20 @@ bool RedisRemoteSaiInterface::isRedisAttribute(
return true;
}

bool RedisRemoteSaiInterface::isRedisPortAttribute(
_In_ sai_object_id_t objectType,
_In_ const sai_attribute_t* attr)
{
SWSS_LOG_ENTER();

if ((objectType != SAI_OBJECT_TYPE_PORT) || (attr == nullptr) || (attr->id < SAI_PORT_ATTR_CUSTOM_RANGE_START))
{
return false;
}

return true;
}

void RedisRemoteSaiInterface::handleNotification(
_In_ const std::string &name,
_In_ const std::string &serializedNotification,
Expand Down
19 changes: 19 additions & 0 deletions lib/RedisRemoteSaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ namespace sairedis
_In_ sai_object_id_t switchId,
_In_ const sai_attribute_t* attr);

/**
* @brief Checks whether attribute is custom SAI_REDIS_PORT attribute.
*
* This function should only be used on port_api set function.
*/
static bool isRedisPortAttribute(
_In_ sai_object_id_t obejctType,
_In_ const sai_attribute_t* attr);

void setMeta(
_In_ std::weak_ptr<saimeta::Meta> meta);

Expand Down Expand Up @@ -343,6 +352,11 @@ namespace sairedis
_In_ sai_object_id_t objectId,
_In_ const sai_attribute_t *attr);

sai_status_t setRedisPortExtensionAttribute(
_In_ sai_object_type_t objectType,
_In_ sai_object_id_t objectId,
_In_ const sai_attribute_t *attr);

bool isSaiS8ListValidString(
_In_ const sai_s8_list_t &s8list);

Expand Down Expand Up @@ -370,6 +384,11 @@ namespace sairedis
_In_ sai_object_id_t switchId,
_In_ const sai_attribute_t *attr);

sai_status_t setLinkEventDampingConfig(
_In_ sai_object_type_t objectType,
_In_ sai_object_id_t objectId,
_In_ const std::vector<swss::FieldValueTuple> &values);

void clear_local_state();

sai_switch_notifications_t processNotification(
Expand Down
6 changes: 6 additions & 0 deletions lib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ sai_status_t Sai::set(

REDIS_CHECK_CONTEXT(objectId);

if (RedisRemoteSaiInterface::isRedisPortAttribute(objectType, attr))
{
// skip metadata if attribute is redis extension port attribute.
return context->m_redisSai->set(objectType, objectId, attr);
}

return context->m_meta->set(objectType, objectId, attr);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/sairediscommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#define REDIS_ASIC_STATE_COMMAND_OBJECT_TYPE_GET_AVAILABILITY_QUERY "object_type_get_availability_query"
#define REDIS_ASIC_STATE_COMMAND_OBJECT_TYPE_GET_AVAILABILITY_RESPONSE "object_type_get_availability_response"

#define REDIS_ASIC_STATE_COMMAND_DAMPING_CONFIG_SET "link_event_damping_config_set"

#define REDIS_FLEX_COUNTER_COMMAND_START_POLL "start_poll"
#define REDIS_FLEX_COUNTER_COMMAND_STOP_POLL "stop_poll"
#define REDIS_FLEX_COUNTER_COMMAND_SET_GROUP "set_counter_group"
Expand Down
33 changes: 33 additions & 0 deletions syncd/Syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ sai_status_t Syncd::processSingleEvent(
if (op == REDIS_ASIC_STATE_COMMAND_OBJECT_TYPE_GET_AVAILABILITY_QUERY)
return processObjectTypeGetAvailabilityQuery(kco);

if (op == REDIS_ASIC_STATE_COMMAND_DAMPING_CONFIG_SET)
return processLinkEventDampingConfigSet(kco);

if (op == REDIS_FLEX_COUNTER_COMMAND_START_POLL)
return processFlexCounterEvent(key, SET_COMMAND, kfvFieldsValues(kco));

Expand Down Expand Up @@ -580,6 +583,36 @@ sai_status_t Syncd::processObjectTypeGetAvailabilityQuery(
return status;
}

sai_status_t Syncd::processLinkEventDampingConfigSet(
_In_ const swss::KeyOpFieldsValuesTuple &kco)
{
SWSS_LOG_ENTER();

sendLinkEventDampingConfigResponse(SAI_STATUS_NOT_IMPLEMENTED);

return SAI_STATUS_NOT_IMPLEMENTED;
}

void Syncd::sendLinkEventDampingConfigResponse(
_In_ sai_status_t status)
{
SWSS_LOG_ENTER();

// If sync mode is not enabled, do not send response.
if (!m_enableSyncMode)
{
return;
}

std::string strStatus = sai_serialize_status(status);

std::vector<swss::FieldValueTuple> entry;

SWSS_LOG_INFO("sending link event damping config response: %s", strStatus.c_str());

m_selectableChannel->set(strStatus, entry, REDIS_ASIC_STATE_COMMAND_DAMPING_CONFIG_SET);
}

sai_status_t Syncd::processFdbFlush(
_In_ const swss::KeyOpFieldsValuesTuple &kco)
{
Expand Down
6 changes: 6 additions & 0 deletions syncd/Syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ namespace syncd
_In_ const std::vector<swss::FieldValueTuple> &values,
_In_ bool fromAsicChannel=true);

sai_status_t processLinkEventDampingConfigSet(
_In_ const swss::KeyOpFieldsValuesTuple &kco);

private: // process quad oid

sai_status_t processOidCreate(
Expand Down Expand Up @@ -361,6 +364,9 @@ namespace syncd
void sendNotifyResponse(
_In_ sai_status_t status);

void sendLinkEventDampingConfigResponse(
_In_ sai_status_t status);

private: // snoop get response oids

void snoopGetResponse(
Expand Down
2 changes: 1 addition & 1 deletion syncd/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main
bin_PROGRAMS = tests

tests_SOURCES = \
main.cpp TestSyncdBrcm.cpp TestSyncdMlnx.cpp TestSyncdNvdaBf.cpp TestSyncdLib.cpp
main.cpp TestSyncdBrcm.cpp TestSyncdMlnx.cpp TestSyncdNvdaBf.cpp TestSyncdLib.cpp TestSyncdLinkEventDamping.cpp
tests_CXXFLAGS = \
$(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDADD = \
Expand Down
Loading

0 comments on commit ec5cf30

Please sign in to comment.