Skip to content

Commit

Permalink
Ignore order when compare QOS MAP list entries (sonic-net#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Nov 7, 2018
1 parent e8df347 commit d1e26c3
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
3 changes: 3 additions & 0 deletions meta/sai_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ std::string sai_serialize_l2mc_entry_type(
std::string sai_serialize_ipmc_entry_type(
_In_ const sai_ipmc_entry_type_t type);

std::string sai_serialize_qos_map_item(
_In_ const sai_qos_map_t& qosmap);

// serialize ntf

std::string sai_serialize_fdb_event_ntf(
Expand Down
13 changes: 13 additions & 0 deletions meta/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,19 @@ json sai_serialize_qos_map(
return j;
}

std::string sai_serialize_qos_map_item(
_In_ const sai_qos_map_t& qosmap)
{
SWSS_LOG_ENTER();

json j;

j["key"] = sai_serialize_qos_map_params(qosmap.key);
j["value"] = sai_serialize_qos_map_params(qosmap.value);;

return j.dump();
}

std::string sai_serialize_qos_map_list(
_In_ const sai_qos_map_list_t& qosmap,
_In_ bool countOnly)
Expand Down
59 changes: 59 additions & 0 deletions syncd/syncd_applyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,55 @@ bool hasEqualObjectList(
return true;
}

/**
* @brief Compare qos map list attributes order insensitive.
*
* @param current Current object qos map attribute.
* @param temporary Temporary object qos map attribute.
*
* @return True if attributes are equal, false otherwise.
*/
bool hasEqualQosMapList(
_In_ const std::shared_ptr<const SaiAttr> &current,
_In_ const std::shared_ptr<const SaiAttr> &temporary)
{
SWSS_LOG_ENTER();

auto c = current->getSaiAttr()->value.qosmap;
auto t = temporary->getSaiAttr()->value.qosmap;

if (c.count != t.count)
return false;

if (c.list == NULL || t.list == NULL)
return false;

std::vector<std::string> citems;
std::vector<std::string> titems;

for (uint32_t i = 0; i < c.count; i++)
{
citems.push_back(sai_serialize_qos_map_item(c.list[i]));
titems.push_back(sai_serialize_qos_map_item(t.list[i]));
}

std::sort(citems.begin(), citems.end());
std::sort(titems.begin(), titems.end());

for (uint32_t i = 0; i < c.count; i++)
{
if (citems.at(i) != titems.at(i))
{
return false;
}
}

SWSS_LOG_NOTICE("qos map are equal, but has different order");

// all items in both attributes are equal
return true;
}

/**
* @brief Check if current and temporary object has
* the same attribute and attribute has the same value on both.
Expand Down Expand Up @@ -2117,6 +2166,16 @@ bool hasEqualAttribute(
return true;
}

if (currentAttr->getAttrMetadata()->attrvaluetype == SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST)
{
/*
* In case of qos map list, order of list does not matter, so
* compare only entries.
*/

return hasEqualQosMapList(currentAttr, temporaryAttr);
}

if (currentAttr->isObjectIdAttr() == false)
{
/*
Expand Down
9 changes: 9 additions & 0 deletions tests/brcm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,18 @@ sub test_brcm_lag_no_members
play "lag_no_members.rec", 0;
}

sub test_brcm_qos_map_order
{
fresh_start;

# we expect no asic operation on qos maps that are the same but different order

play "qos_map_order.rec", 0;
}

# RUN TESTS

test_brcm_qos_map_order;
test_brcm_lag_no_members;
test_brcm_rif_loopback;
test_brcm_hostif;
Expand Down
Loading

0 comments on commit d1e26c3

Please sign in to comment.