Skip to content

Commit 242189b

Browse files
authored
[Dynamic Buffer Calc] Enhance the field checking in table handling (sonic-net#1680)
* Fix a typo in test_buffer_dynamic.py and enhance a field name check * Use "else if" instead of "if" Signed-off-by: Stephen Sun <stephens@nvidia.com>
1 parent de5fb41 commit 242189b

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

cfgmgr/buffermgrdyn.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -1376,15 +1376,15 @@ task_process_status BufferMgrDynamic::handleBufferPoolTable(KeyOpFieldsValuesTup
13761376
{
13771377
bufferPool.dynamic_size = false;
13781378
}
1379-
if (field == buffer_pool_xoff_field_name)
1379+
else if (field == buffer_pool_xoff_field_name)
13801380
{
13811381
newSHPSize = value;
13821382
}
1383-
if (field == buffer_pool_mode_field_name)
1383+
else if (field == buffer_pool_mode_field_name)
13841384
{
13851385
bufferPool.mode = value;
13861386
}
1387-
if (field == buffer_pool_type_field_name)
1387+
else if (field == buffer_pool_type_field_name)
13881388
{
13891389
bufferPool.ingress = (value == buffer_value_ingress);
13901390
}
@@ -1503,32 +1503,32 @@ task_process_status BufferMgrDynamic::handleBufferProfileTable(KeyOpFieldsValues
15031503
return task_process_status::task_failed;
15041504
}
15051505
}
1506-
if (field == buffer_xon_field_name)
1506+
else if (field == buffer_xon_field_name)
15071507
{
15081508
profileApp.xon = value;
15091509
}
1510-
if (field == buffer_xoff_field_name)
1510+
else if (field == buffer_xoff_field_name)
15111511
{
15121512
profileApp.xoff = value;
15131513
profileApp.lossless = true;
15141514
}
1515-
if (field == buffer_xon_offset_field_name)
1515+
else if (field == buffer_xon_offset_field_name)
15161516
{
15171517
profileApp.xon_offset = value;
15181518
}
1519-
if (field == buffer_size_field_name)
1519+
else if (field == buffer_size_field_name)
15201520
{
15211521
profileApp.size = value;
15221522
}
1523-
if (field == buffer_dynamic_th_field_name)
1523+
else if (field == buffer_dynamic_th_field_name)
15241524
{
15251525
profileApp.threshold = value;
15261526
}
1527-
if (field == buffer_static_th_field_name)
1527+
else if (field == buffer_static_th_field_name)
15281528
{
15291529
profileApp.threshold = value;
15301530
}
1531-
if (field == buffer_headroom_type_field_name)
1531+
else if (field == buffer_headroom_type_field_name)
15321532
{
15331533
profileApp.dynamic_calculated = (value == "dynamic");
15341534
if (profileApp.dynamic_calculated)
@@ -1692,6 +1692,13 @@ task_process_status BufferMgrDynamic::handleOneBufferPgEntry(const string &key,
16921692
bufferPg.static_configured = true;
16931693
bufferPg.configured_profile_name = profileName;
16941694
}
1695+
1696+
if (field != buffer_profile_field_name)
1697+
{
1698+
SWSS_LOG_ERROR("BUFFER_PG: Invalid field %s", field.c_str());
1699+
return task_process_status::task_invalid_entry;
1700+
}
1701+
16951702
fvVector.emplace_back(field, value);
16961703
SWSS_LOG_INFO("Inserting BUFFER_PG table field %s value %s", field.c_str(), value.c_str());
16971704
}

tests/test_buffer_dynamic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_headroomOverride(self, dvs, testlog):
328328
self.app_db.wait_for_deleted_entry("BUFFER_PG_TABLE", "Ethernet0:6")
329329

330330
# readd lossless PG with dynamic profile
331-
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profie': 'NULL'})
331+
self.config_db.update_entry('BUFFER_PG', 'Ethernet0|3-4', {'profile': 'NULL'})
332332
self.app_db.wait_for_field_match("BUFFER_PG_TABLE", "Ethernet0:3-4", {"profile": "[BUFFER_PROFILE_TABLE:" + expectedProfile + "]"})
333333

334334
# remove the headroom override profile

0 commit comments

Comments
 (0)