Skip to content

Commit

Permalink
Revert "[meta] Use metadata to check port notification port_id type (#…
Browse files Browse the repository at this point in the history
…1469)"

This reverts commit 29a8f86.
  • Loading branch information
yxieca committed Dec 5, 2024
1 parent 0383740 commit 064a3a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 80 deletions.
67 changes: 16 additions & 51 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#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 @@ -6696,14 +6694,24 @@ void Meta::meta_sai_on_port_state_change_single(

auto ot = objectTypeQuery(data.port_id);

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

if (!valid)
switch (ot)
{
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());
// 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;
}

if (valid && !m_oids.objectReferenceExists(data.port_id))
Expand Down Expand Up @@ -7123,46 +7131,3 @@ 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;
}
5 changes: 0 additions & 5 deletions meta/Meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,6 @@ 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
24 changes: 0 additions & 24 deletions unittest/meta/TestMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include <gtest/gtest.h>

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

#include <memory>

#define VLAN_ID 2
Expand Down Expand Up @@ -1852,25 +1850,3 @@ TEST(Meta, remove_prefix_compression_entry)

EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, sai.remove(e));
}

TEST(Meta, isPortObjectIdValid)
{
EXPECT_EQ(Meta::isPortObjectIdValid(SAI_OBJECT_TYPE_PORT), true);
EXPECT_EQ(Meta::isPortObjectIdValid(SAI_OBJECT_TYPE_BRIDGE_PORT), true);
EXPECT_EQ(Meta::isPortObjectIdValid(SAI_OBJECT_TYPE_LAG), true);

EXPECT_EQ(Meta::isPortObjectIdValid(SAI_OBJECT_TYPE_TUNNEL),false);
EXPECT_EQ(Meta::isPortObjectIdValid(SAI_OBJECT_TYPE_NULL), false);
EXPECT_EQ(Meta::isPortObjectIdValid(SAI_OBJECT_TYPE_VLAN), false);
}

TEST(Meta, getValidPortObjectTypes)
{
auto v = Meta::getValidPortObjectTypes();

EXPECT_EQ(v.size(), 3);

auto s = boost::algorithm::join(v, ",");

EXPECT_EQ(s, "PORT,LAG,BRIDGE_PORT");
}

0 comments on commit 064a3a8

Please sign in to comment.