From a13a1a1ee4502096817f7174974c9bef37c1a00f Mon Sep 17 00:00:00 2001 From: saksarav Date: Thu, 6 Nov 2025 11:58:14 -0500 Subject: [PATCH] Update the COUNTER_DB with the new Port Object-Id when the Port is removed and created when the Port Speed is changed dynamically via GCU Signed-off-by: saksarav --- orchagent/portsorch.cpp | 75 ++++++++++++++++++++++++++++++++++------- orchagent/portsorch.h | 4 +++ 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 7f3c29f3c9..5da5402f68 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -4014,6 +4014,19 @@ void PortsOrch::registerPort(Port &p) auto wred_port_stats = generateCounterStats(wred_port_stat_ids, sai_serialize_port_stat); wred_port_stat_manager.setCounterIdList(p.m_port_id, CounterType::PORT, wred_port_stats); } + //Add the Queue Counters + if ((flex_counters_orch->getQueueCountersState()) || (flex_counters_orch->getQueueWatermarkCountersState())) + { + auto maxQueueNumber = static_cast(p.m_queue_ids.size()); + addPortBufferQueueCounters(p, 0, maxQueueNumber-1, false); + } + + //Add the PG Counters + if ((flex_counters_orch->getPgCountersState()) || (flex_counters_orch->getPgWatermarkCountersState())) + { + auto maxPgNumber = static_cast(p.m_priority_group_ids.size()); + addPortBufferPgCounters(p, 0, maxPgNumber-1); + } PortUpdate update = { p, true }; notify(SUBJECT_TYPE_PORT_CHANGE, static_cast(&update)); @@ -4062,6 +4075,20 @@ void PortsOrch::deInitPort(string alias, sai_object_id_t port_id) /* remove port name map from counter table */ m_counterNameMapUpdater->delCounterNameMap(alias); + if((flex_counters_orch->getQueueCountersState()) || (flex_counters_orch->getQueueWatermarkCountersState())) + { + // Remove the Port Queues from COUNTERS_DB + auto maxQueueNumber = static_cast(p.m_queue_ids.size()); + deletePortBufferQueueCounters(p, 0, maxQueueNumber-1, false); + } + + if ((flex_counters_orch->getPgCountersState()) || (flex_counters_orch->getPgWatermarkCountersState())) + { + // Remove the Priority Groups from COUNTERS_DB + auto maxPgNumber = static_cast(p.m_priority_group_ids.size()); + deletePortBufferPgCounters(p, 0, maxPgNumber-1); + } + /* Remove the associated port serdes attribute */ removePortSerdesAttribute(p.m_port_id); @@ -8292,12 +8319,6 @@ void PortsOrch::createPortBufferQueueCounters(const Port &port, string queues, b { SWSS_LOG_ENTER(); - /* Create the Queue map in the Counter DB */ - vector queueVector; - vector queuePortVector; - vector queueIndexVector; - vector queueTypeVector; - auto toks = tokenize(queues, '-'); auto startIndex = to_uint(toks[0]); auto endIndex = startIndex; @@ -8305,6 +8326,18 @@ void PortsOrch::createPortBufferQueueCounters(const Port &port, string queues, b { endIndex = to_uint(toks[1]); } + addPortBufferQueueCounters(port, startIndex, endIndex, skip_host_tx_queue); +} + +void PortsOrch::addPortBufferQueueCounters(const Port &port, uint32_t startIndex, uint32_t endIndex, bool skip_host_tx_queue) +{ + SWSS_LOG_ENTER(); + + /* Create the Queue map in the Counter DB */ + vector queueVector; + vector queuePortVector; + vector queueIndexVector; + vector queueTypeVector; for (auto queueIndex = startIndex; queueIndex <= endIndex; queueIndex++) { @@ -8369,6 +8402,12 @@ void PortsOrch::removePortBufferQueueCounters(const Port &port, string queues, b { endIndex = to_uint(toks[1]); } + deletePortBufferQueueCounters(port, startIndex, endIndex, skip_host_tx_queue); +} + +void PortsOrch::deletePortBufferQueueCounters(const Port &port, uint32_t startIndex, uint32_t endIndex, bool skip_host_tx_queue) +{ + SWSS_LOG_ENTER(); for (auto queueIndex = startIndex; queueIndex <= endIndex; queueIndex++) { @@ -8486,12 +8525,6 @@ void PortsOrch::createPortBufferPgCounters(const Port& port, string pgs) { SWSS_LOG_ENTER(); - /* Create the PG map in the Counter DB */ - /* Add stat counters to flex_counter */ - vector pgVector; - vector pgPortVector; - vector pgIndexVector; - auto toks = tokenize(pgs, '-'); auto startIndex = to_uint(toks[0]); auto endIndex = startIndex; @@ -8499,6 +8532,18 @@ void PortsOrch::createPortBufferPgCounters(const Port& port, string pgs) { endIndex = to_uint(toks[1]); } + addPortBufferPgCounters(port, startIndex, endIndex); +} + +void PortsOrch::addPortBufferPgCounters(const Port& port, uint32_t startIndex, uint32_t endIndex) +{ + SWSS_LOG_ENTER(); + + /* Create the PG map in the Counter DB */ + /* Add stat counters to flex_counter */ + vector pgVector; + vector pgPortVector; + vector pgIndexVector; for (auto pgIndex = startIndex; pgIndex <= endIndex; pgIndex++) { @@ -8654,6 +8699,12 @@ void PortsOrch::removePortBufferPgCounters(const Port& port, string pgs) { endIndex = to_uint(toks[1]); } + deletePortBufferPgCounters(port, startIndex, endIndex); +} + +void PortsOrch::deletePortBufferPgCounters(const Port& port, uint32_t startIndex, uint32_t endIndex) +{ + SWSS_LOG_ENTER(); for (auto pgIndex = startIndex; pgIndex <= endIndex; pgIndex++) { diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 3ed160cafd..5857b37f3c 100644 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -191,7 +191,9 @@ class PortsOrch : public Orch, public Subject void generateQueueMap(map queuesStateVector); uint32_t getNumberOfPortSupportedQueueCounters(string port); void createPortBufferQueueCounters(const Port &port, string queues, bool skip_host_tx_queue=true); + void addPortBufferQueueCounters(const Port &port, uint32_t startIndex, uint32_t endIndex, bool skip_host_tx_queue=true); void removePortBufferQueueCounters(const Port &port, string queues, bool skip_host_tx_queue=true); + void deletePortBufferQueueCounters(const Port &port, uint32_t startIndex, uint32_t endIndex, bool skip_host_tx_queue=true); void addQueueFlexCounters(map queuesStateVector); void addQueueWatermarkFlexCounters(map queuesStateVector); void addWredQueueFlexCounters(map queuesStateVector); @@ -199,7 +201,9 @@ class PortsOrch : public Orch, public Subject void generatePriorityGroupMap(map pgsStateVector); uint32_t getNumberOfPortSupportedPgCounters(string port); void createPortBufferPgCounters(const Port &port, string pgs); + void addPortBufferPgCounters(const Port& port, uint32_t startIndex, uint32_t endIndex); void removePortBufferPgCounters(const Port& port, string pgs); + void deletePortBufferPgCounters(const Port& port, uint32_t startIndex, uint32_t endIndex); void addPriorityGroupFlexCounters(map pgsStateVector); void addPriorityGroupWatermarkFlexCounters(map pgsStateVector);