Skip to content

Commit efa0f01

Browse files
authored
[QoS] Enforce drop probability only for colors whose WRED are enabled (sonic-net#2422)
What I did Do not enforce drop probability for a color whose WRED is disabled. Signed-off-by: Stephen Sun stephens@nvidia.com Why I did it Currently, there is a logic to enforce the drop probability if it is not explicitly designated for a color. However, the drop probability is not a mandatory attribute. It can incur vendor SAI complaints to set it when the color is disabled. The logic was introduced from the very beginning (by PR sonic-net#571) because no drop probability was defined in the QoS template at the time, which is no longer true. So we will enforce drop probability only if it is not configured and the color is enabled. How I verified it Unit test and manual test
1 parent 05c5c2f commit efa0f01

File tree

2 files changed

+128
-10
lines changed

2 files changed

+128
-10
lines changed

orchagent/qosorch.cpp

+38-10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ enum {
4646
RED_DROP_PROBABILITY_SET = (1U << 2)
4747
};
4848

49+
enum {
50+
GREEN_WRED_ENABLED = (1U << 0),
51+
YELLOW_WRED_ENABLED = (1U << 1),
52+
RED_WRED_ENABLED = (1U << 2)
53+
};
54+
4955
// field_name is what is expected in CONFIG_DB PORT_QOS_MAP table
5056
map<string, sai_port_attr_t> qos_to_attr_map = {
5157
{dscp_to_tc_field_name, SAI_PORT_ATTR_QOS_DSCP_TO_TC_MAP},
@@ -720,6 +726,7 @@ sai_object_id_t WredMapHandler::addQosItem(const vector<sai_attribute_t> &attrib
720726
sai_attribute_t attr;
721727
vector<sai_attribute_t> attrs;
722728
uint8_t drop_prob_set = 0;
729+
uint8_t wred_enable_set = 0;
723730

724731
attr.id = SAI_WRED_ATTR_WEIGHT;
725732
attr.value.s32 = 0;
@@ -729,32 +736,53 @@ sai_object_id_t WredMapHandler::addQosItem(const vector<sai_attribute_t> &attrib
729736
{
730737
attrs.push_back(attrib);
731738

732-
if (attrib.id == SAI_WRED_ATTR_GREEN_DROP_PROBABILITY)
739+
switch (attrib.id)
733740
{
741+
case SAI_WRED_ATTR_GREEN_ENABLE:
742+
if (attrib.value.booldata)
743+
{
744+
wred_enable_set |= GREEN_WRED_ENABLED;
745+
}
746+
break;
747+
case SAI_WRED_ATTR_YELLOW_ENABLE:
748+
if (attrib.value.booldata)
749+
{
750+
wred_enable_set |= YELLOW_WRED_ENABLED;
751+
}
752+
break;
753+
case SAI_WRED_ATTR_RED_ENABLE:
754+
if (attrib.value.booldata)
755+
{
756+
wred_enable_set |= RED_WRED_ENABLED;
757+
}
758+
break;
759+
case SAI_WRED_ATTR_GREEN_DROP_PROBABILITY:
734760
drop_prob_set |= GREEN_DROP_PROBABILITY_SET;
735-
}
736-
else if (attrib.id == SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY)
737-
{
761+
break;
762+
case SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY:
738763
drop_prob_set |= YELLOW_DROP_PROBABILITY_SET;
739-
}
740-
else if (attrib.id == SAI_WRED_ATTR_RED_DROP_PROBABILITY)
741-
{
764+
break;
765+
case SAI_WRED_ATTR_RED_DROP_PROBABILITY:
742766
drop_prob_set |= RED_DROP_PROBABILITY_SET;
767+
break;
768+
default:
769+
break;
743770
}
744771
}
745-
if (!(drop_prob_set & GREEN_DROP_PROBABILITY_SET))
772+
773+
if (!(drop_prob_set & GREEN_DROP_PROBABILITY_SET) && (wred_enable_set & GREEN_WRED_ENABLED))
746774
{
747775
attr.id = SAI_WRED_ATTR_GREEN_DROP_PROBABILITY;
748776
attr.value.s32 = 100;
749777
attrs.push_back(attr);
750778
}
751-
if (!(drop_prob_set & YELLOW_DROP_PROBABILITY_SET))
779+
if (!(drop_prob_set & YELLOW_DROP_PROBABILITY_SET) && (wred_enable_set & YELLOW_WRED_ENABLED))
752780
{
753781
attr.id = SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY;
754782
attr.value.s32 = 100;
755783
attrs.push_back(attr);
756784
}
757-
if (!(drop_prob_set & RED_DROP_PROBABILITY_SET))
785+
if (!(drop_prob_set & RED_DROP_PROBABILITY_SET) && (wred_enable_set & RED_WRED_ENABLED))
758786
{
759787
attr.id = SAI_WRED_ATTR_RED_DROP_PROBABILITY;
760788
attr.value.s32 = 100;

tests/mock_tests/qosorch_ut.cpp

+90
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ namespace qosorch_test
3737
sai_set_switch_attribute_fn old_set_switch_attribute_fn;
3838
sai_switch_api_t ut_sai_switch_api, *pold_sai_switch_api;
3939

40+
typedef struct
41+
{
42+
sai_uint32_t green_max_drop_probability;
43+
sai_uint32_t yellow_max_drop_probability;
44+
sai_uint32_t red_max_drop_probability;
45+
} qos_wred_max_drop_probability_t;
46+
4047
sai_status_t _ut_stub_sai_set_switch_attribute(sai_object_id_t switch_id, const sai_attribute_t *attr)
4148
{
4249
auto rc = old_set_switch_attribute_fn(switch_id, attr);
@@ -55,6 +62,7 @@ namespace qosorch_test
5562

5663
bool testing_wred_thresholds;
5764
WredMapHandler::qos_wred_thresholds_t saiThresholds;
65+
qos_wred_max_drop_probability_t saiMaxDropProbabilities;
5866
void _ut_stub_sai_check_wred_attributes(const sai_attribute_t &attr)
5967
{
6068
if (!testing_wred_thresholds)
@@ -88,6 +96,15 @@ namespace qosorch_test
8896
ASSERT_TRUE(!saiThresholds.red_max_threshold || saiThresholds.red_max_threshold > attr.value.u32);
8997
saiThresholds.red_min_threshold = attr.value.u32;
9098
break;
99+
case SAI_WRED_ATTR_GREEN_DROP_PROBABILITY:
100+
saiMaxDropProbabilities.green_max_drop_probability = attr.value.u32;
101+
break;
102+
case SAI_WRED_ATTR_YELLOW_DROP_PROBABILITY:
103+
saiMaxDropProbabilities.yellow_max_drop_probability = attr.value.u32;
104+
break;
105+
case SAI_WRED_ATTR_RED_DROP_PROBABILITY:
106+
saiMaxDropProbabilities.red_max_drop_probability = attr.value.u32;
107+
break;
91108
default:
92109
break;
93110
}
@@ -132,6 +149,23 @@ namespace qosorch_test
132149
ASSERT_TRUE(ts.empty());
133150
}
134151

152+
void updateMaxDropProbabilityAndCheck(string name, vector<FieldValueTuple> &maxDropProbabilityVector, qos_wred_max_drop_probability_t &maxDropProbabilities)
153+
{
154+
std::deque<KeyOpFieldsValuesTuple> entries;
155+
vector<string> ts;
156+
entries.push_back({name, "SET", maxDropProbabilityVector});
157+
auto consumer = dynamic_cast<Consumer *>(gQosOrch->getExecutor(CFG_WRED_PROFILE_TABLE_NAME));
158+
consumer->addToSync(entries);
159+
entries.clear();
160+
saiMaxDropProbabilities.green_max_drop_probability = 0;
161+
saiMaxDropProbabilities.yellow_max_drop_probability = 0;
162+
saiMaxDropProbabilities.red_max_drop_probability = 0;
163+
static_cast<Orch *>(gQosOrch)->doTask();
164+
ASSERT_EQ(saiMaxDropProbabilities.green_max_drop_probability, maxDropProbabilities.green_max_drop_probability);
165+
ASSERT_EQ(saiMaxDropProbabilities.yellow_max_drop_probability, maxDropProbabilities.yellow_max_drop_probability);
166+
ASSERT_EQ(saiMaxDropProbabilities.red_max_drop_probability, maxDropProbabilities.red_max_drop_probability);
167+
}
168+
135169
sai_status_t _ut_stub_sai_create_wred(
136170
_Out_ sai_object_id_t *wred_id,
137171
_In_ sai_object_id_t switch_id,
@@ -1338,6 +1372,62 @@ namespace qosorch_test
13381372
testing_wred_thresholds = false;
13391373
}
13401374

1375+
TEST_F(QosOrchTest, QosOrchTestWredDropProbability)
1376+
{
1377+
testing_wred_thresholds = true;
1378+
1379+
// The order of fields matters when the wred profile is updated from the upper set to the lower set
1380+
// It should be max, min for each color. In this order, the new max is less then the current min
1381+
// QoS orchagent should guarantee that the new min is configured first and then new max
1382+
vector<FieldValueTuple> greenProfile = {
1383+
{"wred_green_enable", "true"},
1384+
{"wred_yellow_enable", "false"},
1385+
};
1386+
qos_wred_max_drop_probability_t greenProbabilities = {
1387+
100, // green_max_drop_probability
1388+
0, // yellow_max_drop_probability
1389+
0 // red_max_drop_probability
1390+
};
1391+
updateMaxDropProbabilityAndCheck("green_default", greenProfile, greenProbabilities);
1392+
1393+
greenProfile.push_back({"green_drop_probability", "5"});
1394+
greenProbabilities.green_max_drop_probability = 5;
1395+
updateMaxDropProbabilityAndCheck("green", greenProfile, greenProbabilities);
1396+
1397+
vector<FieldValueTuple> yellowProfile = {
1398+
{"wred_yellow_enable", "true"},
1399+
{"wred_red_enable", "false"},
1400+
};
1401+
qos_wred_max_drop_probability_t yellowProbabilities = {
1402+
0, // green_max_drop_probability
1403+
100, // yellow_max_drop_probability
1404+
0 // red_max_drop_probability
1405+
};
1406+
updateMaxDropProbabilityAndCheck("yellow_default", yellowProfile, yellowProbabilities);
1407+
1408+
yellowProfile.push_back({"yellow_drop_probability", "5"});
1409+
yellowProbabilities.yellow_max_drop_probability = 5;
1410+
updateMaxDropProbabilityAndCheck("yellow", yellowProfile, yellowProbabilities);
1411+
1412+
vector<FieldValueTuple> redProfile = {
1413+
{"wred_green_enable", "false"},
1414+
{"wred_red_enable", "true"},
1415+
};
1416+
qos_wred_max_drop_probability_t redProbabilities = {
1417+
0, // green_max_drop_probability
1418+
0, // yellow_max_drop_probability
1419+
100 // red_max_drop_probability
1420+
};
1421+
updateMaxDropProbabilityAndCheck("red_default", redProfile, redProbabilities);
1422+
1423+
redProfile.push_back({"red_drop_probability", "5"});
1424+
redProbabilities.red_max_drop_probability = 5;
1425+
updateMaxDropProbabilityAndCheck("red", redProfile, redProbabilities);
1426+
1427+
testing_wred_thresholds = false;
1428+
}
1429+
1430+
13411431
/*
13421432
* Make sure empty fields won't cause orchagent crash
13431433
*/

0 commit comments

Comments
 (0)