@@ -137,6 +137,11 @@ namespace buffermgrdyn_test
137
137
{" size" , " 1024000" }
138
138
};
139
139
140
+ testBufferProfile[" ingress_lossy_profile" ] = {
141
+ {" dynamic_th" , " 7" },
142
+ {" pool" , " ingress_lossless_pool" },
143
+ {" size" , " 0" }
144
+ };
140
145
testBufferProfile[" ingress_lossless_profile" ] = {
141
146
{" dynamic_th" , " 7" },
142
147
{" pool" , " ingress_lossless_pool" },
@@ -522,8 +527,8 @@ namespace buffermgrdyn_test
522
527
523
528
InitDefaultBufferProfile ();
524
529
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 );
527
532
for (auto i : testBufferProfile)
528
533
{
529
534
CheckProfile (m_dynamicBuffer->m_bufferProfileLookup [i.first ], testBufferProfile[i.first ]);
@@ -647,7 +652,7 @@ namespace buffermgrdyn_test
647
652
appBufferPoolTable.getKeys (keys);
648
653
ASSERT_EQ (keys.size (), 3 );
649
654
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 );
651
656
for (auto i : testBufferProfile)
652
657
{
653
658
CheckProfile (m_dynamicBuffer->m_bufferProfileLookup [i.first ], testBufferProfile[i.first ]);
@@ -933,8 +938,8 @@ namespace buffermgrdyn_test
933
938
934
939
InitDefaultBufferProfile ();
935
940
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 );
938
943
for (auto i : testBufferProfile)
939
944
{
940
945
CheckProfile (m_dynamicBuffer->m_bufferProfileLookup [i.first ], testBufferProfile[i.first ]);
@@ -1267,8 +1272,8 @@ namespace buffermgrdyn_test
1267
1272
ASSERT_EQ (keys.size (), 3 );
1268
1273
InitDefaultBufferProfile ();
1269
1274
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 );
1272
1277
1273
1278
m_dynamicBuffer->m_bufferCompletelyInitialized = true ;
1274
1279
m_dynamicBuffer->m_waitApplyAdditionalZeroProfiles = 0 ;
@@ -1471,4 +1476,141 @@ namespace buffermgrdyn_test
1471
1476
HandleTable (cableLengthTable);
1472
1477
ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet12" ].state , PORT_READY);
1473
1478
}
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
+ }
1474
1616
}
0 commit comments