@@ -1477,15 +1477,30 @@ namespace buffermgrdyn_test
1477
1477
ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet12" ].state , PORT_READY);
1478
1478
}
1479
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
+ */
1480
1494
TEST_F (BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
1481
1495
{
1482
1496
vector<FieldValueTuple> fieldValues;
1483
1497
vector<string> keys;
1484
1498
1485
- // Prepare information that will be read at the beginning
1499
+ // 1. Initialize the environment, including default lossless parameters and MMU size.
1486
1500
InitDefaultLosslessParameter ();
1487
1501
InitMmuSize ();
1488
1502
1503
+ // 2. Start the Buffer Manager and initialize the port.
1489
1504
StartBufferManager ();
1490
1505
1491
1506
InitPort ();
@@ -1506,56 +1521,95 @@ namespace buffermgrdyn_test
1506
1521
appBufferProfileTable.getKeys (keys);
1507
1522
ASSERT_EQ (keys.size (), 4 );
1508
1523
ASSERT_EQ (m_dynamicBuffer->m_bufferProfileLookup .size (), 4 );
1509
-
1510
- // 1. Set cable length to "0m"
1511
- InitCableLength (" Ethernet0" , " 0m" );
1524
+ InitCableLength (" Ethernet0" , " 5m" );
1512
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);
1513
1536
// Expect profile not created
1514
1537
auto zeroMProfile = " pg_lossless_100000_0m_profile" ;
1515
1538
ASSERT_EQ (m_dynamicBuffer->m_bufferProfileLookup .find (zeroMProfile), m_dynamicBuffer->m_bufferProfileLookup .end ());
1516
1539
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".
1518
1541
// Since the cable length is set to 0m, previous profile for 5m should not exist.
1519
1542
ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_5m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1520
1543
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".
1522
1545
// The expectation is that no new PGs should be created with a cable length of 0m.
1523
1546
InitBufferPg (" Ethernet0|6" );
1524
1547
ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:6" ) == m_dynamicBuffer->m_portPgLookup .end ());
1525
1548
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);
1528
1555
// Check if the profiles are created correctly
1529
1556
CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1530
1557
CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1531
1558
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
1536
1566
ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_0m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1537
1567
ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_5m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1538
1568
// Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
1539
1569
ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:3-4" ) == m_dynamicBuffer->m_portPgLookup .end ());
1540
1570
ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:6" ) == m_dynamicBuffer->m_portPgLookup .end ());
1541
1571
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);
1544
1578
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;
1547
1580
// Check if the profile is created correctly
1548
1581
CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1549
1582
CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1550
1583
1551
1584
// 7. Check if lossy PG can still be created
1552
1585
InitBufferPg (" Ethernet0|0" , " ingress_lossy_profile" );
1553
- InitCableLength (" Ethernet0" , " 0m" );
1586
+ cableLengthTable.set (" AZURE" ,
1587
+ {
1588
+ {" Ethernet0" , " 0m" }
1589
+ });
1590
+ HandleTable (cableLengthTable);
1554
1591
bool found = false ;
1555
1592
auto it = m_dynamicBuffer->m_portPgLookup .find (" Ethernet0" );
1556
1593
if (it != m_dynamicBuffer->m_portPgLookup .end ()) {
1557
1594
found = (it->second .find (" Ethernet0:0" ) != it->second .end ());
1558
1595
}
1559
1596
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 ());
1560
1614
}
1561
1615
}
0 commit comments