Skip to content

Commit 975e019

Browse files
committed
Prevent profile creation for invalid cable length
Added a check in BufferMgrDynamic::allocateProfile to skip profile creation when the cable length is 0m. This change ensures that profiles are not created for invalid cable lengths, preventing potential configuration errors. Logged a notice message when skipping profile creation due to 0m cable length. Signed-off-by: Jianyue Wu <jianyuew@nvidia.com>
1 parent 4eb74f0 commit 975e019

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

cfgmgr/buffermgrdyn.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,12 @@ task_process_status BufferMgrDynamic::handleSingleBufferPgEntry(const string &ke
29322932
buffer_pg_t &bufferPg = m_portPgLookup[port][key];
29332933
port_info_t &portInfo = m_portInfoLookup[port];
29342934

2935+
if (portInfo.cable_length == "0m")
2936+
{
2937+
SWSS_LOG_NOTICE("Skipping profile creation for cable length '0m'");
2938+
return task_process_status::task_success;
2939+
}
2940+
29352941
SWSS_LOG_DEBUG("Processing command:%s table BUFFER_PG key %s", op.c_str(), key.c_str());
29362942
if (op == SET_COMMAND)
29372943
{

tests/mock_tests/buffermgrdyn_ut.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -1471,4 +1471,47 @@ namespace buffermgrdyn_test
14711471
HandleTable(cableLengthTable);
14721472
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet12"].state, PORT_READY);
14731473
}
1474+
1475+
TEST_F(BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
1476+
{
1477+
vector<FieldValueTuple> fieldValues;
1478+
vector<string> keys;
1479+
1480+
// Prepare information that will be read at the beginning
1481+
InitDefaultLosslessParameter();
1482+
InitMmuSize();
1483+
1484+
StartBufferManager();
1485+
1486+
InitPort();
1487+
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet0"].state, PORT_INITIALIZING);
1488+
1489+
SetPortInitDone();
1490+
// Timer will be called
1491+
m_dynamicBuffer->doTask(m_selectableTable);
1492+
1493+
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 0);
1494+
InitBufferPool();
1495+
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 3);
1496+
appBufferPoolTable.getKeys(keys);
1497+
ASSERT_EQ(keys.size(), 3);
1498+
1499+
// Initialize buffer profiles
1500+
InitDefaultBufferProfile();
1501+
appBufferProfileTable.getKeys(keys);
1502+
ASSERT_EQ(keys.size(), 3);
1503+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 3);
1504+
1505+
// Set cable length to "0m"
1506+
InitCableLength("Ethernet0", "0m");
1507+
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet0"].state, PORT_READY);
1508+
1509+
InitBufferPg("Ethernet0|3-4");
1510+
1511+
auto expectedProfile = "pg_lossless_100000_0m_profile";
1512+
auto &portPgMap = m_dynamicBuffer->m_bufferProfileLookup[expectedProfile].port_pgs;
1513+
// Expect not created
1514+
ASSERT_EQ(portPgMap.size(), 0);
1515+
ASSERT_TRUE(portPgMap.find("Ethernet0:3-4") == portPgMap.end());
1516+
}
14741517
}

0 commit comments

Comments
 (0)