Skip to content

Commit 3494eae

Browse files
committed
Keep PGs, remove losslesss profiles when 0m cable
When 0m cable, lossy PG and profile can still be created, while lossless profile will be deleted. Signed-off-by: Jianyue Wu <jianyuew@nvidia.com>
1 parent 74e9e63 commit 3494eae

File tree

2 files changed

+146
-81
lines changed

2 files changed

+146
-81
lines changed

cfgmgr/buffermgrdyn.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,18 @@ task_process_status BufferMgrDynamic::refreshPgsForPort(const string &port, cons
14721472
}
14731473
updateBufferObjectToDb(key, oldProfile, false);
14741474
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());
1475+
1476+
if (m_bufferProfileLookup.find(oldProfile) != m_bufferProfileLookup.end())
1477+
{
1478+
m_bufferProfileLookup[oldProfile].port_pgs.erase(key);
1479+
}
1480+
else
1481+
{
1482+
SWSS_LOG_NOTICE("Attempted to remove non-existent profile %s for port %s.", oldProfile.c_str(), port.c_str());
1483+
}
1484+
portPg.running_profile_name.clear();
1485+
SWSS_LOG_NOTICE("All lossless profiles and PGs for port %s will be removed due to cable length being set to '0m'",
1486+
port.c_str());
14771487
continue;
14781488
}
14791489

tests/mock_tests/buffermgrdyn_ut.cpp

+134-79
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,46 @@ namespace buffermgrdyn_test
467467
}
468468
}
469469

