SAI
SAI copied to clipboard
Get vendor specific version information from SAI
Hello,
I would like to be able to drop constructs like #ifdef BRCMSAI and be able to deduce from the SAI library what vendor workarounds to apply. I did not find any sai_query_api_vendor or similar.
Are there any current ways of doing this, and if not, are you open to the idea of adding one?
i think SAI was designed to be generic interface and not vendor specific, currently there is no specific interface to query underlying vendoer, and we should not specifically design any macros for that
what is your motivation to have workaroudns for specific vendor ? if some apis are not implemented you will get not implemented or not supported error code and this should be your information
Happy to hear! I agree that not relying on the vendor is a good stance to take and try to hold on to.
In my case it is only for debugging, so having something like sai_query_api_vendor_version that outputs an opaque string would suffice - like bsv (e.g. BRCM SAI ver: [8.4.0.2], OCP SAI ver: [1.11.0], SDK ver: [sdk-6.5.27] CANCUN ver: [06.04.01]).
Right now I have to resort to vendor-specific ways to get that information for my test logs, which ironically requires me to care about what module I load so I can query its non-SAI API to get the data.
That said, I based some debugging code on saithrift from this very repo and it used ifdef macros per vendor.
E.g.: https://github.com/opencomputeproject/SAI/blob/e2a3d4487c93f1e0f45cd4c0ab85f07e72c75a18/test/saithrift/src/saiserver.cpp#L457-L460
In my case I just removed that particular ifdef and always spawned a debug shell, but if it is indeed the case that SAI tries to be vendor agnostic maybe we should remove those from the code people otherwise use as references.
SAI headers are generic, and there will be no vendor specific macro here, that will let you decide which SAI vendor is internally, and at SAI headers this is even impossible, since there are no vendor specific headers here. investigate SAI_SWITCH_ATTR_SWITCH_SHELL_ENABLE attribute.
We could discuss to introduce vendor string api or something like this that will return something like that, or have an enum in which will return actual vendor as unique integer, but this is broader discussion at SAI community meeting @rlhui
For reference, this is how I currently get the data I want in my logs if anyone wants something similar:
typedef struct {
const char* sai_api_version;
const char* bcm_sai_version;
const char* build_release;
/* these are only populated after create_switch */
const char* cancun_version;
const char* npl_version;
} brcm_sai_version_t;
extern "C" {
extern brcm_sai_version_t* brcm_sai_version_get(brcm_sai_version_t*) __attribute__((weak));
extern void ifcs_get_version(int* major, int* minor, int* rev) __attribute__((weak));
}
/* ... */
{
sai_api_version_t version;
if (sai_query_api_version(&version) == SAI_STATUS_SUCCESS) {
int major = version / 10000;
int minor = (version - major * 10000) / 100;
int rev = version - major * 10000 - minor * 100;
printf("================================\n");
printf(" Loaded SAI version %d.%d.%d\n", major, minor, rev);
}
if (brcm_sai_version_get != NULL) {
brcm_sai_version_t brcm_version;
brcm_sai_version_get(&brcm_version);
printf(
"\n Broadcom SAI detected\n SAI API version: %s\n BRCM SAI version: %s\n Build release: %s\n",
brcm_version.sai_api_version,
brcm_version.bcm_sai_version,
brcm_version.build_release);
}
if (ifcs_get_version != NULL) {
int major = 0;
int minor = 0;
int rev = 0;
ifcs_get_version(&major, &minor, &rev);
printf(
"\n Innovium SAI detected\n IFCS version: %d.%d.%d\n",
major, minor, rev);
}
printf("================================\n");
}
Output:
================================
Loaded SAI version 1.11.0
Innovium SAI detected
IFCS version: 0.15.4
================================
================================
Loaded SAI version 1.11.0
Broadcom SAI detected
SAI API version: 8.4.0.2
BRCM SAI version: 1.11.0
Build release: sdk-6.5.27
================================