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

Get vendor specific version information from SAI #1972

Open
bluecmd opened this issue Mar 1, 2024 · 5 comments
Open

Get vendor specific version information from SAI #1972

bluecmd opened this issue Mar 1, 2024 · 5 comments

Comments

@bluecmd
Copy link
Contributor

bluecmd commented Mar 1, 2024

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?

@kcudnik
Copy link
Collaborator

kcudnik commented Mar 1, 2024

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

@kcudnik
Copy link
Collaborator

kcudnik commented Mar 1, 2024

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

@bluecmd
Copy link
Contributor Author

bluecmd commented Mar 1, 2024

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.:

#ifdef BRCMSAI
std::thread bcm_diag_shell_thread = std::thread(sai_diag_shell);
bcm_diag_shell_thread.detach();
#endif

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.

@kcudnik
Copy link
Collaborator

kcudnik commented Mar 1, 2024

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

@bluecmd bluecmd changed the title Get vendor specific information from SAI Get vendor specific version information from SAI Mar 1, 2024
@bluecmd
Copy link
Contributor Author

bluecmd commented Mar 1, 2024

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
================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants