Skip to content

Commit 0b1dee6

Browse files
authored
Merge branch 'sonic-net:master' into SAI_DBG_GEN_DUMP_support
2 parents ffc1a08 + e6ec142 commit 0b1dee6

20 files changed

+371
-28
lines changed

syncd/AttrVersionChecker.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include "AttrVersionChecker.h"
2+
3+
#include "swss/logger.h"
4+
5+
using namespace syncd;
6+
7+
AttrVersionChecker::AttrVersionChecker():
8+
m_enabled(false),
9+
m_saiApiVersion(SAI_VERSION(0,0,0))
10+
{
11+
SWSS_LOG_ENTER();
12+
13+
// empty
14+
}
15+
16+
void AttrVersionChecker::enable(
17+
_In_ bool enable)
18+
{
19+
SWSS_LOG_ENTER();
20+
21+
m_enabled = enable;
22+
}
23+
24+
void AttrVersionChecker::setSaiApiVersion(
25+
_In_ sai_api_version_t version)
26+
{
27+
SWSS_LOG_ENTER();
28+
29+
m_saiApiVersion = version;
30+
}
31+
32+
void AttrVersionChecker::reset()
33+
{
34+
SWSS_LOG_ENTER();
35+
36+
m_visitedAttributes.clear();
37+
}
38+
39+
bool AttrVersionChecker::isSufficientVersion(
40+
_In_ const sai_attr_metadata_t *md)
41+
{
42+
SWSS_LOG_ENTER();
43+
44+
if (md == nullptr)
45+
{
46+
SWSS_LOG_ERROR("md is NULL");
47+
48+
return false;
49+
}
50+
51+
if (!m_enabled)
52+
{
53+
return true;
54+
}
55+
56+
if (SAI_METADATA_HAVE_ATTR_VERSION == 0)
57+
{
58+
// metadata does not contain attr versions, no check will be preformed
59+
return true;
60+
}
61+
62+
// check attr version if metadata have version defined
63+
64+
if (m_saiApiVersion > md->apiversion)
65+
{
66+
// ok, SAI version is bigger than attribute release version
67+
68+
return true;
69+
}
70+
71+
if (m_saiApiVersion < md->apiversion)
72+
{
73+
// skip, SAI version is not sufficient
74+
75+
if (m_visitedAttributes.find(md->attridname) == m_visitedAttributes.end())
76+
{
77+
m_visitedAttributes.insert(md->attridname);
78+
79+
// log only once
80+
81+
SWSS_LOG_WARN("SAI version %lu, not sufficient to discover %s", m_saiApiVersion, md->attridname);
82+
}
83+
84+
return false;
85+
}
86+
87+
// m_saiApiVersion == md->apiversion
88+
89+
if (md->nextrelease == false)
90+
{
91+
// ok, SAI version is equal to attribute version
92+
return true;
93+
}
94+
95+
// next release == true
96+
97+
if (m_visitedAttributes.find(md->attridname) == m_visitedAttributes.end())
98+
{
99+
m_visitedAttributes.insert(md->attridname);
100+
101+
// warn only once
102+
103+
SWSS_LOG_WARN("%s is ment for next release after %lu, will not discover", md->attridname, m_saiApiVersion);
104+
}
105+
106+
return false;
107+
}

syncd/AttrVersionChecker.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
extern "C" {
4+
#include "sai.h"
5+
#include "saimetadata.h"
6+
}
7+
8+
#include <set>
9+
#include <string>
10+
11+
namespace syncd
12+
{
13+
class AttrVersionChecker
14+
{
15+
public:
16+
17+
AttrVersionChecker();
18+
19+
public:
20+
21+
void enable(
22+
_In_ bool enable);
23+
24+
void setSaiApiVersion(
25+
_In_ sai_api_version_t version);
26+
27+
void reset();
28+
29+
bool isSufficientVersion(
30+
_In_ const sai_attr_metadata_t *md);
31+
32+
private:
33+
34+
bool m_enabled;
35+
36+
sai_api_version_t m_saiApiVersion;
37+
38+
std::set<std::string> m_visitedAttributes;
39+
};
40+
}

syncd/CommandLineOptions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ CommandLineOptions::CommandLineOptions()
4444

4545
#endif // SAITHRIFT
4646

47+
m_supportingBulkCounterGroups = "";
48+
49+
m_enableAttrVersionCheck = false;
4750
}
4851

4952
std::string CommandLineOptions::getCommandLineString() const
@@ -67,6 +70,7 @@ std::string CommandLineOptions::getCommandLineString() const
6770
ss << " BreakConfig=" << m_breakConfig;
6871
ss << " WatchdogWarnTimeSpan=" << m_watchdogWarnTimeSpan;
6972
ss << " SupportingBulkCounters=" << m_supportingBulkCounterGroups;
73+
ss << " EnableAttrVersionCheck=" << (m_enableAttrVersionCheck ? "YES" : "NO");
7074

