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

Revert "Revert back to SAI version 1 15 (#1481)" #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3154,6 +3156,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 @@ -6675,24 +6696,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 @@ -7112,3 +7123,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 @@ -315,6 +315,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 @@ -563,6 +568,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
17 changes: 17 additions & 0 deletions meta/SaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,20 @@ sai_status_t SaiInterface::clearStats(

return SAI_STATUS_NOT_IMPLEMENTED;
}

std::shared_ptr<SaiOptions> SaiInterface::getOptions(
_In_ const std::string& key)
{
SWSS_LOG_ENTER();

return m_optionsMap[key];
}

void SaiInterface::setOptions(
_In_ const std::string& key,
_In_ std::shared_ptr<SaiOptions> options)
{
SWSS_LOG_ENTER();

m_optionsMap[key] = options;
}
19 changes: 19 additions & 0 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ extern "C" {
#include "saimetadata.h"
}

#include "SaiOptions.h"

#include <map>
#include <memory>
#include <string>

#define SAIREDIS_DECLARE_EVERY_ENTRY(_X) \
SAI_METADATA_DECLARE_EVERY_ENTRY(_X)

Expand Down Expand Up @@ -340,5 +346,18 @@ namespace sairedis

virtual sai_log_level_t logGet(
_In_ sai_api_t api);

public: // non SAI API - options helper

std::shared_ptr<SaiOptions> getOptions(
_In_ const std::string& key);

void setOptions(
_In_ const std::string& key,
_In_ std::shared_ptr<SaiOptions> options);

private:

std::map<std::string, std::shared_ptr<SaiOptions>> m_optionsMap;
};
}
11 changes: 11 additions & 0 deletions meta/SaiOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace sairedis
{
class SaiOptions
{
public:

virtual ~SaiOptions() = default;
};
}
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 @@ -2670,6 +2684,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 @@ -4459,6 +4477,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 @@ -4910,6 +4941,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 @@ -443,6 +446,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;
}
Loading