@@ -1471,4 +1471,74 @@ 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
+ m_dynamicBuffer->doTask (m_selectableTable);
1491
+
1492
+ ASSERT_EQ (m_dynamicBuffer->m_bufferPoolLookup .size (), 0 );
1493
+ InitBufferPool ();
1494
+ ASSERT_EQ (m_dynamicBuffer->m_bufferPoolLookup .size (), 3 );
1495
+ appBufferPoolTable.getKeys (keys);
1496
+ ASSERT_EQ (keys.size (), 3 );
1497
+
1498
+ // Initialize buffer profiles
1499
+ InitBufferPg (" Ethernet0|3-4" );
1500
+ InitDefaultBufferProfile ();
1501
+ appBufferProfileTable.getKeys (keys);
1502
+ ASSERT_EQ (keys.size (), 3 );
1503
+ ASSERT_EQ (m_dynamicBuffer->m_bufferProfileLookup .size (), 3 );
1504
+
1505
+ // 1. Set cable length to "0m"
1506
+ InitCableLength (" Ethernet0" , " 0m" );
1507
+ ASSERT_EQ (m_dynamicBuffer->m_portInfoLookup [" Ethernet0" ].state , PORT_READY);
1508
+ // Expect profile not created
1509
+ auto zeroMProfile = " pg_lossless_100000_0m_profile" ;
1510
+ ASSERT_EQ (m_dynamicBuffer->m_bufferProfileLookup .find (zeroMProfile), m_dynamicBuffer->m_bufferProfileLookup .end ());
1511
+
1512
+ // 2. Check if the reference for 5m profile of this port had been deleted in buffer PG table
1513
+ // Since the cable length is set to 0m, previous profile for 5m should not exist.
1514
+ ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_5m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1515
+
1516
+ // 3. Add a PG, Ethernet0:6, it should not be created with 0m profile
1517
+ // The expectation is that no new PGs should be created with a cable length of 0m.
1518
+ InitBufferPg (" Ethernet0|6" );
1519
+ ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:6" ) == m_dynamicBuffer->m_portPgLookup .end ());
1520
+
1521
+ // 4. Update cable length to 5m, then Ethernet0:6 and Ethernet0:3-4 should be created with 5m profile
1522
+ InitCableLength (" Ethernet0" , " 5m" );
1523
+ // Check if the profiles are created correctly
1524
+ CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1525
+ CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1526
+
1527
+ // 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
1528
+ InitCableLength (" Ethernet0" , " 0m" );
1529
+ // Check that the profiles for 0m and 5m both do not exist
1530
+ ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_0m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1531
+ ASSERT_TRUE (m_dynamicBuffer->m_bufferProfileLookup .find (" pg_lossless_100000_5m_profile" ) == m_dynamicBuffer->m_bufferProfileLookup .end ());
1532
+ // Check that the PGs for Ethernet0:3-4 and Ethernet0:6 have been deleted
1533
+ ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:3-4" ) == m_dynamicBuffer->m_portPgLookup .end ());
1534
+ ASSERT_TRUE (m_dynamicBuffer->m_portPgLookup .find (" Ethernet0:6" ) == m_dynamicBuffer->m_portPgLookup .end ());
1535
+
1536
+ // 6. Check if port MTU update, PG and profile still there
1537
+ InitCableLength (" Ethernet0" , " 5m" );
1538
+ string mtu = " 4096" ;
1539
+ m_dynamicBuffer->m_portInfoLookup [" Ethernet0" ].mtu = mtu;
1540
+ // Check if the profile is created correctly
1541
+ CheckPg (" Ethernet0" , " Ethernet0:3-4" , " pg_lossless_100000_5m_profile" );
1542
+ CheckPg (" Ethernet0" , " Ethernet0:6" , " pg_lossless_100000_5m_profile" );
1543
+ }
1474
1544
}
0 commit comments