7175
#ifdef SAITHRIFT
7276

syncd/CommandLineOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@ namespace syncd
100100

101101
std::string m_supportingBulkCounterGroups;
102102

103+
bool m_enableAttrVersionCheck;
103104
};
104105
}

syncd/CommandLineOptionsParser.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(
1919
auto options = std::make_shared<CommandLineOptions>();
2020

2121
#ifdef SAITHRIFT
22-
const char* const optstring = "dp:t:g:x:b:B:w:uSUCsz:lrm:h";
22+
const char* const optstring = "dp:t:g:x:b:B:aw:uSUCsz:lrm:h";
2323
#else
24-
const char* const optstring = "dp:t:g:x:b:B:w:uSUCsz:lh";
24+
const char* const optstring = "dp:t:g:x:b:B:aw:uSUCsz:lh";
2525
#endif // SAITHRIFT
2626

2727
while (true)
@@ -43,6 +43,7 @@ std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(
4343
{ "breakConfig", required_argument, 0, 'b' },
4444
{ "watchdogWarnTimeSpan", optional_argument, 0, 'w' },
4545
{ "supportingBulkCounters", required_argument, 0, 'B' },
46+
{ "enableAttrVersionCheck", no_argument, 0, 'a' },
4647
#ifdef SAITHRIFT
4748
{ "rpcserver", no_argument, 0, 'r' },
4849
{ "portmap", required_argument, 0, 'm' },
@@ -138,6 +139,10 @@ std::shared_ptr<CommandLineOptions> CommandLineOptionsParser::parseCommandLine(
138139
options->m_supportingBulkCounterGroups = std::string(optarg);
139140
break;
140141

142+
case 'a':
143+
options->m_enableAttrVersionCheck = true;
144+
break;
145+
141146
case 'h':
142147
printUsage();
143148
exit(EXIT_SUCCESS);
@@ -196,6 +201,8 @@ void CommandLineOptionsParser::printUsage()
196201
std::cout << " Watchdog time span (in microseconds) to watch for execution" << std::endl;
197202
std::cout << " -B --supportingBulkCounters" << std::endl;
198203
std::cout << " Counter groups those support bulk polling" << std::endl;
204+
std::cout << " -a --enableAttrVersionCheck" << std::endl;
205+
std::cout << " Enable attribute SAI version check when performing SAI discovery" << std::endl;
199206

200207
#ifdef SAITHRIFT
201208

syncd/HardReiniter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ HardReiniter::HardReiniter(
1313
_In_ std::shared_ptr<RedisClient> client,
1414
_In_ std::shared_ptr<VirtualOidTranslator> translator,
1515
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
16-
_In_ std::shared_ptr<NotificationHandler> handler):
16+
_In_ std::shared_ptr<NotificationHandler> handler,
17+
_In_ bool checkAttrVersion):
1718
m_vendorSai(sai),
1819
m_translator(translator),
1920
m_client(client),
20-
m_handler(handler)
21+
m_handler(handler),
22+
m_checkAttrVersion(checkAttrVersion)
2123
{
2224
SWSS_LOG_ENTER();
2325

@@ -99,7 +101,8 @@ std::map<sai_object_id_t, std::shared_ptr<syncd::SaiSwitch>> HardReiniter::hardR
99101
m_handler,
100102
m_switchVidToRid.at(kvp.first),
101103
m_switchRidToVid.at(kvp.first),
102-
kvp.second);
104+
kvp.second,
105+
m_checkAttrVersion);
103106

104107
sr->hardReinit();
105108

syncd/HardReiniter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ namespace syncd
2727
_In_ std::shared_ptr<RedisClient> client,
2828
_In_ std::shared_ptr<VirtualOidTranslator> translator,
2929
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
30-
_In_ std::shared_ptr<NotificationHandler> handler);
30+
_In_ std::shared_ptr<NotificationHandler> handler,
31+
_In_ bool checkAttrVersion);
3132

3233
virtual ~HardReiniter();
3334

@@ -59,5 +60,7 @@ namespace syncd
5960
std::shared_ptr<RedisClient> m_client;
6061

6162
std::shared_ptr<NotificationHandler> m_handler;
63+
64+
bool m_checkAttrVersion;
6265
};
6366
}

syncd/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ noinst_LIBRARIES = libSyncd.a libSyncdRequestShutdown.a libMdioIpcClient.a
1717
libSyncd_a_SOURCES = \
1818
AsicOperation.cpp \
1919
AsicView.cpp \
20+
AttrVersionChecker.cpp \
2021
BestCandidateFinder.cpp \
2122
BreakConfig.cpp \
2223
BreakConfigParser.cpp \

