Skip to content

Commit

Permalink
[sairedis] Add get response timeout knob (#774)
Browse files Browse the repository at this point in the history
Knob needed by mlnx when doing firmware update on some platforms, which can exceed default 1 min timeout.
  • Loading branch information
kcudnik authored Feb 8, 2021
1 parent 3663e30 commit be8059f
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 13 deletions.
9 changes: 9 additions & 0 deletions lib/inc/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ namespace sairedis

virtual ~Channel();

public:

void setResponseTimeout(
_In_ uint64_t responseTimeout);

uint64_t getResponseTimeout() const;

public:

virtual void setBuffered(
Expand Down Expand Up @@ -56,6 +63,8 @@ namespace sairedis

Callback m_callback;

uint64_t m_responseTimeoutMs;

protected: // notification

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/inc/RedisRemoteSaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ namespace sairedis

std::shared_ptr<Channel> m_communicationChannel;

uint64_t m_responseTimeoutMs;

std::function<sai_switch_notifications_t(std::shared_ptr<Notification>)> m_notificationCallback;

std::map<sai_object_id_t, swss::TableDump> m_tableDump;
Expand Down
17 changes: 17 additions & 0 deletions lib/inc/sairedis.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ extern "C" {
*/
#define SAI_REDIS_KEY_CONTEXT_CONFIG "SAI_REDIS_CONTEXT_CONFIG"

/**
* @brief Default synchronous operation response timeout in milliseconds.
*/
#define SAI_REDIS_DEFAULT_SYNC_OPERATION_RESPONSE_TIMEOUT (60*1000)

typedef enum _sai_redis_notify_syncd_t
{
SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW,
Expand Down Expand Up @@ -205,4 +210,16 @@ typedef enum _sai_redis_switch_attr_t
*/
SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME,

/**
* @brief Synchronous operation response timeout in milliseconds.
*
* Used for every synchronous API call. In asynchronous mode used for GET
* operation.
*
* @type sai_uint64_t
* @flags CREATE_AND_SET
* @default 60000
*/
SAI_REDIS_SWITCH_ATTR_SYNC_OPERATION_RESPONSE_TIMEOUT,

} sai_redis_switch_attr_t;
20 changes: 19 additions & 1 deletion lib/src/Channel.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "Channel.h"

#include "sairedis.h"

#include "swss/logger.h"

using namespace sairedis;

Channel::Channel(
_In_ Callback callback):
m_callback(callback)
m_callback(callback),
m_responseTimeoutMs(SAI_REDIS_DEFAULT_SYNC_OPERATION_RESPONSE_TIMEOUT)
{
SWSS_LOG_ENTER();

Expand All @@ -19,3 +22,18 @@ Channel::~Channel()

// empty
}

void Channel::setResponseTimeout(
_In_ uint64_t responseTimeout)
{
SWSS_LOG_ENTER();

m_responseTimeoutMs = responseTimeout;
}

uint64_t Channel::getResponseTimeout() const
{
SWSS_LOG_ENTER();

return m_responseTimeoutMs;
}
7 changes: 1 addition & 6 deletions lib/src/RedisChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

using namespace sairedis;

/**
* @brief Get response timeout in milliseconds.
*/
#define REDIS_ASIC_STATE_COMMAND_GETRESPONSE_TIMEOUT_MS (60*1000)

RedisChannel::RedisChannel(
_In_ const std::string& dbAsic,
_In_ Channel::Callback callback):
Expand Down Expand Up @@ -179,7 +174,7 @@ sai_status_t RedisChannel::wait(

swss::Selectable *sel;

int result = s.select(&sel, REDIS_ASIC_STATE_COMMAND_GETRESPONSE_TIMEOUT_MS);
int result = s.select(&sel, (int)m_responseTimeoutMs);

if (result == swss::Select::OBJECT)
{
Expand Down
18 changes: 18 additions & 0 deletions lib/src/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ sai_status_t RedisRemoteSaiInterface::initialize(
std::bind(&RedisRemoteSaiInterface::handleNotification, this, _1, _2, _3));
}

m_responseTimeoutMs = m_communicationChannel->getResponseTimeout();

m_db = std::make_shared<swss::DBConnector>(m_contextConfig->m_dbAsic, 0);

m_redisVidIndexGenerator = std::make_shared<RedisVidIndexGenerator>(m_db, REDIS_KEY_VIDCOUNTER);
Expand Down Expand Up @@ -355,6 +357,16 @@ sai_status_t RedisRemoteSaiInterface::setRedisExtensionAttribute(

return SAI_STATUS_SUCCESS;

case SAI_REDIS_SWITCH_ATTR_SYNC_OPERATION_RESPONSE_TIMEOUT:

m_responseTimeoutMs = attr->value.u64;

m_communicationChannel->setResponseTimeout(m_responseTimeoutMs);

SWSS_LOG_NOTICE("set response timeout to %lu ms", m_responseTimeoutMs);

return SAI_STATUS_SUCCESS;

case SAI_REDIS_SWITCH_ATTR_SYNC_MODE:

SWSS_LOG_WARN("sync mode is depreacated, use communication mode");
Expand Down Expand Up @@ -402,6 +414,8 @@ sai_status_t RedisRemoteSaiInterface::setRedisExtensionAttribute(
m_contextConfig->m_dbAsic,
std::bind(&RedisRemoteSaiInterface::handleNotification, this, _1, _2, _3));

m_communicationChannel->setResponseTimeout(m_responseTimeoutMs);

m_communicationChannel->setBuffered(true);

return SAI_STATUS_SUCCESS;
Expand All @@ -416,6 +430,8 @@ sai_status_t RedisRemoteSaiInterface::setRedisExtensionAttribute(
m_contextConfig->m_dbAsic,
std::bind(&RedisRemoteSaiInterface::handleNotification, this, _1, _2, _3));

m_communicationChannel->setResponseTimeout(m_responseTimeoutMs);

m_communicationChannel->setBuffered(false);

return SAI_STATUS_SUCCESS;
Expand All @@ -432,6 +448,8 @@ sai_status_t RedisRemoteSaiInterface::setRedisExtensionAttribute(
m_contextConfig->m_zmqNtfEndpoint,
std::bind(&RedisRemoteSaiInterface::handleNotification, this, _1, _2, _3));

m_communicationChannel->setResponseTimeout(m_responseTimeoutMs);

SWSS_LOG_NOTICE("zmq enabled, forcing sync mode");

m_syncMode = true;
Expand Down
7 changes: 1 addition & 6 deletions lib/src/ZeroMQChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

using namespace sairedis;

/**
* @brief Get response timeout in milliseconds.
*/
#define ZMQ_GETRESPONSE_TIMEOUT_MS (60*1000)

#define ZMQ_RESPONSE_BUFFER_SIZE (4*1024*1024)

ZeroMQChannel::ZeroMQChannel(
Expand Down Expand Up @@ -273,7 +268,7 @@ sai_status_t ZeroMQChannel::wait(
items[0].socket = m_socket;
items[0].events = ZMQ_POLLIN;

int rc = zmq_poll(items, 1, ZMQ_GETRESPONSE_TIMEOUT_MS);
int rc = zmq_poll(items, 1, (int)m_responseTimeoutMs);

if (rc == 0)
{
Expand Down

0 comments on commit be8059f

Please sign in to comment.