Skip to content

Commit eedbb68

Browse files
committed
Skip only lossless PGs when cable length is 0m
Changes: - Add lossless check in cable length handling - Only 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 5402d6a commit eedbb68

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

cfgmgr/buffermgrdyn.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,8 @@ 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")
947+
bool is_lossless = (profile_name.find("pg_lossless_") != string::npos);
948+
if (cable_len == "0m" && is_lossless)
948949
{
949950
SWSS_LOG_NOTICE("Not creating PG profile when cable length is set to %s", cable_len.c_str());
950951
return task_process_status::task_success;
@@ -1468,7 +1469,7 @@ task_process_status BufferMgrDynamic::refreshPgsForPort(const string &port, cons
14681469
continue;
14691470
}
14701471

1471-
if (cable_length == "0m")
1472+
if (cable_length == "0m" && it->second.lossless)
14721473
{
14731474
updateBufferObjectToDb(key, oldProfile, false); // 0m, remove PG.
14741475
SWSS_LOG_NOTICE("All profiles for port %s have been removed due to cable length being set to '0m'", port.c_str());

tests/mock_tests/buffermgrdyn_ut.cpp

+26-9
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;
@@ -1499,8 +1504,8 @@ namespace buffermgrdyn_test
14991504
InitBufferPg("Ethernet0|3-4");
15001505
InitDefaultBufferProfile();
15011506
appBufferProfileTable.getKeys(keys);
1502-
ASSERT_EQ(keys.size(), 3);
1503-
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 3);
1507+
ASSERT_EQ(keys.size(), 4);
1508+
ASSERT_EQ(m_dynamicBuffer->m_bufferProfileLookup.size(), 4);
15041509

15051510
// 1. Set cable length to "0m"
15061511
InitCableLength("Ethernet0", "0m");
@@ -1526,6 +1531,7 @@ namespace buffermgrdyn_test
15261531

15271532
// 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
15281533
InitCableLength("Ethernet0", "0m");
1534+
static_cast<Orch *>(m_dynamicBuffer)->doTask();
15291535
// Check that the profiles for 0m and 5m both do not exist
15301536
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_0m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
15311537
ASSERT_TRUE(m_dynamicBuffer->m_bufferProfileLookup.find("pg_lossless_100000_5m_profile") == m_dynamicBuffer->m_bufferProfileLookup.end());
@@ -1537,8 +1543,19 @@ namespace buffermgrdyn_test
15371543
InitCableLength("Ethernet0", "5m");
15381544
string mtu = "4096";
15391545
m_dynamicBuffer->m_portInfoLookup["Ethernet0"].mtu = mtu;
1546+
static_cast<Orch *>(m_dynamicBuffer)->doTask();
15401547
// Check if the profile is created correctly
15411548
CheckPg("Ethernet0", "Ethernet0:3-4", "pg_lossless_100000_5m_profile");
15421549
CheckPg("Ethernet0", "Ethernet0:6", "pg_lossless_100000_5m_profile");
1550+
1551+
// 7. Check if lossy PG can still be created
1552+
InitBufferPg("Ethernet0|0", "ingress_lossy_profile");
1553+
InitCableLength("Ethernet0", "0m");
1554+
bool found = false;
1555+
auto it = m_dynamicBuffer->m_portPgLookup.find("Ethernet0");
1556+
if (it != m_dynamicBuffer->m_portPgLookup.end()) {
1557+
found = (it->second.find("Ethernet0:0") != it->second.end());
1558+
}
1559+
ASSERT_TRUE(found);
15431560
}
15441561
}

0 commit comments

Comments
 (0)