@@ -1471,4 +1471,77 @@ namespace buffermgrdyn_test
1471
1471
HandleTable (cableLengthTable);
1472
1472
ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet12" ].state , PORT_READY);
1473
1473
}
1474
+
1475
+ TEST_F (BufferMgrDynTest, SkipProfileCreationForZeroCableLength)
1476
+ {
1477
+ vector<FieldValueTuple> fieldValues;
1478
+ vector<string> keys;
1479
+
1480
+ // Prepare information that will be read at the beginning
1481
+ InitDefaultLosslessParameter ();
1482
+ InitMmuSize ();
1483
+
1484
+ StartBufferManager ();
1485
+
1486
+ InitPort ();
1487
+ ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet0" ].state , PORT_INITIALIZING);
1488
+
1489
+ SetPortInitDone ();
1490
+ // Timer will be called
1491
+ m_dynamicBuffer->doTask (m_selectableTable);
1492
+
1493
+ ASSERT_EQ (m_dynamicBuffer->m_bufferPoolLookup .size (), 0 );
1494
+ InitBufferPool ();
1495
+ ASSERT_EQ (m_dynamicBuffer->m_bufferPoolLookup .size (), 3 );
1496
+ appBufferPoolTable.getKeys (keys);
1497
+ ASSERT_EQ (keys.size (), 3 );
1498
+
1499
+ // Initialize buffer profiles
1500
+ InitBufferPg (" Ethernet0|3-4" );
1501
+ InitDefaultBufferProfile ();
1502
+ appBufferProfileTable.getKeys (keys);
1503
+ ASSERT_EQ (keys.size (), 3 );
1504
+ ASSERT_EQ (m_dynamicBuffer->m_bufferProfileLookup .size (), 3 );
1505
+
1506
+ // 1. Set cable length to "0m"
1507
+ InitCableLength (" Ethernet0" , " 0m" );
1508
+ ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet0" ].state , PORT_READY);
1509
+ // Expect profile not created
1510
+ auto zeroMProfile = " pg_lossless_100000_0m_profile" ;
1511
+ ASSERT_EQ (m_dynamicBuffer->m_bufferProfileLookup .find (zeroMProfile), m_dynamicBuffer->m_bufferProfileLookup .end ());
1512
+
1513
+ // 2. Check if the reference for 5m profile of this port had been deleted in buffer PG table
1514
+ // Since the cable length is set to 0m, previous profile for 5m should not exist.
1515
+ ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_5m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1516
+
1517
+ // 3. Add a PG, Ethernet0:6, it should not be created with 0m profile
1518
+ // The expectation is that no new PGs should be created with a cable length of 0m.
1519
+ InitBufferPg (" Ethernet0|6" );
1520
+ ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:6" ) == m_dynamicBuffer->m_portPgLookup .end ());
1521
+
1522
+ // 4. Update cable length to 5m, then Ethernet0:6 and Ethernet0:3-4 should be created with 5m profile
1523
+ InitCableLength (" Ethernet0" , " 5m" );
1524
+ m_dynamicBuffer->doTask ();
1525
+ // Check if the profiles are created correctly
1526
+ CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1527
+ CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1528
+
1529
+ // 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
1530
+ InitCableLength (" Ethernet0" , " 0m" );
1531
+ m_dynamicBuffer->doTask ();
1532
+ // Check that the profiles for 0m and 5m both do not exist
1533
+ ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_0m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1534
+ ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_5m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1535
+ // Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
1536
+ ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:3-4" ) == m_dynamicBuffer->m_portPgLookup .end ());
1537
+ ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:6" ) == m_dynamicBuffer->m_portPgLookup .end ());
1538
+
1539
+ // 6. Check if port MTU update, PG and profile still there
1540
+ InitCableLength (" Ethernet0" , " 5m" );
1541
+ string mtu = " 4096" ;
1542
+ m_dynamicBuffer->m_portInfoLookup [" Ethernet0" ].mtu = mtu;
1543
+ // Check if the profile is created correctly
1544
+ CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1545
+ CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1546
+ }
1474
1547
}
0 commit comments