470+
void VerifyPgExists(const string &port, const string &pg, bool shouldExist)
471+
{
472+
if (shouldExist)
473+
{
474+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup[port].find(pg) != m_dynamicBuffer->m_portPgLookup[port].end())
475+
<< "PG " << pg << " should exist for port " << port;
476+
}
477+
else
478+
{
479+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup[port].find(pg) == m_dynamicBuffer->m_portPgLookup[port].end())
480+
<< "PG " << pg << " should not exist for port " << port;
481+
}
482+
}
483+
484+
void VerifyPgProfile(const string &port, const string &pg, const string &expectedProfile)
485+
{
486+
ASSERT_EQ(m_dynamicBuffer->m_portPgLookup[port][pg].running_profile_name, expectedProfile)
487+
<< "PG " << pg << " should have profile " << expectedProfile;
488+
}
489+
490+
void VerifyPgProfileEmpty(const string &port, const string &pg)
491+
{
492+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup[port][pg].running_profile_name.empty())
493+
<< "PG " << pg << " should have an empty profile";
494+
}
495+
496+
void VerifyProfileExists(const string &profile, bool shouldExist)
497+
{
498+
if (shouldExist)
499+
{
500+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find(profile) != m_dynamicBuffer->m_bufferProfileLookup.end())
501+
<< "Profile " << profile << " should exist";
502+
}
503+
else
504+
{
505+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find(profile) == m_dynamicBuffer->m_bufferProfileLookup.end())
506+
<< "Profile " << profile << " should not exist";
507+
}
508+
}
509+
470510
void TearDown() override
471511
{
472512
delete m_dynamicBuffer;
@@ -1481,41 +1521,56 @@ namespace buffermgrdyn_test
14811521
Purpose: To verify the behavior of the buffer mgr dynamic when the cable length is set to "0m".
14821522
Here set to 0m indicates no lossless profile will be created, can still create lossy profile.
14831523
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.
1524+
1. Initialize default lossless parameters and MMU size
1525+
2. Initialize port and verify initial state
1526+
3. Set port initialization as done and process tasks
1527+
4. Initialize buffer pools and verify
1528+
5. Initialize buffer profiles and PGs with 5m cable length
1529+
6. Verify PG configuration with 5m cable length
1530+
7. Change cable length to 0m and verify profile behavior
1531+
8. Verify that no 0m profile is created and existing profile is removed
1532+
9. Verify that the running_profile_name is cleared for lossless PGs
1533+
10. Verify that the 5m profile is removed
1534+
11. Try to create a new lossless PG with 0m cable length
1535+
12. Verify that the PG exists but has no profile assigned
1536+
13. Change cable length back to 5m and verify profiles are restored correctly
1537+
14. Verify that profiles are removed again when cable length is set back to 0m
1538+
15. Additional verification of PG state
1539+
16. MTU updates work correctly with non-zero cable length
1540+
17. Create a lossy PG and change cable length to 0m
1541+
18. Verify that lossy PG keeps its profile while lossless PGs have empty profiles
1542+
19. Verify that lossless profiles are removed when cable length is set back to 0m
1543+
20. Verify that lossy profiles are still there when cable length is 0m
1544+
21. Verify that lossless PGs are deleted when cable length is 0m
14931545
*/
1546+
14941547
TEST_F(BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
14951548
{
14961549
vector<FieldValueTuple> fieldValues;
14971550
vector<string> keys;
14981551

1499-
// 1. Initialize the environment, including default lossless parameters and MMU size.
1552+
// SETUP: Initialize the environment
1553+
// 1. Initialize default lossless parameters and MMU size
15001554
InitDefaultLosslessParameter();
15011555
InitMmuSize();
1502-
1503-
// 2. Start the Buffer Manager and initialize the port.
15041556
StartBufferManager();
15051557

1558+
// 2. Initialize port and verify initial state
15061559
InitPort();
15071560
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet0"].state, PORT_INITIALIZING);
15081561

1562+
// 3. Set port initialization as done and process tasks
15091563
SetPortInitDone();
15101564
m_dynamicBuffer->doTask(m_selectableTable);
15111565

1566+
// 4. Initialize buffer pools and verify
15121567
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 0);
15131568
InitBufferPool();
15141569
ASSERT_EQ(m_dynamicBuffer->m_bufferPoolLookup.size(), 3);
15151570
appBufferPoolTable.getKeys(keys);
15161571
ASSERT_EQ(keys.size(), 3);
15171572

1518-
// Initialize buffer profiles
1573+
// 5. Initialize buffer profiles and PGs with 5m cable length
15191574
InitBufferPg("Ethernet0|3-4");
15201575
InitDefaultBufferProfile();
15211576
appBufferProfileTable.getKeys(keys);
@@ -1524,93 +1579,93 @@ namespace buffermgrdyn_test
15241579
InitCableLength("Ethernet0", "5m");
15251580
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet0"].state, PORT_READY);
15261581

1582+
// 6. Verify PG configuration with 5m cable length
15271583
auto expectedProfile = "pg_lossless_100000_5m_profile";
15281584
CheckPg("Ethernet0", "Ethernet0:3-4", expectedProfile);
15291585

1530-
// 3. No new lossless profile is created when the cable length is "0m".
1531-
cableLengthTable.set("AZURE",
1532-
{
1533-
{"Ethernet0", "0m"}
1534-
});
1586+
// TEST CASE 1: No new lossless profile is created when cable length is "0m"
1587+
// 7. Change cable length to 0m and verify profile behavior
1588+
cableLengthTable.set("AZURE", {{"Ethernet0", "0m"}});
15351589
HandleTable(cableLengthTable);
1536-
// Expect profile not created
1590+
1591+
// 8. Verify that no 0m profile is created and existing profile is removed
15371592
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());
1593+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find(zeroMProfile) == m_dynamicBuffer->m_bufferProfileLookup.end())
1594+
<< "No lossless profile should be created for 0m cable length";
1595+
1596+
// 9. Verify that the running_profile_name is cleared for lossless PGs
1597+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:3-4"].running_profile_name.empty())
1598+
<< "Running profile name should be empty for lossless PGs when cable length is 0m";
15401599

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());
1600+
// 10. Verify that the 5m profile is removed
1601+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end())
1602+
<< "Previous lossless profile should be removed when cable length is 0m";
15441603

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.
1604+
// TEST CASE 2: No new lossless PG is created when cable length is "0m"
1605+
// 11. Try to create a new lossless PG with 0m cable length
15471606
InitBufferPg("Ethernet0|6");
1548-
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
15491607

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-
});
1608+
// 12. Verify that the PG exists but has no profile assigned
1609+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:6") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end())
1610+
<< "PG should be created even with 0m cable length";
1611+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:6"].running_profile_name.empty())
1612+
<< "No profile should be assigned to lossless PG when cable length is 0m";
1613+
1614+
// TEST CASE 3: Profiles are restored when cable length is changed back to non-zero
1615+
// 13. Change cable length back to 5m
1616+
cableLengthTable.set("AZURE", {{"Ethernet0", "5m"}});
15551617
HandleTable(cableLengthTable);
1556-
// Check if the profiles are created correctly
1618+
m_dynamicBuffer->doTask();
1619+
1620+
// 14. Verify that profiles are restored correctly
15571621
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
15581622
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
15591623

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-
});
1624+
// 15. Additional verification of PG state
1625+
VerifyPgExists("Ethernet0", "Ethernet0:3-4", true);
1626+
VerifyPgExists("Ethernet0", "Ethernet0:6", true);
1627+
VerifyPgProfile("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
1628+
VerifyPgProfile("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
1629+
1630+
// TEST CASE 4: Profiles are removed again when cable length is set back to 0m
1631+
// 16. Change cable length back to 0m
1632+
cableLengthTable.set("AZURE", {{"Ethernet0", "0m"}});
15651633
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-
});
1634+
m_dynamicBuffer->doTask();
1635+
1636+
// 17. Verify that profiles are removed but PGs remain
1637+
VerifyProfileExists("pg_lossless_100000_0m_profile", false);
1638+
VerifyProfileExists("pg_lossless_100000_5m_profile", false);
1639+
VerifyPgExists("Ethernet0", "Ethernet0:3-4", true);
1640+
VerifyPgExists("Ethernet0", "Ethernet0:6", true);
1641+
VerifyPgProfileEmpty("Ethernet0", "Ethernet0:3-4");
1642+
VerifyPgProfileEmpty("Ethernet0", "Ethernet0:6");
1643+
1644+
// TEST CASE 5: MTU updates work correctly with non-zero cable length
1645+
// 18. Change cable length to 5m and update MTU
1646+
cableLengthTable.set("AZURE", {{"Ethernet0", "5m"}});
15781647
HandleTable(cableLengthTable);
15791648
string mtu = "4096";
1580-
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
1581-
// Check if the profile is created correctly
1649+
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
1650+
1651+
// 19. Verify profiles are created correctly with new MTU
15821652
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
15831653
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
15841654

