Skip to content

Commit

Permalink
[SaiInterface] Support sai_query_api_version api (#1383)
Browse files Browse the repository at this point in the history
Will be needed in later consolidation code
  • Loading branch information
kcudnik authored May 26, 2024
1 parent c3ad5ce commit 20bcfe1
Show file tree
Hide file tree
Showing 32 changed files with 302 additions and 50 deletions.
12 changes: 12 additions & 0 deletions lib/ClientSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,3 +1497,15 @@ sai_status_t ClientSai::logSet(

return SAI_STATUS_SUCCESS;
}

sai_status_t ClientSai::queryApiVersion(
_Out_ sai_api_version_t *version)
{
MUTEX();
SWSS_LOG_ENTER();
REDIS_CHECK_API_INITIALIZED();

SWSS_LOG_ERROR("queryApiVersion not implemented, FIXME");

return SAI_STATUS_NOT_IMPLEMENTED;
}
3 changes: 3 additions & 0 deletions lib/ClientSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ namespace sairedis
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

private: // QUAD API helpers

sai_status_t create(
Expand Down
10 changes: 10 additions & 0 deletions lib/ClientServerSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,13 @@ sai_status_t ClientServerSai::logSet(

return m_sai->logSet(api, log_level);
}

sai_status_t ClientServerSai::queryApiVersion(
_Out_ sai_api_version_t *version)
{
MUTEX();
SWSS_LOG_ENTER();
REDIS_CHECK_API_INITIALIZED();

return m_sai->queryApiVersion(version);
}
3 changes: 3 additions & 0 deletions lib/ClientServerSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ namespace sairedis
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

private:

bool m_apiInitialized;
Expand Down
21 changes: 21 additions & 0 deletions lib/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,27 @@ sai_status_t RedisRemoteSaiInterface::logSet(
return SAI_STATUS_SUCCESS;
}

sai_status_t RedisRemoteSaiInterface::queryApiVersion(
_Out_ sai_api_version_t *version)
{
SWSS_LOG_ENTER();

if (version)
{
*version = SAI_API_VERSION;

// TODO FIXME implement proper query for syncd, currently this is not an issue since swss is not using this API

SWSS_LOG_WARN("retruning SAI API version %d with sairedis compiled SAI headers, not actual libsai.so", SAI_API_VERSION);

return SAI_STATUS_SUCCESS;
}

SWSS_LOG_ERROR("version parameter is NULL");

return SAI_STATUS_INVALID_PARAMETER;
}

sai_status_t RedisRemoteSaiInterface::sai_redis_notify_syncd(
_In_ sai_object_id_t switchId,
_In_ const sai_attribute_t *attr)
Expand Down
3 changes: 3 additions & 0 deletions lib/RedisRemoteSaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ namespace sairedis
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

public: // notify syncd

virtual sai_status_t notifySyncd(
Expand Down
25 changes: 25 additions & 0 deletions lib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,31 @@ sai_status_t Sai::logSet(
return SAI_STATUS_SUCCESS;
}

sai_status_t Sai::queryApiVersion(
_Out_ sai_api_version_t *version)
{
MUTEX();
SWSS_LOG_ENTER();
REDIS_CHECK_API_INITIALIZED();

// TODO we should use specific context, but we don't know which one since
// there is no object ID parameter, we can use default context or cast
// version as context id same as passed in SAI_REDIS_SWITCH_ATTR_CONTEXT
// currently we will return just first context on context map, since
// user maybe not aware of trick with casting context

for (auto&kvp: m_contextMap)
{
SWSS_LOG_WARN("using first context");

return kvp.second->m_meta->queryApiVersion(version);
}

SWSS_LOG_ERROR("context map is empty");

return SAI_STATUS_FAILURE;
}

/*
* NOTE: Notifications during switch create and switch remove.
*
Expand Down
3 changes: 3 additions & 0 deletions lib/Sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ namespace sairedis
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

private:

sai_switch_notifications_t handle_notification(
Expand Down
10 changes: 10 additions & 0 deletions lib/ServerSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ sai_status_t ServerSai::logSet(
return m_sai->logSet(api, log_level);
}

sai_status_t ServerSai::queryApiVersion(
_Out_ sai_api_version_t *version)
{
MUTEX();
SWSS_LOG_ENTER();
REDIS_CHECK_API_INITIALIZED();

return m_sai->queryApiVersion(version);
}

void ServerSai::serverThreadFunction()
{
SWSS_LOG_ENTER();
Expand Down
3 changes: 3 additions & 0 deletions lib/ServerSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ namespace sairedis
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

private:

void serverThreadFunction();
Expand Down
15 changes: 1 addition & 14 deletions lib/sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,7 @@ sai_status_t sai_query_api_version(
{
SWSS_LOG_ENTER();

if (version)
{
*version = SAI_API_VERSION;

// TODO FIXME implement proper query for syncd, currently this is not an issue since swss is not using this API

SWSS_LOG_WARN("retruning SAI API version %d with sairedis compiled SAI headers, not actual libsai.so", SAI_API_VERSION);

return SAI_STATUS_SUCCESS;
}

SWSS_LOG_ERROR("version parameter is NULL");

return SAI_STATUS_INVALID_PARAMETER;
return redis_sai->queryApiVersion(version);
}

sai_status_t sai_bulk_object_get_stats(
Expand Down
17 changes: 17 additions & 0 deletions meta/DummySaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,20 @@ sai_status_t DummySaiInterface::logSet(

return m_status;
}

sai_status_t DummySaiInterface::queryApiVersion(
_Out_ sai_api_version_t *version)
{
SWSS_LOG_ENTER();

if (version)
{
*version = SAI_API_VERSION;

return m_status;
}

SWSS_LOG_ERROR("version parameter is NULL");

return m_status;
}
3 changes: 3 additions & 0 deletions meta/DummySaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ namespace saimeta
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

protected:

sai_status_t m_status;
Expand Down
10 changes: 10 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,16 @@ sai_status_t Meta::logSet(
return m_implementation->logSet(api, log_level);
}

sai_status_t Meta::queryApiVersion(
_Out_ sai_api_version_t *version)
{
SWSS_LOG_ENTER();

PARAMETER_CHECK_IF_NOT_NULL(version);

return m_implementation->queryApiVersion(version);
}

void Meta::clean_after_switch_remove(
_In_ sai_object_id_t switchId)
{
Expand Down
3 changes: 3 additions & 0 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ namespace saimeta
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

public:

void meta_init_db();
Expand Down
3 changes: 3 additions & 0 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ namespace sairedis
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) = 0;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) = 0;

public: // non SAI API

virtual sai_log_level_t logGet(
Expand Down
23 changes: 23 additions & 0 deletions proxylib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,29 @@ sai_status_t Sai::logSet(
return SAI_STATUS_SUCCESS;
}

sai_status_t Sai::queryApiVersion(
_Out_ sai_api_version_t *version)
{
SWSS_LOG_ENTER();

// TODO this should be forwarded to SaiInterface object

if (version)
{
*version = SAI_API_VERSION;

// TODO FIXME implement proper query for syncd, currently this is not an issue since swss is not using this API

SWSS_LOG_WARN("retruning SAI API version %d with saiproxy compiled SAI headers, not actual libsai.so", SAI_API_VERSION);

return SAI_STATUS_SUCCESS;
}

SWSS_LOG_ERROR("version parameter is NULL");

return SAI_STATUS_INVALID_PARAMETER;
}

//sai_switch_notifications_t Sai::handle_notification(
// _In_ std::shared_ptr<Notification> notification)
//{
Expand Down
3 changes: 3 additions & 0 deletions proxylib/Sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ namespace saiproxy
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

private:

sai_switch_notifications_t handle_notification(
Expand Down
17 changes: 1 addition & 16 deletions proxylib/sai_proxy_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,7 @@ sai_status_t sai_query_api_version(
{
SWSS_LOG_ENTER();

// TODO this should be forwarded to SaiInterface object

if (version)
{
*version = SAI_API_VERSION;

// TODO FIXME implement proper query for syncd, currently this is not an issue since swss is not using this API

SWSS_LOG_WARN("retruning SAI API version %d with saiproxy compiled SAI headers, not actual libsai.so", SAI_API_VERSION);

return SAI_STATUS_SUCCESS;
}

SWSS_LOG_ERROR("version parameter is NULL");

return SAI_STATUS_INVALID_PARAMETER;
return proxy_sai->queryApiVersion(version);
}

sai_status_t sai_bulk_object_get_stats(
Expand Down
43 changes: 26 additions & 17 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ sai_status_t VendorSai::initialize(
return SAI_STATUS_INVALID_PARAMETER;
}

memcpy(&m_service_method_table, service_method_table, sizeof(m_service_method_table));

auto status = m_globalApis.api_initialize(flags, service_method_table);

if (status == SAI_STATUS_SUCCESS)
{
memset(&m_apis, 0, sizeof(m_apis));

int failed = sai_metadata_apis_query(m_globalApis.api_query, &m_apis);

if (failed > 0)
{
SWSS_LOG_NOTICE("sai_api_query failed for %d apis", failed);
}

}

sai_api_version_t version{};

auto api_status = m_globalApis.query_api_version(&version);
Expand Down Expand Up @@ -120,23 +137,7 @@ sai_status_t VendorSai::initialize(
return SAI_STATUS_FAILURE;
}

memcpy(&m_service_method_table, service_method_table, sizeof(m_service_method_table));

auto status = m_globalApis.api_initialize(flags, service_method_table);

if (status == SAI_STATUS_SUCCESS)
{
memset(&m_apis, 0, sizeof(m_apis));

int failed = sai_metadata_apis_query(m_globalApis.api_query, &m_apis);

if (failed > 0)
{
SWSS_LOG_NOTICE("sai_api_query failed for %d apis", failed);
}

m_apiInitialized = true;
}
m_apiInitialized = true;

return status;
}
Expand Down Expand Up @@ -1686,6 +1687,14 @@ sai_status_t VendorSai::logSet(
return m_globalApis.log_set(api, log_level);
}

sai_status_t VendorSai::queryApiVersion(
_Out_ sai_api_version_t *version)
{
SWSS_LOG_ENTER();

return m_globalApis.query_api_version(version);
}

sai_log_level_t VendorSai::logGet(
_In_ sai_api_t api)
{
Expand Down
3 changes: 3 additions & 0 deletions syncd/VendorSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ namespace syncd
_In_ sai_api_t api,
_In_ sai_log_level_t log_level) override;

virtual sai_status_t queryApiVersion(
_Out_ sai_api_version_t *version) override;

public: // extra API

virtual sai_log_level_t logGet(
Expand Down
3 changes: 2 additions & 1 deletion unittest/lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ tests_SOURCES = \
TestServerConfig.cpp \
TestRedisVidIndexGenerator.cpp \
TestRecorder.cpp \
TestRedisChannel.cpp
TestRedisChannel.cpp \
TestSai.cpp

tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/lib/libSaiRedis.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)
Expand Down
Loading

0 comments on commit 20bcfe1

Please sign in to comment.