From 57ed18076530e41dd12ee1adfb392f240e7983fb Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Tue, 17 May 2022 17:48:01 +0300 Subject: [PATCH] [configure.ac] implement SAI API version check (#1000) Signed-off-by: Stepan Blyschak stepanb@nvidia.com 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. --- configure.ac | 23 +++++++++++++++++++++++ lib/sai_redis_interfacequery.cpp | 8 ++++++++ syncd/VendorSai.cpp | 22 +++++++++++++++++++++- vslib/sai_vs_interfacequery.cpp | 9 +++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 23da9c2bd25f..03394a8c9c3f 100644 --- a/configure.ac +++ b/configure.ac @@ -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 +} +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 diff --git a/lib/sai_redis_interfacequery.cpp b/lib/sai_redis_interfacequery.cpp index f7ee17688866..bac3540208a7 100644 --- a/lib/sai_redis_interfacequery.cpp +++ b/lib/sai_redis_interfacequery.cpp @@ -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; +} diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index 7776149429c3..85d0bdcfcd22 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -4,6 +4,7 @@ #include "swss/logger.h" +#include #include using namespace syncd; @@ -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) { diff --git a/vslib/sai_vs_interfacequery.cpp b/vslib/sai_vs_interfacequery.cpp index 42b9fa468921..8dac01d437a0 100644 --- a/vslib/sai_vs_interfacequery.cpp +++ b/vslib/sai_vs_interfacequery.cpp @@ -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; +}