diff --git a/vslib/inc/SwitchStateBase.h b/vslib/inc/SwitchStateBase.h index b41ab1200..443e5a00a 100644 --- a/vslib/inc/SwitchStateBase.h +++ b/vslib/inc/SwitchStateBase.h @@ -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 &objects); + + bool dumpObject( + _In_ const sai_object_id_t object_id, + _Out_ std::vector &attrs); + protected: constexpr static const int maxDebugCounters = 32; diff --git a/vslib/src/SwitchStateBase.cpp b/vslib/src/SwitchStateBase.cpp index 5cc210c75..a5f9f73f1 100644 --- a/vslib/src/SwitchStateBase.cpp +++ b/vslib/src/SwitchStateBase.cpp @@ -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 &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 &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; +}