Skip to content

Commit b7bdc69

Browse files
authored
Merge branch 'sonic-net:master' into SAI_DBG_GEN_DUMP_support
2 parents ac9f2a2 + e6ec142 commit b7bdc69

30 files changed

+621
-49
lines changed

meta/Meta.cpp

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <inttypes.h>
1010

11+
#include <boost/algorithm/string/join.hpp>
12+
1113
#include <set>
1214

1315
// TODO add validation for all oids belong to the same switch
@@ -3162,6 +3164,25 @@ sai_status_t Meta::meta_sai_validate_meter_bucket_entry(
31623164
return SAI_STATUS_NOT_IMPLEMENTED;
31633165
}
31643166

3167+
sai_status_t Meta::meta_sai_validate_prefix_compression_entry(
3168+
_In_ const sai_prefix_compression_entry_t* prefix_compression_entry,
3169+
_In_ bool create,
3170+
_In_ bool get)
3171+
{
3172+
SWSS_LOG_ENTER();
3173+
3174+
if (prefix_compression_entry == NULL)
3175+
{
3176+
SWSS_LOG_ERROR("prefix_compression_entry pointer is NULL");
3177+
3178+
return SAI_STATUS_INVALID_PARAMETER;
3179+
}
3180+
3181+
// TODO FIX ME
3182+
3183+
return SAI_STATUS_NOT_IMPLEMENTED;
3184+
}
3185+
31653186
sai_status_t Meta::meta_generic_validation_create(
31663187
_In_ const sai_object_meta_key_t& meta_key,
31673188
_In_ sai_object_id_t switch_id,
@@ -6683,24 +6704,14 @@ void Meta::meta_sai_on_port_state_change_single(
66836704

66846705
auto ot = objectTypeQuery(data.port_id);
66856706

6686-
bool valid = false;
6707+
bool valid = isPortObjectIdValid(ot);
66876708

6688-
switch (ot)
6709+
if (!valid)
66896710
{
6690-
// TODO hardcoded types, must advance SAI repository commit to get metadata for this
6691-
case SAI_OBJECT_TYPE_PORT:
6692-
case SAI_OBJECT_TYPE_BRIDGE_PORT:
6693-
case SAI_OBJECT_TYPE_LAG:
6694-
6695-
valid = true;
6696-
break;
6697-
6698-
default:
6699-
6700-
SWSS_LOG_ERROR("data.port_id %s has unexpected type: %s, expected PORT, BRIDGE_PORT or LAG",
6701-
sai_serialize_object_id(data.port_id).c_str(),
6702-
sai_serialize_object_type(ot).c_str());
6703-
break;
6711+
SWSS_LOG_ERROR("data.port_id %s has unexpected type: %s, expected: %s",
6712+
sai_serialize_object_id(data.port_id).c_str(),
6713+
sai_serialize_object_type(ot).c_str(),
6714+
boost::algorithm::join(getValidPortObjectTypes(), ",").c_str());
67046715
}
67056716

67066717
if (valid && !m_oids.objectReferenceExists(data.port_id))
@@ -7120,3 +7131,46 @@ void Meta::populate(
71207131
}
71217132
}
71227133
}
7134+
7135+
bool Meta::isPortObjectIdValid(
7136+
_In_ sai_object_type_t object_type)
7137+
{
7138+
SWSS_LOG_ENTER();
7139+
7140+
auto members = sai_metadata_struct_members_sai_port_oper_status_notification_t;
7141+
7142+
for (size_t i = 0; members[i]; i++)
7143+
{
7144+
auto* mb = members[i];
7145+
7146+
if (mb->membername != std::string("port_id"))
7147+
continue;
7148+
7149+
for (size_t idx = 0; idx < mb->allowedobjecttypeslength; idx++)
7150+
{
7151+
if (mb->allowedobjecttypes[idx] == object_type)
7152+
return true;
7153+
}
7154+
7155+
return false;
7156+
}
7157+
7158+
SWSS_LOG_THROW("port_id member not found on sai_port_oper_status_notification");
7159+
}
7160+
7161+
std::vector<std::string> Meta::getValidPortObjectTypes()
7162+
{
7163+
SWSS_LOG_ENTER();
7164+
7165+
auto md = sai_metadata_enum_sai_object_type_t;
7166+
7167+
std::vector<std::string> v;
7168+
7169+
for (size_t i = 0; i < md.valuescount; i++)
7170+
{
7171+
if (isPortObjectIdValid((sai_object_type_t)md.values[i]))
7172+
v.push_back(md.valuesshortnames[i]);
7173+
}
7174+
7175+
return v;
7176+
}

meta/Meta.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ namespace saimeta
318318
static bool is_ipv6_mask_valid(
319319
_In_ const uint8_t* mask);
320320

