Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into SAI_DBG_GEN_DUMP_support
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramd authored Nov 25, 2024
2 parents ac9f2a2 + e6ec142 commit b7bdc69
Show file tree
Hide file tree
Showing 30 changed files with 621 additions and 49 deletions.
86 changes: 70 additions & 16 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <inttypes.h>

#include <boost/algorithm/string/join.hpp>

#include <set>

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

sai_status_t Meta::meta_sai_validate_prefix_compression_entry(
_In_ const sai_prefix_compression_entry_t* prefix_compression_entry,
_In_ bool create,
_In_ bool get)
{
SWSS_LOG_ENTER();

if (prefix_compression_entry == NULL)
{
SWSS_LOG_ERROR("prefix_compression_entry pointer is NULL");

return SAI_STATUS_INVALID_PARAMETER;
}

// TODO FIX ME

return SAI_STATUS_NOT_IMPLEMENTED;
}

sai_status_t Meta::meta_generic_validation_create(
_In_ const sai_object_meta_key_t& meta_key,
_In_ sai_object_id_t switch_id,
Expand Down Expand Up @@ -6683,24 +6704,14 @@ void Meta::meta_sai_on_port_state_change_single(

auto ot = objectTypeQuery(data.port_id);

bool valid = false;
bool valid = isPortObjectIdValid(ot);

switch (ot)
if (!valid)
{
// TODO hardcoded types, must advance SAI repository commit to get metadata for this
case SAI_OBJECT_TYPE_PORT:
case SAI_OBJECT_TYPE_BRIDGE_PORT:
case SAI_OBJECT_TYPE_LAG:

valid = true;
break;

default:

SWSS_LOG_ERROR("data.port_id %s has unexpected type: %s, expected PORT, BRIDGE_PORT or LAG",
sai_serialize_object_id(data.port_id).c_str(),
sai_serialize_object_type(ot).c_str());
break;
SWSS_LOG_ERROR("data.port_id %s has unexpected type: %s, expected: %s",
sai_serialize_object_id(data.port_id).c_str(),
sai_serialize_object_type(ot).c_str(),
boost::algorithm::join(getValidPortObjectTypes(), ",").c_str());
}

if (valid && !m_oids.objectReferenceExists(data.port_id))
Expand Down Expand Up @@ -7120,3 +7131,46 @@ void Meta::populate(
}
}
}

bool Meta::isPortObjectIdValid(
_In_ sai_object_type_t object_type)
{
SWSS_LOG_ENTER();

auto members = sai_metadata_struct_members_sai_port_oper_status_notification_t;

for (size_t i = 0; members[i]; i++)
{
auto* mb = members[i];

if (mb->membername != std::string("port_id"))
continue;

for (size_t idx = 0; idx < mb->allowedobjecttypeslength; idx++)
{
if (mb->allowedobjecttypes[idx] == object_type)
return true;
}

return false;
}

SWSS_LOG_THROW("port_id member not found on sai_port_oper_status_notification");
}

std::vector<std::string> Meta::getValidPortObjectTypes()
{
SWSS_LOG_ENTER();

auto md = sai_metadata_enum_sai_object_type_t;

std::vector<std::string> v;

for (size_t i = 0; i < md.valuescount; i++)
{
if (isPortObjectIdValid((sai_object_type_t)md.values[i]))
v.push_back(md.valuesshortnames[i]);
}

return v;
}
10 changes: 10 additions & 0 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ namespace saimeta
static bool is_ipv6_mask_valid(
_In_ const uint8_t* mask);

static bool isPortObjectIdValid(
_In_ sai_object_type_t object_type);

static std::vector<std::string> getValidPortObjectTypes();

private: // unit tests helpers

bool meta_unittests_get_and_erase_set_readonly_flag(
Expand Down Expand Up @@ -566,6 +571,11 @@ namespace saimeta
_In_ bool create,
_In_ bool get = false);

sai_status_t meta_sai_validate_prefix_compression_entry(
_In_ const sai_prefix_compression_entry_t* prefix_compression_entry,
_In_ bool create,
_In_ bool get = false);

public:

