Skip to content

Commit 74e9e63

Browse files
committed
Prevent lossless profile creation for 0m cable
Changes: - Skip PG creation when both cable length is 0m AND PG is lossless - Allow lossy PGs to be created regardless of cable length Test: - Add unit test to verify lossy PG can be created with 0m cable length - Verify lossy PG profile and attributes are set correctly Signed-off-by: Jianyue Wu <jianyuew@nvidia.com>
1 parent 4eb74f0 commit 74e9e63

File tree

2 files changed

+164
-7
lines changed

2 files changed

+164
-7
lines changed

cfgmgr/buffermgrdyn.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,21 @@ task_process_status BufferMgrDynamic::refreshPgsForPort(const string &port, cons
14621462
continue;
14631463
}
14641464

1465+
// If cable len is 0m, remove lossless PG, keep lossy PG.
1466+
if (cable_length == "0m" && portPg.lossless)
1467+
{
1468+
if (oldProfile.empty())
1469+
{
1470+
SWSS_LOG_NOTICE("No lossless profile found for port %s when cable length is set to '0m'.", port.c_str());
1471+
continue;
1472+
}
1473+
updateBufferObjectToDb(key, oldProfile, false);
1474+
profilesToBeReleased.insert(oldProfile);
1475+
m_bufferProfileLookup[oldProfile].port_pgs.erase(key);
1476+
SWSS_LOG_NOTICE("All lossless profiles for port %s will be removed due to cable length being set to '0m'", port.c_str());
1477+
continue;
1478+
}
1479+
14651480
string threshold;
14661481
// Calculate new headroom size
14671482
if (portPg.static_configured)

tests/mock_tests/buffermgrdyn_ut.cpp

+149-7
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ namespace buffermgrdyn_test
137137
{"size", "1024000"}
138138
};
139139

140+
testBufferProfile["ingress_lossy_profile"] = {
141+
{"dynamic_th", "7"},
142+
{"pool", "ingress_lossless_pool"},
143+
{"size", "0"}
144+
};
140145
testBufferProfile["ingress_lossless_profile"] = {
141146
{"dynamic_th", "7"},
142147
{"pool", "ingress_lossless_pool"},
@@ -522,8 +527,8 @@ namespace buffermgrdyn_test
522527

523528
InitDefaultBufferProfile();
524529
appBufferProfileTable.getKeys(keys);
525-
ASSERT_EQ(keys.size(), 3);
526-
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 3);
530+
ASSERT_EQ(keys.size(), 4);
531+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 4);
527532
for (auto i : testBufferProfile)
528533
{
529534
CheckProfile(m_dynamicBuffer->m_bufferProfileLookup[i.first], testBufferProfile[i.first]);
@@ -647,7 +652,7 @@ namespace buffermgrdyn_test
647652
appBufferPoolTable.getKeys(keys);
648653
ASSERT_EQ(keys.size(), 3);
649654
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 3);
650-
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 3);
655+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 4);
651656
for (auto i : testBufferProfile)
652657
{
653658
CheckProfile(m_dynamicBuffer->m_bufferProfileLookup[i.first], testBufferProfile[i.first]);
@@ -933,8 +938,8 @@ namespace buffermgrdyn_test
933938

934939
InitDefaultBufferProfile();
935940
appBufferProfileTable.getKeys(keys);
936-
ASSERT_EQ(keys.size(), 3);
937-
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 3);
941+
ASSERT_EQ(keys.size(), 4);
942+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 4);
938943
for (auto i : testBufferProfile)
939944
{
940945
CheckProfile(m_dynamicBuffer->m_bufferProfileLookup[i.first], testBufferProfile[i.first]);
@@ -1267,8 +1272,8 @@ namespace buffermgrdyn_test
12671272
ASSERT_EQ(keys.size(), 3);
12681273
InitDefaultBufferProfile();
12691274
appBufferProfileTable.getKeys(keys);
1270-
ASSERT_EQ(keys.size(), 3);
1271-
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 3);
1275+
ASSERT_EQ(keys.size(), 4);
1276+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 4);
12721277

