@@ -2378,6 +2378,18 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
23782378 port_buffer_drop_stat_manager.setCounterIdList (p.m_port_id , CounterType::PORT, port_buffer_drop_stats);
23792379 }
23802380
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+
23812393 PortUpdate update = { p, true };
23822394 notify (SUBJECT_TYPE_PORT_CHANGE, static_cast <void *>(&update));
23832395
@@ -2410,8 +2422,13 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
24102422{
24112423 SWSS_LOG_ENTER ();
24122424
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+ }
24152432
24162433 /* remove port from flex_counter_table for updating counters */
24172434 auto flex_counters_orch = gDirectory .get <FlexCounterOrch*>();
@@ -2425,9 +2442,20 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
24252442 port_buffer_drop_stat_manager.clearCounterIdList (p.m_port_id );
24262443 }
24272444
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+ }
24282456
24292457 /* remove port name map from counter table */
2430- m_counter_db ->hdel (COUNTERS_PORT_NAME_MAP , alias);
2458+ m_counterTable ->hdel (" " , alias);
24312459
24322460 /* Remove the associated port serdes attribute */
24332461 removePortSerdesAttribute (p.m_port_id );
@@ -2436,7 +2464,6 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id)
24362464 SWSS_LOG_NOTICE (" De-Initialized port %s" , alias.c_str ());
24372465}
24382466
2439-
24402467bool PortsOrch::bake ()
24412468{
24422469 SWSS_LOG_ENTER ();
@@ -5409,6 +5436,44 @@ void PortsOrch::generateQueueMap()
54095436 m_isQueueMapGenerated = true ;
54105437}
54115438
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+
54125477void PortsOrch::generateQueueMapPerPort (const Port& port)
54135478{
54145479 /* Create the Queue map in the Counter DB */
@@ -5487,6 +5552,32 @@ void PortsOrch::generatePriorityGroupMap()
54875552 m_isPriorityGroupMapGenerated = true ;
54885553}
54895554
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+
54905581void PortsOrch::generatePriorityGroupMapPerPort (const Port& port)
54915582{
54925583 /* Create the PG map in the Counter DB */
@@ -5644,7 +5735,7 @@ void PortsOrch::doTask(NotificationConsumer &consumer)
56445735 updateDbPortOperSpeed (port, 0 );
56455736 }
56465737 }
5647-
5738+
56485739 /* update m_portList */
56495740 m_portList[port.m_alias ] = port;
56505741 }
0 commit comments