Skip to content

Commit 5402d6a

Browse files
committed
Prevent profile creation for invalid cable length
Added a check 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 5402d6a

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

cfgmgr/buffermgrdyn.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,12 @@ void BufferMgrDynamic::updateBufferObjectListToDb(const string &key, const strin
944944
// We have to check the headroom ahead of applying them
945945
task_process_status BufferMgrDynamic::allocateProfile(const string &speed, const string &cable_len, const string &mtu, const string &threshold, const string &gearbox_model, long lane_count, string &profile_name)
946946
{
947+
if (cable_len == "0m")
948+
{
949+
SWSS_LOG_NOTICE("Not creating PG profile when cable length is set to %s", cable_len.c_str());
950+
return task_process_status::task_success;
951+
}
952+
947953
// Create record in BUFFER_PROFILE table
948954

949955
SWSS_LOG_INFO("Allocating new BUFFER_PROFILE %s", profile_name.c_str());
@@ -1462,6 +1468,19 @@ task_process_status BufferMgrDynamic::refreshPgsForPort(const string &port, cons
14621468
continue;
14631469
}
14641470

1471+
if (cable_length == "0m")
1472+
{
1473+
updateBufferObjectToDb(key, oldProfile, false); // 0m, remove PG.
1474+
SWSS_LOG_NOTICE("All profiles for port %s have been removed due to cable length being set to '0m'", port.c_str());
1475+
1476+
if (!oldProfile.empty())
1477+
{
1478+
profilesToBeReleased.insert(oldProfile);
1479+
m_bufferProfileLookup[oldProfile].port_pgs.erase(key);
1480+
}
1481+
continue;
1482+
}
1483+
14651484
string threshold;
14661485
// Calculate new headroom size
14671486
if (portPg.static_configured)

tests/mock_tests/buffermgrdyn_ut.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -1471,4 +1471,74 @@ 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+
m_dynamicBuffer->doTask(m_selectableTable);
1491+
1492+
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 0);
1493+
InitBufferPool();
1494+
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 3);
1495+
appBufferPoolTable.getKeys(keys);
1496+
ASSERT_EQ(keys.size(), 3);
1497+
1498+
// Initialize buffer profiles
1499+
InitBufferPg("Ethernet0|3-4");
1500+
InitDefaultBufferProfile();
1501+
appBufferProfileTable.getKeys(keys);
1502+
ASSERT_EQ(keys.size(), 3);
1503+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 3);
1504+
1505+
// 1. Set cable length to "0m"
1506+
InitCableLength("Ethernet0", "0m");
1507+
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet0"].state, PORT_READY);
1508+
// Expect profile not created
1509+
auto zeroMProfile = "pg_lossless_100000_0m_profile";
1510+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.find(zeroMProfile), m_dynamicBuffer->m_bufferProfileLookup.end());
1511+
1512+
// 2. Check if the reference for 5m profile of this port had been deleted in buffer PG table
1513+
// Since the cable length is set to 0m, previous profile for 5m should not exist.
1514+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1515+
1516+
// 3. Add a PG, Ethernet0:6, it should not be created with 0m profile
1517+
// The expectation is that no new PGs should be created with a cable length of 0m.
1518+
InitBufferPg("Ethernet0|6");
1519+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
1520+
1521+
// 4. Update cable length to 5m, then Ethernet0:6 and Ethernet0:3-4 should be created with 5m profile
1522+
InitCableLength("Ethernet0", "5m");
1523+
// Check if the profiles are created correctly
1524+
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
1525+
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
1526+
1527+
// 5. Update cable length to 0m, then Ethernet0:6 should be deleted, Ethernet0:3-4 should be deleted and 0m profile also not exist, and 5m profile should be deleted, PG also deleted, as profiles not exist
1528+
InitCableLength("Ethernet0", "0m");
1529+
// Check that the profiles for 0m and 5m both do not exist
1530+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1531+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1532+
// Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
1533+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:3-4") == m_dynamicBuffer->m_portPgLookup.end());
1534+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
1535+
1536+
// 6. Check if port MTU update, PG and profile still there
1537+
InitCableLength("Ethernet0", "5m");
1538+
string mtu = "4096";
1539+
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
1540+
// Check if the profile is created correctly
1541+
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
1542+
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
1543+
}
14741544
}

0 commit comments

Comments
 (0)