Skip to content

Commit

Permalink
Add helper functions, findObjects and dumpObject (sonic-net#716)
Browse files Browse the repository at this point in the history
findObjects: Find out objects that have expected attribute
dumpObject: dump object attributes to vector<sai_attributes_t> according to specified object id

Signed-off-by: Ze Gan <ganze718@gmail.com>
  • Loading branch information
Pterosaur authored Nov 20, 2020
1 parent e713473 commit 65de898
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
11 changes: 11 additions & 0 deletions vslib/inc/SwitchStateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@ namespace saivs
void send_fdb_event_notification(
_In_ const sai_fdb_event_notification_data_t& data);

protected:

void findObjects(
_In_ sai_object_type_t object_type,
_In_ const sai_attribute_t &expect,
_Out_ std::vector<sai_object_id_t> &objects);

bool dumpObject(
_In_ const sai_object_id_t object_id,
_Out_ std::vector<sai_attribute_t> &attrs);

protected:

constexpr static const int maxDebugCounters = 32;
Expand Down
49 changes: 49 additions & 0 deletions vslib/src/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2661,3 +2661,52 @@ sai_status_t SwitchStateBase::refresh_system_port_list(

return SAI_STATUS_SUCCESS;
}

void SwitchStateBase::findObjects(
_In_ sai_object_type_t object_type,
_In_ const sai_attribute_t &expect,
_Out_ std::vector<sai_object_id_t> &objects)
{
SWSS_LOG_ENTER();

objects.clear();

SaiAttrWrap expect_wrap(object_type, &expect);

for (auto &obj : m_objectHash.at(object_type))
{
auto attr_itr = obj.second.find(expect_wrap.getAttrMetadata()->attridname);

if (attr_itr != obj.second.end()
&& attr_itr->second->getAttrStrValue() == expect_wrap.getAttrStrValue())
{
sai_object_id_t object_id;
sai_deserialize_object_id(obj.first, object_id);
objects.push_back(object_id);
}
}
}

bool SwitchStateBase::dumpObject(
_In_ const sai_object_id_t object_id,
_Out_ std::vector<sai_attribute_t> &attrs)
{
SWSS_LOG_ENTER();

attrs.clear();

auto &objs = m_objectHash.at(objectTypeQuery(object_id));
auto obj = objs.find(sai_serialize_object_id(object_id));

if (obj == objs.end())
{
return false;
}

for (auto &attr : obj->second)
{
attrs.push_back(*attr.second->getAttr());
}

return true;
}

0 comments on commit 65de898

Please sign in to comment.