/*
Expand Down
35 changes: 35 additions & 0 deletions meta/SaiSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,20 @@ std::string sai_serialize_meter_bucket_entry(
return j.dump();
}

std::string sai_serialize_prefix_compression_entry(
_In_ const sai_prefix_compression_entry_t &prefix_compression_entry)
{
SWSS_LOG_ENTER();

json j;

j["switch_id"] = sai_serialize_object_id(prefix_compression_entry.switch_id);
j["prefix_table_id"] = sai_serialize_object_id(prefix_compression_entry.prefix_table_id);
j["prefix"] = sai_serialize_ip_prefix(prefix_compression_entry.prefix);

return j.dump();
}

std::string sai_serialize_flow_entry(
_In_ const sai_flow_entry_t &flow_entry)
{
Expand Down Expand Up @@ -2662,6 +2676,10 @@ static bool sai_serialize_object_entry(
key = sai_serialize_mcast_fdb_entry(key_entry.mcast_fdb_entry);
return true;

case SAI_OBJECT_TYPE_PREFIX_COMPRESSION_ENTRY:
key = sai_serialize_prefix_compression_entry(key_entry.prefix_compression_entry);
return true;

default:
return false;
}
Expand Down Expand Up @@ -4451,6 +4469,19 @@ void sai_deserialize_meter_bucket_entry(
sai_deserialize_number(j["meter_class"], meter_bucket_entry.meter_class);
}

void sai_deserialize_prefix_compression_entry(
_In_ const std::string& s,
_Out_ sai_prefix_compression_entry_t& prefix_compression_entry)
{
SWSS_LOG_ENTER();

json j = json::parse(s);

sai_deserialize_object_id(j["switch_id"], prefix_compression_entry.switch_id);
sai_deserialize_object_id(j["prefix_table_id"], prefix_compression_entry.prefix_table_id);
sai_deserialize_ip_prefix(j["prefix"], prefix_compression_entry.prefix);
}

void sai_deserialize_flow_entry(
_In_ const std::string& s,
_Out_ sai_flow_entry_t &flow_entry)
Expand Down Expand Up @@ -4902,6 +4933,10 @@ bool sai_deserialize_object_entry(
sai_deserialize_mcast_fdb_entry(object_id, meta_key.objectkey.key.mcast_fdb_entry);
return true;

case SAI_OBJECT_TYPE_PREFIX_COMPRESSION_ENTRY:
sai_deserialize_prefix_compression_entry(object_id, meta_key.objectkey.key.prefix_compression_entry);
return true;

default:
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions meta/sai_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ std::string sai_serialize_fdb_entry(
std::string sai_serialize_meter_bucket_entry(
_In_ const sai_meter_bucket_entry_t &meter_bucket_entry);

std::string sai_serialize_prefix_compression_entry(
_In_ const sai_prefix_compression_entry_t &prefix_compression_entry);

std::string sai_serialize_flow_entry(
_In_ const sai_flow_entry_t &flow_entry);

Expand Down Expand Up @@ -440,6 +443,10 @@ void sai_deserialize_meter_bucket_entry(
_In_ const std::string& s,
_Out_ sai_meter_bucket_entry_t& meter_bucket_entry);

void sai_deserialize_prefix_compression_entry(
_In_ const std::string& s,
_Out_ sai_prefix_compression_entry_t& prefix_compression_entry);

void sai_deserialize_flow_entry(
_In_ const std::string& s,
_Out_ sai_flow_entry_t &flow_entry);
Expand Down
107 changes: 107 additions & 0 deletions syncd/AttrVersionChecker.cpp
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;
}
40 changes: 40 additions & 0 deletions syncd/AttrVersionChecker.h
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;
};
}
4 changes: 4 additions & 0 deletions syncd/CommandLineOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ CommandLineOptions::CommandLineOptions()

#endif // SAITHRIFT

m_supportingBulkCounterGroups = "";

m_enableAttrVersionCheck = false;
}

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

#ifdef SAITHRIFT

Expand Down
1 change: 1 addition & 0 deletions syncd/CommandLineOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ namespace syncd

std::string m_supportingBulkCounterGroups;

bool m_enableAttrVersionCheck;
};
}
Loading

0 comments on commit b7bdc69

Please sign in to comment.