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

[configure.ac] implement SAI API version check #1000

Merged
merged 4 commits into from
May 17, 2022
Merged
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
23 changes: 23 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ AC_SUBST(CXXFLAGS_COMMON)

AC_SUBST(SAIINC, "-I\$(top_srcdir)/SAI/inc -I\$(top_srcdir)/SAI/experimental -I\$(top_srcdir)/SAI/meta")

AM_COND_IF([SYNCD], [
AM_COND_IF([SAIVS], [], [
SAVED_FLAGS="$CXXFLAGS"
CXXFLAGS="-lsai -I$srcdir/SAI/inc -I$srcdir/SAI/experimental -I$srcdir/SAI/meta"
AC_MSG_CHECKING([SAI headers API version and library version check])
AC_TRY_RUN([
extern "C" {
#include <sai.h>
}
int main() {
sai_api_version_t version;
if (SAI_STATUS_SUCCESS != sai_query_api_version(&version))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also add a runtime check in syncd + log to syslog

{
return 1;
}
return (version != SAI_API_VERSION);
}],
[AC_MSG_RESULT(ok)],
[AC_MSG_RESULT(failed)
AC_MSG_ERROR("SAI headers API version and library version mismatch")])
CXXFLAGS="$SAVED_FLAGS"
])])

AC_OUTPUT(Makefile
meta/Makefile
lib/Makefile
Expand Down
8 changes: 8 additions & 0 deletions lib/sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,11 @@ sai_status_t sai_query_stats_capability(

return SAI_STATUS_NOT_IMPLEMENTED;
}

sai_status_t sai_query_api_version(
_Out_ sai_api_version_t *version)
{
SWSS_LOG_ENTER();

return SAI_STATUS_NOT_IMPLEMENTED;
}
22 changes: 21 additions & 1 deletion syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "swss/logger.h"

#include <cinttypes>
#include <cstring>

using namespace syncd;
Expand Down Expand Up @@ -57,9 +58,28 @@ sai_status_t VendorSai::initialize(
return SAI_STATUS_INVALID_PARAMETER;
}

sai_api_version_t version{};
auto status = sai_query_api_version(&version);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("failed to query SAI API version");

return status;
}

SWSS_LOG_NOTICE("SAI API version: %" PRId64, version);

if (version != SAI_API_VERSION)
{
SWSS_LOG_ERROR("SAI implementation API version %" PRId64 " does not match SAI headers API version %" PRId64,
version, SAI_API_VERSION);

return SAI_STATUS_FAILURE;
}

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

auto status = sai_api_initialize(flags, service_method_table);
status = sai_api_initialize(flags, service_method_table);

if (status == SAI_STATUS_SUCCESS)
{
Expand Down
9 changes: 9 additions & 0 deletions vslib/sai_vs_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,12 @@ sai_status_t sai_query_stats_capability(

return vs_sai->queryStatsCapability(switch_id, object_type, stats_capability);
}

sai_status_t sai_query_api_version(
_Out_ sai_api_version_t *version)
{
SWSS_LOG_ENTER();

*version = SAI_API_VERSION;
return SAI_STATUS_SUCCESS;
}