syncd/SaiDiscovery.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,31 @@ using namespace syncd;
1919
#define SAI_DISCOVERY_LIST_MAX_ELEMENTS 1024
2020

2121
SaiDiscovery::SaiDiscovery(
22-
_In_ std::shared_ptr<sairedis::SaiInterface> sai):
22+
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
23+
_In_ bool checkAttrVersion):
2324
m_sai(sai)
2425
{
2526
SWSS_LOG_ENTER();
2627

27-
// empty
28+
sai_api_version_t version = SAI_VERSION(0,0,0);
29+
30+
sai_status_t status = m_sai->queryApiVersion(&version);
31+
32+
if (status == SAI_STATUS_SUCCESS)
33+
{
34+
m_attrVersionChecker.enable(checkAttrVersion);
35+
m_attrVersionChecker.setSaiApiVersion(version);
36+
37+
SWSS_LOG_NOTICE("check attr version ENABLED, libsai api version: %lu", version);
38+
}
39+
else
40+
{
41+
m_attrVersionChecker.enable(false);
42+
m_attrVersionChecker.setSaiApiVersion(SAI_API_VERSION);
43+
44+
SWSS_LOG_WARN("failed to obtain libsai api version: %s, will discover all attributes",
45+
sai_serialize_status(status).c_str());
46+
}
2847
}
2948

3049
SaiDiscovery::~SaiDiscovery()
@@ -110,6 +129,11 @@ void SaiDiscovery::discover(
110129

111130
attr.id = md->attrid;
112131

132+
if (!m_attrVersionChecker.isSufficientVersion(md))
133+
{
134+
continue;
135+
}
136+
113137
if (md->attrvaluetype == SAI_ATTR_VALUE_TYPE_OBJECT_ID)
114138
{
115139
if (md->defaultvaluetype == SAI_DEFAULT_VALUE_TYPE_CONST)
@@ -259,6 +283,8 @@ std::set<sai_object_id_t> SaiDiscovery::discover(
259283

260284
m_defaultOidMap.clear();
261285

286+
m_attrVersionChecker.reset();
287+
262288
std::set<sai_object_id_t> discovered_rids;
263289

264290
{

syncd/SaiDiscovery.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "meta/SaiInterface.h"
44

5+
#include "AttrVersionChecker.h"
6+
57
#include <memory>
68
#include <set>
79
#include <map>
@@ -18,7 +20,8 @@ namespace syncd
1820
public:
1921

2022
SaiDiscovery(
21-
_In_ std::shared_ptr<sairedis::SaiInterface> sai);
23+
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
24+
_In_ bool checkAttrVersion);
2225

2326
virtual ~SaiDiscovery();
2427

@@ -61,5 +64,7 @@ namespace syncd
6164
std::shared_ptr<sairedis::SaiInterface> m_sai;
6265

6366
DefaultOidMap m_defaultOidMap;
67+
68+
AttrVersionChecker m_attrVersionChecker;
6469
};
6570
}

syncd/SaiSwitch.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ SaiSwitch::SaiSwitch(
2626
_In_ std::shared_ptr<RedisClient> client,
2727
_In_ std::shared_ptr<VirtualOidTranslator> translator,
2828
_In_ std::shared_ptr<sairedis::SaiInterface> vendorSai,
29-
_In_ bool warmBoot):
29+
_In_ bool warmBoot,
30+
_In_ bool checkAttrVersion):
3031
SaiSwitchInterface(switch_vid, switch_rid),
3132
m_vendorSai(vendorSai),
3233
m_warmBoot(warmBoot),
3334
m_translator(translator),
34-
m_client(client)
35+
m_client(client),
36+
m_checkAttrVersion(checkAttrVersion)
3537
{
3638
SWSS_LOG_ENTER();
3739

@@ -661,7 +663,7 @@ void SaiSwitch::helperDiscover()
661663
{
662664
SWSS_LOG_ENTER();
663665

664-
SaiDiscovery sd(m_vendorSai);
666+
SaiDiscovery sd(m_vendorSai, m_checkAttrVersion);
665667

666668
m_discovered_rids = sd.discover(m_switch_rid);
667669

@@ -952,7 +954,7 @@ void SaiSwitch::onPostPortCreate(
952954
{
953955
SWSS_LOG_ENTER();
954956

955-
SaiDiscovery sd(m_vendorSai);
957+
SaiDiscovery sd(m_vendorSai, m_checkAttrVersion);
956958

957959
auto discovered = sd.discover(port_rid);
958960

0 commit comments

Comments
 (0)