Skip to content

Commit d1e26c3

Browse files
authored
Ignore order when compare QOS MAP list entries (#372)
1 parent e8df347 commit d1e26c3

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

meta/sai_serialize.h

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ std::string sai_serialize_l2mc_entry_type(
135135
std::string sai_serialize_ipmc_entry_type(
136136
_In_ const sai_ipmc_entry_type_t type);
137137

138+
std::string sai_serialize_qos_map_item(
139+
_In_ const sai_qos_map_t& qosmap);
140+
138141
// serialize ntf
139142

140143
std::string sai_serialize_fdb_event_ntf(

meta/saiserialize.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,19 @@ json sai_serialize_qos_map(
10651065
return j;
10661066
}
10671067

1068+
std::string sai_serialize_qos_map_item(
1069+
_In_ const sai_qos_map_t& qosmap)
1070+
{
1071+
SWSS_LOG_ENTER();
1072+
1073+
json j;
1074+
1075+
j["key"] = sai_serialize_qos_map_params(qosmap.key);
1076+
j["value"] = sai_serialize_qos_map_params(qosmap.value);;
1077+
1078+
return j.dump();
1079+
}
1080+
10681081
std::string sai_serialize_qos_map_list(
10691082
_In_ const sai_qos_map_list_t& qosmap,
10701083
_In_ bool countOnly)

syncd/syncd_applyview.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,55 @@ bool hasEqualObjectList(
20532053
return true;
20542054
}
20552055

2056+
/**
2057+
* @brief Compare qos map list attributes order insensitive.
2058+
*
2059+
* @param current Current object qos map attribute.
2060+
* @param temporary Temporary object qos map attribute.
2061+
*
2062+
* @return True if attributes are equal, false otherwise.
2063+
*/
2064+
bool hasEqualQosMapList(
2065+
_In_ const std::shared_ptr<const SaiAttr> &current,
2066+
_In_ const std::shared_ptr<const SaiAttr> &temporary)
2067+
{
2068+
SWSS_LOG_ENTER();
2069+
2070+
auto c = current->getSaiAttr()->value.qosmap;
2071+
auto t = temporary->getSaiAttr()->value.qosmap;
2072+
2073+
if (c.count != t.count)
2074+
return false;
2075+
2076+
if (c.list == NULL || t.list == NULL)
2077+
return false;
2078+
2079+
std::vector<std::string> citems;
2080+
std::vector<std::string> titems;
2081+
2082+
for (uint32_t i = 0; i < c.count; i++)
2083+
{
2084+
citems.push_back(sai_serialize_qos_map_item(c.list[i]));
2085+
titems.push_back(sai_serialize_qos_map_item(t.list[i]));
2086+
}
2087+
2088+
std::sort(citems.begin(), citems.end());
2089+
std::sort(titems.begin(), titems.end());
2090+
2091+
for (uint32_t i = 0; i < c.count; i++)
2092+
{
2093+
if (citems.at(i) != titems.at(i))
2094+
{
2095+
return false;
2096+
}
2097+
}
2098+
2099+
SWSS_LOG_NOTICE("qos map are equal, but has different order");
2100+
2101+
// all items in both attributes are equal
2102+
return true;
2103+
}
2104+
20562105
/**
20572106
* @brief Check if current and temporary object has
20582107
* the same attribute and attribute has the same value on both.
@@ -2117,6 +2166,16 @@ bool hasEqualAttribute(
21172166
return true;
21182167
}
21192168

2169+
if (currentAttr->getAttrMetadata()->attrvaluetype == SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST)
2170+
{
2171+
/*
2172+
* In case of qos map list, order of list does not matter, so
2173+
* compare only entries.
2174+
*/
2175+
2176+
return hasEqualQosMapList(currentAttr, temporaryAttr);
2177+
}
2178+
21202179
if (currentAttr->isObjectIdAttr() == false)
21212180
{
21222181
/*

tests/brcm.pl

+9
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,18 @@ sub test_brcm_lag_no_members
268268
play "lag_no_members.rec", 0;
269269
}
270270

271+
sub test_brcm_qos_map_order
272+
{
273+
fresh_start;
274+
275+
# we expect no asic operation on qos maps that are the same but different order
276+
277+
play "qos_map_order.rec", 0;
278+
}
271279

272280
# RUN TESTS
273281

282+
test_brcm_qos_map_order;
274283
test_brcm_lag_no_members;
275284
test_brcm_rif_loopback;
276285
test_brcm_hostif;

0 commit comments

Comments
 (0)