Skip to content

Commit

Permalink
[configure.ac] implement SAI API version check (#1000)
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Blyschak [email protected]

The motivation for this change is described in the proposal sonic-net/SONiC#935 and proposal in SAI opencomputeproject/SAI#1404
NOTE: Requires to update SAI once opencomputeproject/SAI#1404 is in.
  • Loading branch information
stepanblyschak authored May 17, 2022
1 parent 8894dc7 commit 57ed180
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
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))
{
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;
}

0 comments on commit 57ed180

Please sign in to comment.