1585-
// 7. Check if lossy PG can still be created
1655+
// TEST CASE 6: Lossy PGs work correctly with 0m cable length
1656+
// 20. Create a lossy PG and change cable length to 0m
15861657
InitBufferPg("Ethernet0|0", "ingress_lossy_profile");
1587-
cableLengthTable.set("AZURE",
1588-
{
1589-
{"Ethernet0", "0m"}
1590-
});
1658+
cableLengthTable.set("AZURE", {{"Ethernet0", "0m"}});
15911659
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);
15981660

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());
1661+
// 21. Verify that lossy PG keeps its profile while lossless PGs have empty profiles
1662+
VerifyPgExists("Ethernet0", "Ethernet0:0", true);
1663+
VerifyPgExists("Ethernet0", "Ethernet0:3-4", true);
1664+
VerifyPgExists("Ethernet0", "Ethernet0:6", true);
1665+
VerifyPgProfile("Ethernet0", "Ethernet0:0", "ingress_lossy_profile");
1666+
VerifyPgProfileEmpty("Ethernet0", "Ethernet0:3-4");
1667+
VerifyPgProfileEmpty("Ethernet0", "Ethernet0:6");
1668+
VerifyProfileExists("pg_lossless_100000_0m_profile", false);
1669+
VerifyProfileExists("pg_lossless_100000_5m_profile", false);
16151670
}
16161671
}

0 commit comments

Comments
 (0)