Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b62c716

Browse files
authoredSep 9, 2022
Enhance orchagent and buffer manager in error handling (sonic-net#2414)
What I did Enhance orchagent and buffer manager Buffer manager: do not insert buffer queue into cache if the profile is illegal, which prevents an empty string from being inserted into APPL_DB during initialization. orchagent: handle the case that a field referencing other objects is an empty string. There had been such logic that was broken by a PR last year. Signed-off-by: Stephen Sun stephens@nvidia.com Why I did it Enhance the error handling logic. In most cases, a user will not encounter such scenarios in a production environment because it's the front-ends' (eg. CLI) responsibility to identify the wrong configuration and prevent them from being inserted to CONFIG_DB. However, in some cases, like a wrong config_db.json composed and copied to the switch, front-ends can not prevent that. How I verified it Manual and mock tests. Details if related For the improvement in buffer manager: previously, the logic was: declare a reference portQueue to m_portQueueLookup[port][queues] and then assign fvValue(i) to portQueue.running_profile_name But [] operation on C++ map has a side-effect -- it will insert a new element into the map if there wasn't one. In case the validation check in checkBufferProfileDirection failed and there was not one in the map, the portQueue.running_profile_name will keep empty. This is not what we want. In case there was an item configured in the map, we should not remove it on failure because we want to prevent the user from being affected by misconfiguration and alert user to correct the error. There is log in checkBufferProfileDirection Now it is improved in this way: Avoid using reference and initialize m_portQueueLookup[port][queues] only if there is a valid egress profile configured
1 parent 13bda3c commit b62c716

File tree

4 files changed

+80
-4
lines changed

4 files changed

+80
-4
lines changed
 

‎cfgmgr/buffermgrdyn.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -3110,8 +3110,7 @@ task_process_status BufferMgrDynamic::handleSingleBufferQueueEntry(const string
31103110

31113111
if (op == SET_COMMAND)
31123112
{
3113-
auto &portQueue = m_portQueueLookup[port][queues];
3114-
3113+
bool successful = false;
31153114
SWSS_LOG_INFO("Inserting entry BUFFER_QUEUE_TABLE:%s to APPL_DB", key.c_str());
31163115

31173116
for (auto i : kfvFieldsValues(tuple))
@@ -3122,8 +3121,10 @@ task_process_status BufferMgrDynamic::handleSingleBufferQueueEntry(const string
31223121
auto rc = checkBufferProfileDirection(fvValue(i), BUFFER_EGRESS);
31233122
if (rc != task_process_status::task_success)
31243123
return rc;
3125-
portQueue.running_profile_name = fvValue(i);
3124+
3125+
m_portQueueLookup[port][queues].running_profile_name = fvValue(i);
31263126
SWSS_LOG_NOTICE("Queue %s has been configured on the system, referencing profile %s", key.c_str(), fvValue(i).c_str());
3127+
successful = true;
31273128
}
31283129
else
31293130
{
@@ -3134,8 +3135,15 @@ task_process_status BufferMgrDynamic::handleSingleBufferQueueEntry(const string
31343135
SWSS_LOG_INFO("Inserting field %s value %s", fvField(i).c_str(), fvValue(i).c_str());
31353136
}
31363137

3138+
if (!successful)
3139+
{
3140+
SWSS_LOG_ERROR("Invalid BUFFER_QUEUE configuration on %s: no profile configured", key.c_str());
3141+
return task_process_status::task_failed;
3142+
}
3143+
31373144
// TODO: check overlap. Currently, assume there is no overlap
31383145

3146+
auto &portQueue = m_portQueueLookup[port][queues];
31393147
if (PORT_ADMIN_DOWN == portInfo.state)
31403148
{
31413149
handleSetSingleBufferObjectOnAdminDownPort(BUFFER_QUEUE, port, key, portQueue.running_profile_name);

‎orchagent/orch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ ref_resolve_status Orch::resolveFieldRefValue(
393393
{
394394
return ref_resolve_status::not_resolved;
395395
}
396-
else if (ref_type_name.empty() && object_name.empty())
396+
else if (object_name.empty())
397397
{
398398
return ref_resolve_status::empty;
399399
}

‎tests/mock_tests/buffermgrdyn_ut.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,13 @@ namespace buffermgrdyn_test
667667
CheckProfileList("Ethernet0", true, "ingress_lossless_profile", false);
668668
CheckProfileList("Ethernet0", false, "egress_lossless_profile,egress_lossy_profile", false);
669669

670+
// Initialize a port with all profiles undefined
671+
InitPort("Ethernet8");
672+
InitBufferPg("Ethernet8|0", "ingress_not_defined_profile");
673+
InitBufferQueue("Ethernet8|0", "egress_not_defined_profile");
674+
InitBufferProfileList("Ethernet8", "egress_not_defined_profile", bufferEgrProfileListTable);
675+
InitBufferProfileList("Ethernet8", "ingress_not_defined_profile", bufferIngProfileListTable);
676+
670677
// All default buffer profiles should be generated and pushed into BUFFER_PROFILE_TABLE
671678
static_cast<Orch *>(m_dynamicBuffer)->doTask();
672679

@@ -686,6 +693,36 @@ namespace buffermgrdyn_test
686693
CheckProfileList("Ethernet0", true, "ingress_lossless_profile", true);
687694
CheckProfileList("Ethernet0", false, "egress_lossless_profile,egress_lossy_profile", true);
688695

696+
// Check no items applied on port Ethernet8
697+
ASSERT_EQ(appBufferPgTable.get("Ethernet8:0", fieldValues), false);
698+
CheckQueue("Ethernet8", "Ethernet8:0", "", false);
699+
CheckProfileList("Ethernet8", true, "", false);
700+
CheckProfileList("Ethernet8", false, "", false);
701+
702+
// Configure the missing buffer profiles
703+
bufferProfileTable.set("ingress_not_defined_profile",
704+
{
705+
{"pool", "ingress_lossless_pool"},
706+
{"dynamic_th", "0"},
707+
{"size", "0"}
708+
});
709+
bufferProfileTable.set("egress_not_defined_profile",
710+
{
711+
{"pool", "egress_lossless_pool"},
712+
{"dynamic_th", "0"},
713+
{"size", "0"}
714+
});
715+
m_dynamicBuffer->addExistingData(&bufferProfileTable);
716+
// For buffer profile
717+
static_cast<Orch *>(m_dynamicBuffer)->doTask();
718+
// For all other items
719+
static_cast<Orch *>(m_dynamicBuffer)->doTask();
720+
ASSERT_EQ(appBufferPgTable.get("Ethernet8:0", fieldValues), true);
721+
ASSERT_EQ(fvValue(fieldValues[0]), "ingress_not_defined_profile");
722+
CheckQueue("Ethernet8", "Ethernet8:0", "egress_not_defined_profile", true);
723+
CheckProfileList("Ethernet8", true, "ingress_not_defined_profile", true);
724+
CheckProfileList("Ethernet8", false, "egress_not_defined_profile", true);
725+
689726
InitPort("Ethernet4");
690727
InitPort("Ethernet6");
691728
InitBufferQueue("Ethernet6|0-2", "egress_lossy_profile");

‎tests/mock_tests/qosorch_ut.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -1337,4 +1337,35 @@ namespace qosorch_test
13371337

13381338
testing_wred_thresholds = false;
13391339
}
1340+
1341+
/*
1342+
* Make sure empty fields won't cause orchagent crash
1343+
*/
1344+
TEST_F(QosOrchTest, QosOrchTestEmptyField)
1345+
{
1346+
// Create a new dscp to tc map
1347+
std::deque<KeyOpFieldsValuesTuple> entries;
1348+
entries.push_back({"Ethernet0", "SET",
1349+
{
1350+
{"dscp_to_tc_map", ""}
1351+
}});
1352+
auto consumer = dynamic_cast<Consumer *>(gQosOrch->getExecutor(CFG_PORT_QOS_MAP_TABLE_NAME));
1353+
consumer->addToSync(entries);
1354+
entries.clear();
1355+
1356+
entries.push_back({"Ethernet0|3", "SET",
1357+
{
1358+
{"scheduler", ""}
1359+
}});
1360+
entries.push_back({"Ethernet0|4", "SET",
1361+
{
1362+
{"wred_profile", ""}
1363+
}});
1364+
consumer = dynamic_cast<Consumer *>(gQosOrch->getExecutor(CFG_QUEUE_TABLE_NAME));
1365+
consumer->addToSync(entries);
1366+
entries.clear();
1367+
1368+
// Drain DSCP_TO_TC_MAP and PORT_QOS_MAP table
1369+
static_cast<Orch *>(gQosOrch)->doTask();
1370+
}
13401371
}

0 commit comments

Comments
 (0)
Please sign in to comment.