Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libsai RedisInterface for link event damping. #1331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Comment on lines +507 to +515
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this api always synchronous, async mode is just for create/remove/set operations all other apis should be synchronous


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;
Comment on lines +1883 to +1888
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can turn this to 1 single line by reversing condition

}

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 @@ -210,6 +210,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 @@ -346,6 +355,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 @@ -373,6 +387,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);
Ashish1805 marked this conversation as resolved.
Show resolved Hide resolved

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
Loading