forked from sonic-net/sonic-sairedis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[syncd] Add attribute version check feature (sonic-net#1470)
By default disabled. If enabled, it will use SAI metadata and libsai version returned by sai_api_version_query to verify if given attribute during SAI discovery process was introduced in the current libsai version or below that version. This feature is partial solution to this problem: sonic-net/sonic-buildimage#20725, more here: opencomputeproject/SAI#2099
- Loading branch information
Showing
20 changed files
with
371 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include "AttrVersionChecker.h" | ||
|
||
#include "swss/logger.h" | ||
|
||
using namespace syncd; | ||
|
||
AttrVersionChecker::AttrVersionChecker(): | ||
m_enabled(false), | ||
m_saiApiVersion(SAI_VERSION(0,0,0)) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
// empty | ||
} | ||
|
||
void AttrVersionChecker::enable( | ||
_In_ bool enable) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
m_enabled = enable; | ||
} | ||
|
||
void AttrVersionChecker::setSaiApiVersion( | ||
_In_ sai_api_version_t version) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
m_saiApiVersion = version; | ||
} | ||
|
||
void AttrVersionChecker::reset() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
m_visitedAttributes.clear(); | ||
} | ||
|
||
bool AttrVersionChecker::isSufficientVersion( | ||
_In_ const sai_attr_metadata_t *md) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
if (md == nullptr) | ||
{ | ||
SWSS_LOG_ERROR("md is NULL"); | ||
|
||
return false; | ||
} | ||
|
||
if (!m_enabled) | ||
{ | ||
return true; | ||
} | ||
|
||
if (SAI_METADATA_HAVE_ATTR_VERSION == 0) | ||
{ | ||
// metadata does not contain attr versions, no check will be preformed | ||
return true; | ||
} | ||
|
||
// check attr version if metadata have version defined | ||
|
||
if (m_saiApiVersion > md->apiversion) | ||
{ | ||
// ok, SAI version is bigger than attribute release version | ||
|
||
return true; | ||
} | ||
|
||
if (m_saiApiVersion < md->apiversion) | ||
{ | ||
// skip, SAI version is not sufficient | ||
|
||
if (m_visitedAttributes.find(md->attridname) == m_visitedAttributes.end()) | ||
{ | ||
m_visitedAttributes.insert(md->attridname); | ||
|
||
// log only once | ||
|
||
SWSS_LOG_WARN("SAI version %lu, not sufficient to discover %s", m_saiApiVersion, md->attridname); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
// m_saiApiVersion == md->apiversion | ||
|
||
if (md->nextrelease == false) | ||
{ | ||
// ok, SAI version is equal to attribute version | ||
return true; | ||
} | ||
|
||
// next release == true | ||
|
||
if (m_visitedAttributes.find(md->attridname) == m_visitedAttributes.end()) | ||
{ | ||
m_visitedAttributes.insert(md->attridname); | ||
|
||
// warn only once | ||
|
||
SWSS_LOG_WARN("%s is ment for next release after %lu, will not discover", md->attridname, m_saiApiVersion); | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
extern "C" { | ||
#include "sai.h" | ||
#include "saimetadata.h" | ||
} | ||
|
||
#include <set> | ||
#include <string> | ||
|
||
namespace syncd | ||
{ | ||
class AttrVersionChecker | ||
{ | ||
public: | ||
|
||
AttrVersionChecker(); | ||
|
||
public: | ||
|
||
void enable( | ||
_In_ bool enable); | ||
|
||
void setSaiApiVersion( | ||
_In_ sai_api_version_t version); | ||
|
||
void reset(); | ||
|
||
bool isSufficientVersion( | ||
_In_ const sai_attr_metadata_t *md); | ||
|
||
private: | ||
|
||
bool m_enabled; | ||
|
||
sai_api_version_t m_saiApiVersion; | ||
|
||
std::set<std::string> m_visitedAttributes; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,5 +100,6 @@ namespace syncd | |
|
||
std::string m_supportingBulkCounterGroups; | ||
|
||
bool m_enableAttrVersionCheck; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.