Skip to content

Commit 3f54ab4

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 3f54ab4

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
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

+29-33
Original file line numberDiff line numberDiff line change
@@ -1487,10 +1487,11 @@ namespace buffermgrdyn_test
14871487
4. Existing lossless profiles are removed when the cable length is "0m".
14881488
5. No new lossless PG is created when the cable length is "0m".
14891489
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.
1490+
7. When the cable length is updated back to "0m", the lossless profiles are removed, PG still there.
14911491
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.
1492+
9. When the cable length is "0m", lossy PG and profile can still be created, lossless profile deleted.
14931493
*/
1494+
14941495
TEST_F(BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
14951496
{
14961497
vector<FieldValueTuple> fieldValues;
@@ -1536,7 +1537,7 @@ namespace buffermgrdyn_test
15361537
// Expect profile not created
15371538
auto zeroMProfile = "pg_lossless_100000_0m_profile";
15381539
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+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:3-4"].running_profile_name.empty());
15401541

15411542
// 4. Existing lossless profiles are removed when the cable length is "0m".
15421543
// Since the cable length is set to 0m, previous profile for 5m should not exist.
@@ -1545,30 +1546,38 @@ namespace buffermgrdyn_test
15451546
// 5. No new lossless PG is created when the cable length is "0m".
15461547
// The expectation is that no new PGs should be created with a cable length of 0m.
15471548
InitBufferPg("Ethernet0|6");
1548-
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup.find("Ethernet0:6") == m_dynamicBuffer->m_portPgLookup.end());
1549+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:6") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1550+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:6"].running_profile_name.empty());
15491551

15501552
// 6. When the cable length is updated to "5m", the correct lossless profiles and PGs are created.
15511553
cableLengthTable.set("AZURE",
15521554
{
15531555
{"Ethernet0", "5m"}
15541556
});
15551557
HandleTable(cableLengthTable);
1556-
// Check if the profiles are created correctly
1558+
m_dynamicBuffer->doTask();
1559+
// Check if the profiles are restored correctly
15571560
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
15581561
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
1562+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:3-4") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1563+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:6") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1564+
ASSERT_EQ(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:3-4"].running_profile_name, "pg_lossless_100000_5m_profile");
1565+
ASSERT_EQ(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:6"].running_profile_name, "pg_lossless_100000_5m_profile");
15591566

1560-
// 7. When the cable length is updated back to "0m", the lossless profiles and PGs are removed.
1567+
// 7. When the cable length is updated back to "0m", the lossless profiles are removed, PG still there.
15611568
cableLengthTable.set("AZURE",
15621569
{
15631570
{"Ethernet0", "0m"}
15641571
});
15651572
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
1573+
m_dynamicBuffer->doTask();
15671574
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
15681575
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());
1576+
// Check that the PGs for Ethernet0:3-4 and Ethernet0:6 are still there
1577+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:3-4") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1578+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:6") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1579+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:3-4"].running_profile_name.empty());
1580+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:6"].running_profile_name.empty());
15721581

15731582
// 8. Check if port MTU update, PG and profile still there.
15741583
cableLengthTable.set("AZURE",
@@ -1577,40 +1586,27 @@ namespace buffermgrdyn_test
15771586
});
15781587
HandleTable(cableLengthTable);
15791588
string mtu = "4096";
1580-
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
1589+
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
15811590
// Check if the profile is created correctly
15821591
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
15831592
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
15841593

1585-
// 7. Check if lossy PG can still be created
1594+
// 9. When the cable length is "0m", lossy PG and profile can still be created, lossless profile deleted.
15861595
InitBufferPg("Ethernet0|0", "ingress_lossy_profile");
15871596
cableLengthTable.set("AZURE",
15881597
{
15891598
{"Ethernet0", "0m"}
15901599
});
15911600
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);
1601+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:0") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1602+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:3-4") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1603+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"].find("Ethernet0:6") != m_dynamicBuffer->m_portPgLookup["Ethernet0"].end());
1604+
1605+
// Lossy profiles still there
1606+
ASSERT_EQ(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:0"].running_profile_name, "ingress_lossy_profile");
1607+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:3-4"].running_profile_name.empty());
1608+
ASSERT_TRUE(m_dynamicBuffer->m_portPgLookup["Ethernet0"]["Ethernet0:6"].running_profile_name.empty());
16101609
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
16111610
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());
16151611
}
16161612
}

0 commit comments

Comments
 (0)