321+
static bool isPortObjectIdValid(
322+
_In_ sai_object_type_t object_type);
323+
324+
static std::vector<std::string> getValidPortObjectTypes();
325+
321326
private: // unit tests helpers
322327

323328
bool meta_unittests_get_and_erase_set_readonly_flag(
@@ -566,6 +571,11 @@ namespace saimeta
566571
_In_ bool create,
567572
_In_ bool get = false);
568573

574+
sai_status_t meta_sai_validate_prefix_compression_entry(
575+
_In_ const sai_prefix_compression_entry_t* prefix_compression_entry,
576+
_In_ bool create,
577+
_In_ bool get = false);
578+
569579
public:
570580

571581
/*

meta/SaiSerialize.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,20 @@ std::string sai_serialize_meter_bucket_entry(
975975
return j.dump();
976976
}
977977

978+
std::string sai_serialize_prefix_compression_entry(
979+
_In_ const sai_prefix_compression_entry_t &prefix_compression_entry)
980+
{
981+
SWSS_LOG_ENTER();
982+
983+
json j;
984+
985+
j["switch_id"] = sai_serialize_object_id(prefix_compression_entry.switch_id);
986+
j["prefix_table_id"] = sai_serialize_object_id(prefix_compression_entry.prefix_table_id);
987+
j["prefix"] = sai_serialize_ip_prefix(prefix_compression_entry.prefix);
988+
989+
return j.dump();
990+
}
991+
978992
std::string sai_serialize_flow_entry(
979993
_In_ const sai_flow_entry_t &flow_entry)
980994
{
@@ -2662,6 +2676,10 @@ static bool sai_serialize_object_entry(
26622676
key = sai_serialize_mcast_fdb_entry(key_entry.mcast_fdb_entry);
26632677
return true;
26642678

2679+
case SAI_OBJECT_TYPE_PREFIX_COMPRESSION_ENTRY:
2680+
key = sai_serialize_prefix_compression_entry(key_entry.prefix_compression_entry);
2681+
return true;
2682+
26652683
default:
26662684
return false;
26672685
}
@@ -4451,6 +4469,19 @@ void sai_deserialize_meter_bucket_entry(
44514469
sai_deserialize_number(j["meter_class"], meter_bucket_entry.meter_class);
44524470
}
44534471

4472+
void sai_deserialize_prefix_compression_entry(
4473+
_In_ const std::string& s,
4474+
_Out_ sai_prefix_compression_entry_t& prefix_compression_entry)
4475+
{
4476+
SWSS_LOG_ENTER();
4477+
4478+
json j = json::parse(s);
4479+
4480+
sai_deserialize_object_id(j["switch_id"], prefix_compression_entry.switch_id);
4481+
sai_deserialize_object_id(j["prefix_table_id"], prefix_compression_entry.prefix_table_id);
4482+
sai_deserialize_ip_prefix(j["prefix"], prefix_compression_entry.prefix);
4483+
}
4484+
44544485
void sai_deserialize_flow_entry(
44554486
_In_ const std::string& s,
44564487
_Out_ sai_flow_entry_t &flow_entry)
@@ -4902,6 +4933,10 @@ bool sai_deserialize_object_entry(
49024933
sai_deserialize_mcast_fdb_entry(object_id, meta_key.objectkey.key.mcast_fdb_entry);
49034934
return true;
49044935

4936+
case SAI_OBJECT_TYPE_PREFIX_COMPRESSION_ENTRY:
4937+
sai_deserialize_prefix_compression_entry(object_id, meta_key.objectkey.key.prefix_compression_entry);
4938+
return true;
4939+
49054940
default:
49064941
return false;
49074942
}

meta/sai_serialize.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ std::string sai_serialize_fdb_entry(
7272
std::string sai_serialize_meter_bucket_entry(
7373
_In_ const sai_meter_bucket_entry_t &meter_bucket_entry);
7474

75+
std::string sai_serialize_prefix_compression_entry(
76+
_In_ const sai_prefix_compression_entry_t &prefix_compression_entry);
77+
7578
std::string sai_serialize_flow_entry(
7679
_In_ const sai_flow_entry_t &flow_entry);
7780

@@ -440,6 +443,10 @@ void sai_deserialize_meter_bucket_entry(
440443
_In_ const std::string& s,
441444
_Out_ sai_meter_bucket_entry_t& meter_bucket_entry);
442445

446+
void sai_deserialize_prefix_compression_entry(
447+
_In_ const std::string& s,
448+
_Out_ sai_prefix_compression_entry_t& prefix_compression_entry);
449+
443450
void sai_deserialize_flow_entry(
444451
_In_ const std::string& s,
445452
_Out_ sai_flow_entry_t &flow_entry);

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
}

0 commit comments

Comments
 (0)