Skip to content

Commit

Permalink
Fix swss enter
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Dec 17, 2024
1 parent a9767a4 commit fdaa992
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 48 deletions.
1 change: 1 addition & 0 deletions tests/aspellcheck.pl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ sub RunAspell
next if $file =~ m!/python/.+wrap.cpp!;
next if $file =~ m!/pyext/.+wrap.cpp!;
next if $file =~ m!sai_(redis|proxy|vs|stub).cpp!;
next if $file =~ m!vslib/vpp/!;

my $data = ReadFile $file;

Expand Down
2 changes: 2 additions & 0 deletions vslib/vpp/BitResourcePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace saivs
}
~BitResourcePool() = default;
int alloc() {
SWSS_LOG_ENTER();
for (uint16_t i = 0; i < resource_size; i++) {
if ((resource_bitmap[i / 8] & (1 << (i % 8))) == 0) {
resource_bitmap[i / 8] |= (uint8_t)(1 << (i % 8));
Expand All @@ -27,6 +28,7 @@ namespace saivs
return -1;
}
void free(uint32_t index) {
SWSS_LOG_ENTER();
if (index >= resource_size + base_index || index < base_index) {
throw std::invalid_argument("Invalid index");
}
Expand Down
28 changes: 28 additions & 0 deletions vslib/vpp/SaiObjectDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ std::map<sai_object_type_t, std::vector<SaiChildRelation>> sai_child_relation_de
static std::vector<std::string>
get_parent_oids(const sai_attribute_value_t *attr_val, const SaiChildRelation& child_def)
{
SWSS_LOG_ENTER();

std::vector<std::string> parent_ids;

switch (child_def.child_link_attr_type) {
Expand All @@ -58,6 +60,8 @@ get_parent_oids(const sai_attribute_value_t *attr_val, const SaiChildRelation& c
static std::vector<std::string>
get_parent_oids(SwitchVpp* switch_db, sai_object_type_t child_type, const std::string& child_oid, const SaiChildRelation& child_def)
{
SWSS_LOG_ENTER();

std::vector<std::string> parent_ids;
sai_status_t status;
sai_attribute_t attr;
Expand Down Expand Up @@ -99,6 +103,8 @@ SaiObjectDB::create_or_update(
_In_ const sai_attribute_t *attr_list,
_In_ bool is_create)
{
SWSS_LOG_ENTER();

sai_status_t status;
auto child_def_it = sai_child_relation_defs.find(object_type);
if (child_def_it == sai_child_relation_defs.end()) {
Expand Down Expand Up @@ -190,6 +196,8 @@ SaiObjectDB::remove_child_from_parent(
_In_ const std::string& id,
_In_ const SaiChildRelation& child_def)
{
SWSS_LOG_ENTER();

std::vector<std::string> parent_ids = get_parent_oids(m_switch_db, object_type, id, child_def);
auto sai_parents = m_sai_parent_objs[child_def.parent_type];
for (auto parent_id: parent_ids) {
Expand Down Expand Up @@ -225,6 +233,8 @@ SaiObjectDB::remove(
_In_ sai_object_type_t object_type,
_In_ const std::string& id)
{
SWSS_LOG_ENTER();

//remove parent object
auto sai_parent_type_it = m_sai_parent_objs.find(object_type);
if (sai_parent_type_it != m_sai_parent_objs.end()) {
Expand Down Expand Up @@ -257,6 +267,8 @@ SaiObjectDB::get(
_In_ sai_object_type_t object_type,
_In_ const std::string& id)
{
SWSS_LOG_ENTER();

sai_status_t status;
sai_attribute_t attr;
//first check if the object is a stored SaiDBObject
Expand Down Expand Up @@ -285,6 +297,8 @@ SaiObject::get_linked_object(
_In_ sai_object_type_t linked_object_type,
_In_ sai_attr_id_t link_attr_id) const
{
SWSS_LOG_ENTER();

sai_status_t status;
sai_attribute_t attr;
std::string linked_obj_id;
Expand All @@ -305,6 +319,8 @@ SaiObject::get_linked_objects(
_In_ sai_object_type_t linked_object_type,
_In_ sai_attr_id_t link_attr_id) const
{
SWSS_LOG_ENTER();

sai_status_t status;
sai_attribute_t attr;
std::string linked_obj_id;
Expand All @@ -331,6 +347,8 @@ SaiObject::get_linked_objects(
const char*
SaiObject::get_attr_name(_In_ sai_attr_id_t attr_id) const
{
SWSS_LOG_ENTER();

auto meta = sai_metadata_get_attr_metadata(m_type, attr_id);
if (meta == NULL) {
return "unknown";
Expand All @@ -342,6 +360,8 @@ SaiObject::get_attr_name(_In_ sai_attr_id_t attr_id) const
sai_status_t
SaiObject::get_mandatory_attr(sai_attribute_t &attr) const
{
SWSS_LOG_ENTER();

auto status = get_attr(attr);
if (SAI_STATUS_SUCCESS != status) {
SWSS_LOG_ERROR("Failed to get attribute %s from object %s", get_attr_name(attr.id), m_id.c_str());
Expand All @@ -352,6 +372,8 @@ SaiObject::get_mandatory_attr(sai_attribute_t &attr) const
sai_status_t
SaiCachedObject::get_attr(sai_attribute_t &attr) const
{
SWSS_LOG_ENTER();

for (uint32_t ii = 0; ii < m_attr_count; ii++) {
if (m_attr_list[ii].id == attr.id) {
return transfer_attributes(m_type, 1, &(m_attr_list[ii]), &attr, false);
Expand All @@ -363,6 +385,8 @@ SaiCachedObject::get_attr(sai_attribute_t &attr) const
sai_status_t
SaiDBObject::get_attr(sai_attribute_t &attr) const
{
SWSS_LOG_ENTER();

/* we could make a copy of all the attributes and cache in this object*/
return m_switch_db->get(m_type, m_id, 1, &attr);
}
Expand All @@ -371,6 +395,8 @@ SaiModDBObject::SaiModDBObject(SwitchVpp* switch_db, sai_object_type_t type, con
uint32_t attr_count, const sai_attribute_t *attr_list) :
SaiObject(switch_db, type, id), m_attr_count(attr_count), m_attr_list(attr_list)
{
SWSS_LOG_ENTER();

m_sai_db_obj = switch_db->get_sai_object(type, id);
if (!m_sai_db_obj) {
SWSS_LOG_ERROR("SaiModDBObject: the object is not found in switch_db %s", id.c_str());
Expand All @@ -380,6 +406,8 @@ SaiModDBObject::SaiModDBObject(SwitchVpp* switch_db, sai_object_type_t type, con
sai_status_t
SaiModDBObject::get_attr(sai_attribute_t &attr) const
{
SWSS_LOG_ENTER();

for (uint32_t ii = 0; ii < m_attr_count; ii++) {
if (m_attr_list[ii].id == attr.id) {
return transfer_attributes(m_type, 1, &(m_attr_list[ii]), &attr, false);
Expand Down
5 changes: 5 additions & 0 deletions vslib/vpp/SaiObjectDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ namespace saivs
* @return A pointer to the map of child objects, or nullptr if no child objects of the specified type exist.
*/
const std::unordered_map<std::string, std::shared_ptr<SaiObject>>* get_child_objs(sai_object_type_t child_type) const {
SWSS_LOG_ENTER();
auto it = m_child_map.find(child_type);
if (it != m_child_map.end()) {
return &(it->second);
Expand All @@ -160,6 +161,7 @@ namespace saivs
* @param entry The child object to be added.
*/
void add_child(const std::shared_ptr<SaiObject> entry) {
SWSS_LOG_ENTER();
if (entry) {
m_child_map[entry->get_type()][entry->get_id()] = entry;
}
Expand All @@ -174,6 +176,7 @@ namespace saivs
* @param id The ID of the child object.
*/
void remove_child(sai_object_type_t child_type, const std::string& id) {
SWSS_LOG_ENTER();
auto child_map_it = m_child_map.find(child_type);
if (child_map_it != m_child_map.end()) {
auto child_map_per_type_it = child_map_it->second.find(id);
Expand Down Expand Up @@ -206,10 +209,12 @@ namespace saivs
sai_status_t get_attr(_Inout_ sai_attribute_t &attr) const override;

std::shared_ptr<SaiDBObject> get_db_obj() const {
SWSS_LOG_ENTER();
return m_sai_db_obj;
}

const std::unordered_map<std::string, std::shared_ptr<SaiObject>>* get_child_objs(sai_object_type_t child_type) const {
SWSS_LOG_ENTER();
if (m_sai_db_obj) {
return m_sai_db_obj->get_child_objs(child_type);
} else {
Expand Down
2 changes: 2 additions & 0 deletions vslib/vpp/SwitchVpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ bool SwitchVpp::port_to_hwifname(
void SwitchVpp::setPortStats(
_In_ sai_object_id_t oid)
{
SWSS_LOG_ENTER();

std::map<sai_stat_id_t, uint64_t> stats;

std::string if_name;
Expand Down
Loading

0 comments on commit fdaa992

Please sign in to comment.