12731278
m_dynamicBuffer->m_bufferCompletelyInitialized = true;
12741279
m_dynamicBuffer->m_waitApplyAdditionalZeroProfiles = 0;
@@ -1471,4 +1476,141 @@ namespace buffermgrdyn_test
14711476
HandleTable(cableLengthTable);
14721477
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet12"].state, PORT_READY);
14731478
}
1479+
1480+
/*
1481+
Purpose: To verify the behavior of the buffer mgr dynamic when the cable length is set to "0m".
1482+
Here set to 0m indicates no lossless profile will be created, can still create lossy profile.
1483+
Steps:
1484+
1. Initialize the environment, including default lossless parameters and MMU size.
1485+
2. Start the Buffer Manager and initialize the port.
1486+
3. No new lossless profile is created when the cable length is "0m".
1487+
4. Existing lossless profiles are removed when the cable length is "0m".
1488+
5. No new lossless PG is created when the cable length is "0m".
1489+
6. When the cable length is updated to "5m", the correct lossless profiles and PGs are created.
1490+
7. When the cable length is updated back to "0m", the lossless profiles and PGs are removed.
1491+
8. Check if port MTU update, PG and profile still there.
1492+
9. When the cable length is "0m", lossy PGs remain, while lossless PGs are deleted.
1493+
*/
1494+
TEST_F(BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
1495+
{
1496+
vector<FieldValueTuple> fieldValues;
1497+
vector<string> keys;
1498+
1499+
// 1. Initialize the environment, including default lossless parameters and MMU size.
1500+
InitDefaultLosslessParameter();
1501+
InitMmuSize();
1502+
1503+
// 2. Start the Buffer Manager and initialize the port.
1504+
StartBufferManager();
1505+
1506+
InitPort();
1507+
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet0"].state, PORT_INITIALIZING);
1508+
1509+
SetPortInitDone();
1510+
m_dynamicBuffer->doTask(m_selectableTable);
1511+
1512+
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 0);
1513+
InitBufferPool();
1514+
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 3);
1515+
appBufferPoolTable.getKeys(keys);
1516+
ASSERT_EQ(keys.size(), 3);
1517+
1518+
// Initialize buffer profiles
1519+
InitBufferPg("Ethernet0|3-4");
1520+
InitDefaultBufferProfile();
1521+
appBufferProfileTable.getKeys(keys);
1522+
ASSERT_EQ(keys.size(), 4);
1523+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 4);
1524+
InitCableLength("Ethernet0", "5m");
1525+
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet0"].state, PORT_READY);
1526+
1527+
auto expectedProfile = "pg_lossless_100000_5m_profile";
1528+
CheckPg("Ethernet0", "Ethernet0:3-4", expectedProfile);
1529+
1530+
// 3. No new lossless profile is created when the cable length is "0m".
1531+
cableLengthTable.set("AZURE",
1532+
{
1533+
{"Ethernet0", "0m"}
1534+
});
1535+
HandleTable(cableLengthTable);
1536+
// Expect profile not created
1537+
auto zeroMProfile = "pg_lossless_100000_0m_profile";
1538+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.find(zeroMProfile), m_dynamicBuffer->m_bufferProfileLookup.end());
1539+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:3-4") == m_dynamicBuffer->m_portPgLookup.end());
1540+
1541+
// 4. Existing lossless profiles are removed when the cable length is "0m".
1542+
// Since the cable length is set to 0m, previous profile for 5m should not exist.
1543+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1544+
1545+
// 5. No new lossless PG is created when the cable length is "0m".
1546+
// The expectation is that no new PGs should be created with a cable length of 0m.
1547+
InitBufferPg("Ethernet0|6");
1548+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
1549+
1550+
// 6. When the cable length is updated to "5m", the correct lossless profiles and PGs are created.
1551+
cableLengthTable.set("AZURE",
1552+
{
1553+
{"Ethernet0", "5m"}
1554+
});
1555+
HandleTable(cableLengthTable);
1556+
// Check if the profiles are created correctly
1557+
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
1558+
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
1559+
1560+
// 7. When the cable length is updated back to "0m", the lossless profiles and PGs are removed.
1561+
cableLengthTable.set("AZURE",
1562+
{
1563+
{"Ethernet0", "0m"}
1564+
});
1565+
HandleTable(cableLengthTable);
1566+
// Check that the profiles for 0m do not exist, 5m profile could be still there, because it is shared by other ports
1567+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1568+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1569+
// Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
1570+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:3-4") == m_dynamicBuffer->m_portPgLookup.end());
1571+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
1572+
1573+
// 8. Check if port MTU update, PG and profile still there.
1574+
cableLengthTable.set("AZURE",
1575+
{
1576+
{"Ethernet0", "5m"}
1577+
});
1578+
HandleTable(cableLengthTable);
1579+
string mtu = "4096";
1580+
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
1581+
// Check if the profile is created correctly
1582+
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
1583+
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
1584+
1585+
// 7. Check if lossy PG can still be created
1586+
InitBufferPg("Ethernet0|0", "ingress_lossy_profile");
1587+
cableLengthTable.set("AZURE",
1588+
{
1589+
{"Ethernet0", "0m"}
1590+
});
1591+
HandleTable(cableLengthTable);
1592+
bool found = false;
1593+
auto it = m_dynamicBuffer->m_portPgLookup.find("Ethernet0");
1594+
if (it != m_dynamicBuffer->m_portPgLookup.end()) {
1595+
found = (it->second.find("Ethernet0:0") != it->second.end());
1596+
}
1597+
ASSERT_TRUE(found);
1598+
1599+
// 9. When the cable length is "0m", lossy PGs remain, while lossless PGs are deleted.
1600+
cableLengthTable.set("AZURE",
1601+
{
1602+
{"Ethernet0", "0m"}
1603+
});
1604+
HandleTable(cableLengthTable);
1605+
it = m_dynamicBuffer->m_portPgLookup.find("Ethernet0");
1606+
if (it != m_dynamicBuffer->m_portPgLookup.end()) {
1607+
found = (it->second.find("Ethernet0:0") != it->second.end());
1608+
}
1609+
ASSERT_TRUE(found);
1610+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1611+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1612+
// Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
1613+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:3-4") == m_dynamicBuffer->m_portPgLookup.end());
1614+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
1615+
}
14741616
}

0 commit comments

Comments
 (0)