Skip to content

Commit 61afaa6

Browse files
committed
Add explicit lossy check and update UT
Signed-off-by: Jianyue Wu <jianyuew@nvidia.com>
1 parent eedbb68 commit 61afaa6

File tree

2 files changed

+82
-21
lines changed

2 files changed

+82
-21
lines changed

cfgmgr/buffermgrdyn.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -944,10 +944,10 @@ 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-
bool is_lossless = (profile_name.find("pg_lossless_") != string::npos);
947+
bool is_lossless = (profile_name.find("lossless") != string::npos);
948948
if (cable_len == "0m" && is_lossless)
949949
{
950-
SWSS_LOG_NOTICE("Not creating PG profile when cable length is set to %s", cable_len.c_str());
950+
SWSS_LOG_NOTICE("Not creating lossless profile when cable length is set to %s", cable_len.c_str());
951951
return task_process_status::task_success;
952952
}
953953

@@ -1469,9 +1469,16 @@ task_process_status BufferMgrDynamic::refreshPgsForPort(const string &port, cons
14691469
continue;
14701470
}
14711471

1472-
if (cable_length == "0m" && it->second.lossless)
1472+
// If cable len is 0m, remove lossless PG, keep lossy PG.
1473+
bool old_profile_is_lossless = (oldProfile.find("lossless") != string::npos);
1474+
if (cable_length == "0m" && portPg.lossless && old_profile_is_lossless)
14731475
{
1474-
updateBufferObjectToDb(key, oldProfile, false); // 0m, remove PG.
1476+
if (oldProfile.empty())
1477+
{
1478+
SWSS_LOG_WARN("No lossless profile found for port %s when cable length is set to '0m'.", port.c_str());
1479+
continue;
1480+
}
1481+
updateBufferObjectToDb(key, oldProfile, false);
14751482
SWSS_LOG_NOTICE("All profiles for port %s have been removed due to cable length being set to '0m'", port.c_str());
14761483

14771484
if (!oldProfile.empty())

tests/mock_tests/buffermgrdyn_ut.cpp

+71-17
Original file line numberDiff line numberDiff line change
@@ -1477,15 +1477,30 @@ namespace buffermgrdyn_test
14771477
ASSERT_EQ(m_dynamicBuffer->m_portInfoLookup["Ethernet12"].state, PORT_READY);
14781478
}
14791479

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+
*/
14801494
TEST_F(BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
14811495
{
14821496
vector<FieldValueTuple> fieldValues;
14831497
vector<string> keys;
14841498

1485-
// Prepare information that will be read at the beginning
1499+
// 1. Initialize the environment, including default lossless parameters and MMU size.
14861500
InitDefaultLosslessParameter();
14871501
InitMmuSize();
14881502

1503+
// 2. Start the Buffer Manager and initialize the port.
14891504
StartBufferManager();
14901505

14911506
InitPort();
@@ -1506,56 +1521,95 @@ namespace buffermgrdyn_test
15061521
appBufferProfileTable.getKeys(keys);
15071522
ASSERT_EQ(keys.size(), 4);
15081523
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 4);
1509-
1510-
// 1. Set cable length to "0m"
1511-
InitCableLength("Ethernet0", "0m");
1524+
InitCableLength("Ethernet0", "5m");
15121525
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);
15131536
// Expect profile not created
15141537
auto zeroMProfile = "pg_lossless_100000_0m_profile";
15151538
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.find(zeroMProfile), m_dynamicBuffer->m_bufferProfileLookup.end());
15161539

1517-
// 2. Check if the reference for 5m profile of this port had been deleted in buffer PG table
1540+
// 4. Existing lossless profiles are removed when the cable length is "0m".
15181541
// Since the cable length is set to 0m, previous profile for 5m should not exist.
15191542
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
15201543

1521-
// 3. Add a PG, Ethernet0:6, it should not be created with 0m profile
1544+
// 5. No new lossless PG is created when the cable length is "0m".
15221545
// The expectation is that no new PGs should be created with a cable length of 0m.
15231546
InitBufferPg("Ethernet0|6");
15241547
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
15251548

1526-
// 4. Update cable length to 5m, then Ethernet0:6 and Ethernet0:3-4 should be created with 5m profile
1527-
InitCableLength("Ethernet0", "5m");
1549+
// 6. When the cable length is updated to "5m", the correct lossless profiles and PGs are created.
1550+
cableLengthTable.set("AZURE",
1551+
{
1552+
{"Ethernet0", "5m"}
1553+
});
1554+
HandleTable(cableLengthTable);
15281555
// Check if the profiles are created correctly
15291556
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
15301557
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
15311558

1532-
// 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
1533-
InitCableLength("Ethernet0", "0m");
1534-
static_cast<Orch *>(m_dynamicBuffer)->doTask();
1535-
// Check that the profiles for 0m and 5m both do not exist
1559+
// 7. When the cable length is updated back to "0m", the lossless profiles and PGs are removed.
1560+
cableLengthTable.set("AZURE",
1561+
{
1562+
{"Ethernet0", "0m"}
1563+
});
1564+
HandleTable(cableLengthTable);
1565+
// Check that the profiles for 0m do not exist, 5m profile could be still there, because it is shared by other ports
15361566
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
15371567
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
15381568
// Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
15391569
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:3-4") == m_dynamicBuffer->m_portPgLookup.end());
15401570
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
15411571

1542-
// 6. Check if port MTU update, PG and profile still there
1543-
InitCableLength("Ethernet0", "5m");
1572+
// 8. Check if port MTU update, PG and profile still there.
1573+
cableLengthTable.set("AZURE",
1574+
{
1575+
{"Ethernet0", "5m"}
1576+
});
1577+
HandleTable(cableLengthTable);
15441578
string mtu = "4096";
1545-
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
1546-
static_cast<Orch *>(m_dynamicBuffer)->doTask();
1579+
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
15471580
// Check if the profile is created correctly
15481581
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
15491582
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
15501583

15511584
// 7. Check if lossy PG can still be created
15521585
InitBufferPg("Ethernet0|0", "ingress_lossy_profile");
1553-
InitCableLength("Ethernet0", "0m");
1586+
cableLengthTable.set("AZURE",
1587+
{
1588+
{"Ethernet0", "0m"}
1589+
});
1590+
HandleTable(cableLengthTable);
15541591
bool found = false;
15551592
auto it = m_dynamicBuffer->m_portPgLookup.find("Ethernet0");
15561593
if (it != m_dynamicBuffer->m_portPgLookup.end()) {
15571594
found = (it->second.find("Ethernet0:0") != it->second.end());
15581595
}
15591596
ASSERT_TRUE(found);
1597+
1598+
// 9. When the cable length is "0m", lossy PGs remain, while lossless PGs are deleted.
1599+
cableLengthTable.set("AZURE",
1600+
{
1601+
{"Ethernet0", "0m"}
1602+
});
1603+
HandleTable(cableLengthTable);
1604+
it = m_dynamicBuffer->m_portPgLookup.find("Ethernet0");
1605+
if (it != m_dynamicBuffer->m_portPgLookup.end()) {
1606+
found = (it->second.find("Ethernet0:0") != it->second.end());
1607+
}
1608+
ASSERT_TRUE(found);
1609+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1610+
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
1611+
// Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
1612+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:3-4") == m_dynamicBuffer->m_portPgLookup.end());
1613+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
15601614
}
15611615
}

0 commit comments

Comments
 (0)