@@ -467,6 +467,46 @@ namespace buffermgrdyn_test
467
467
}
468
468
}
469
469
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
+
470
510
void TearDown () override
471
511
{
472
512
delete m_dynamicBuffer;
@@ -1481,41 +1521,56 @@ namespace buffermgrdyn_test
1481
1521
Purpose: To verify the behavior of the buffer mgr dynamic when the cable length is set to "0m".
1482
1522
Here set to 0m indicates no lossless profile will be created, can still create lossy profile.
1483
1523
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
1493
1545
*/
1546
+
1494
1547
TEST_F (BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
1495
1548
{
1496
1549
vector<FieldValueTuple> fieldValues;
1497
1550
vector<string> keys;
1498
1551
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
1500
1554
InitDefaultLosslessParameter ();
1501
1555
InitMmuSize ();
1502
-
1503
- // 2. Start the Buffer Manager and initialize the port.
1504
1556
StartBufferManager ();
1505
1557
1558
+ // 2. Initialize port and verify initial state
1506
1559
InitPort ();
1507
1560
ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet0" ].state , PORT_INITIALIZING);
1508
1561
1562
+ // 3. Set port initialization as done and process tasks
1509
1563
SetPortInitDone ();
1510
1564
m_dynamicBuffer->doTask (m_selectableTable);
1511
1565
1566
+ // 4. Initialize buffer pools and verify
1512
1567
ASSERT_EQ (m_dynamicBuffer->m_bufferPoolLookup .size (), 0 );
1513
1568
InitBufferPool ();
1514
1569
ASSERT_EQ (m_dynamicBuffer->m_bufferPoolLookup .size (), 3 );
1515
1570
appBufferPoolTable.getKeys (keys);
1516
1571
ASSERT_EQ (keys.size (), 3 );
1517
1572
1518
- // Initialize buffer profiles
1573
+ // 5. Initialize buffer profiles and PGs with 5m cable length
1519
1574
InitBufferPg (" Ethernet0|3-4" );
1520
1575
InitDefaultBufferProfile ();
1521
1576
appBufferProfileTable.getKeys (keys);
@@ -1524,93 +1579,93 @@ namespace buffermgrdyn_test
1524
1579
InitCableLength (" Ethernet0" , " 5m" );
1525
1580
ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet0" ].state , PORT_READY);
1526
1581
1582
+ // 6. Verify PG configuration with 5m cable length
1527
1583
auto expectedProfile = " pg_lossless_100000_5m_profile" ;
1528
1584
CheckPg (" Ethernet0" , " Ethernet0:3-4" , expectedProfile);
1529
1585
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" }});
1535
1589
HandleTable (cableLengthTable);
1536
- // Expect profile not created
1590
+
1591
+ // 8. Verify that no 0m profile is created and existing profile is removed
1537
1592
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" ;
1540
1599
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 " ;
1544
1603
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
1547
1606
InitBufferPg (" Ethernet0|6" );
1548
- ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:6" ) == m_dynamicBuffer->m_portPgLookup .end ());
1549
1607
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" }});
1555
1617
HandleTable (cableLengthTable);
1556
- // Check if the profiles are created correctly
1618
+ m_dynamicBuffer->doTask ();
1619
+
1620
+ // 14. Verify that profiles are restored correctly
1557
1621
CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1558
1622
CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1559
1623
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" }});
1565
1633
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" }});
1578
1647
HandleTable (cableLengthTable);
1579
1648
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
1582
1652
CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1583
1653
CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1584
1654
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
1586
1657
InitBufferPg (" Ethernet0|0" , " ingress_lossy_profile" );
1587
- cableLengthTable.set (" AZURE" ,
1588
- {
1589
- {" Ethernet0" , " 0m" }
1590
- });
1658
+ cableLengthTable.set (" AZURE" , {{" Ethernet0" , " 0m" }});
1591
1659
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
1660
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 );
1615
1670
}
1616
1671
}
0 commit comments