@@ -2378,6 +2378,18 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
2378
2378
port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
2379
2379
}
2380
2380
2381
+ /* when a port is added and priority group map counter is enabled --> we need to add pg counter for it */
2382
+ if (m_isPriorityGroupMapGenerated)
2383
+ {
2384
+ generatePriorityGroupMapPerPort (p);
2385
+ }
2386
+
2387
+ /* when a port is added and queue map counter is enabled --> we need to add queue map counter for it */
2388
+ if (m_isQueueMapGenerated)
2389
+ {
2390
+ generateQueueMapPerPort (p);
2391
+ }
2392
+
2381
2393
PortUpdate update = { p, true };
2382
2394
notify (SUBJECT_TYPE_PORT_CHANGE, static_cast <void *>(&update));
2383
2395
@@ -2410,8 +2422,13 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
2410
2422
{
2411
2423
SWSS_LOG_ENTER ();
2412
2424
2413
- Port p (alias, Port::PHY);
2414
- p.m_port_id = port_id;
2425
+ Port p;
2426
+
2427
+ if (!getPort (port_id, p))
2428
+ {
2429
+ SWSS_LOG_ERROR (" Failed to get port object for port id 0x%" PRIx64, port_id);
2430
+ return ;
2431
+ }
2415
2432
2416
2433
/* remove port from flex_counter_table for updating counters */
2417
2434
auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
@@ -2425,9 +2442,20 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
2425
2442
port_buffer_drop_stat_manager.clearCounterIdList (p.m_port_id );
2426
2443
}
2427
2444
2445
+ /* remove pg port counters */
2446
+ if (m_isPriorityGroupMapGenerated)
2447
+ {
2448
+ removePriorityGroupMapPerPort (p);
2449
+ }
2450
+
2451
+ /* remove queue port counters */
2452
+ if (m_isQueueMapGenerated)
2453
+ {
2454
+ removeQueueMapPerPort (p);
2455
+ }
2428
2456
2429
2457
/* remove port name map from counter table */
2430
- m_counter_db ->hdel (COUNTERS_PORT_NAME_MAP , alias);
2458
+ m_counterTable ->hdel (" " , alias);
2431
2459
2432
2460
/* Remove the associated port serdes attribute */
2433
2461
removePortSerdesAttribute (p.m_port_id );
@@ -2436,7 +2464,6 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
2436
2464
SWSS_LOG_NOTICE (" De-Initialized port %s" , alias.c_str ());
2437
2465
}
2438
2466
2439
-
2440
2467
bool PortsOrch::bake ()
2441
2468
{
2442
2469
SWSS_LOG_ENTER ();
@@ -5409,6 +5436,44 @@ void PortsOrch::generateQueueMap()
5409
5436
m_isQueueMapGenerated = true ;
5410
5437
}
5411
5438
5439
+ void PortsOrch::removeQueueMapPerPort (const Port& port)
5440
+ {
5441
+ /* Remove the Queue map in the Counter DB */
5442
+
5443
+ for (size_t queueIndex = 0 ; queueIndex < port.m_queue_ids .size (); ++queueIndex)
5444
+ {
5445
+ std::ostringstream name;
5446
+ name << port.m_alias << " :" << queueIndex;
5447
+ std::unordered_set<string> counter_stats;
5448
+
5449
+ const auto id = sai_serialize_object_id (port.m_queue_ids [queueIndex]);
5450
+
5451
+ m_queueTable->hdel (" " ,name.str ());
5452
+ m_queuePortTable->hdel (" " ,id);
5453
+
5454
+ string queueType;
5455
+ uint8_t queueRealIndex = 0 ;
5456
+ if (getQueueTypeAndIndex (port.m_queue_ids [queueIndex], queueType, queueRealIndex))
5457
+ {
5458
+ m_queueTypeTable->hdel (" " ,id);
5459
+ m_queueIndexTable->hdel (" " ,id);
5460
+ }
5461
+
5462
+ for (const auto & it: queue_stat_ids)
5463
+ {
5464
+ counter_stats.emplace (sai_serialize_queue_stat (it));
5465
+ }
5466
+ queue_stat_manager.clearCounterIdList (port.m_queue_ids [queueIndex]);
5467
+
5468
+ /* remove watermark queue counters */
5469
+ string key = getQueueWatermarkFlexCounterTableKey (id);
5470
+
5471
+ m_flexCounterTable->del (key);
5472
+ }
5473
+
5474
+ CounterCheckOrch::getInstance ().removePort (port);
5475
+ }
5476
+
5412
5477
void PortsOrch::generateQueueMapPerPort (const Port& port)
5413
5478
{
5414
5479
/* Create the Queue map in the Counter DB */
@@ -5487,6 +5552,32 @@ void PortsOrch::generatePriorityGroupMap()
5487
5552
m_isPriorityGroupMapGenerated = true ;
5488
5553
}
5489
5554
5555
+ void PortsOrch::removePriorityGroupMapPerPort (const Port& port)
5556
+ {
5557
+ /* Remove the PG map in the Counter DB */
5558
+
5559
+ for (size_t pgIndex = 0 ; pgIndex < port.m_priority_group_ids .size (); ++pgIndex)
5560
+ {
5561
+ std::ostringstream name;
5562
+ name << port.m_alias << " :" << pgIndex;
5563
+
5564
+ const auto id = sai_serialize_object_id (port.m_priority_group_ids [pgIndex]);
5565
+ string key = getPriorityGroupWatermarkFlexCounterTableKey (id);
5566
+
5567
+ m_pgTable->hdel (" " ,name.str ());
5568
+ m_pgPortTable->hdel (" " ,id);
5569
+ m_pgIndexTable->hdel (" " ,id);
5570
+
5571
+ m_flexCounterTable->del (key);
5572
+
5573
+ key = getPriorityGroupDropPacketsFlexCounterTableKey (id);
5574
+ /* remove dropped packets counters to flex_counter */
5575
+ m_flexCounterTable->del (key);
5576
+ }
5577
+
5578
+ CounterCheckOrch::getInstance ().removePort (port);
5579
+ }
5580
+
5490
5581
void PortsOrch::generatePriorityGroupMapPerPort (const Port& port)
5491
5582
{
5492
5583
/* Create the PG map in the Counter DB */
@@ -5644,7 +5735,7 @@ void PortsOrch::doTask(NotificationConsumer &consumer)
5644
5735
updateDbPortOperSpeed (port, 0 );
5645
5736
}
5646
5737
}
5647
-
5738
+
5648
5739
/* update m_portList */
5649
5740
m_portList[port.m_alias ] = port;
5650
5741
}
0 commit comments