diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 21318fa319..30efedb6c7 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -288,6 +288,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector &tableNames) m_cpuPort = Port("CPU", Port::CPU); m_cpuPort.m_port_id = attr.value.oid; + initCpuPort(m_cpuPort); m_portList[m_cpuPort.m_alias] = m_cpuPort; m_port_ref_count[m_cpuPort.m_alias] = 0; @@ -1787,6 +1788,11 @@ sai_status_t PortsOrch::removePort(sai_object_id_t port_id) return status; } +string PortsOrch::getPortFlexCounterTableKey(string key) +{ + return string(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key; +} + string PortsOrch::getQueueWatermarkFlexCounterTableKey(string key) { return string(QUEUE_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP) + ":" + key; @@ -1871,6 +1877,35 @@ bool PortsOrch::initPort(const string &alias, const int index, const set &l return true; } +void PortsOrch::initCpuPort(Port &cpu_port) +{ + SWSS_LOG_ENTER(); + + initializeQueues(cpu_port); + + /* Add port name map to counter table */ + FieldValueTuple tuple(cpu_port.m_alias, sai_serialize_object_id(cpu_port.m_port_id)); + vector fields; + fields.push_back(tuple); + m_counterTable->set("", fields); + + /* Add port to flex_counter for updating stat counters */ + string key = getPortFlexCounterTableKey(sai_serialize_object_id(cpu_port.m_port_id)); + std::string delimiter = ""; + std::ostringstream counters_stream; + for (const auto &id: port_stat_ids) + { + counters_stream << delimiter << sai_serialize_port_stat(id); + delimiter = comma; + } + + fields.clear(); + fields.emplace_back(PORT_COUNTER_ID_LIST, counters_stream.str()); + + m_flexCounterTable->set(key, fields); + return; +} + void PortsOrch::deInitPort(string alias, sai_object_id_t port_id) { SWSS_LOG_ENTER(); @@ -3934,7 +3969,7 @@ void PortsOrch::generateQueueMap() for (const auto& it: m_portList) { - if (it.second.m_type == Port::PHY) + if ((it.second.m_type == Port::PHY) || (it.second.m_type == Port::CPU)) { generateQueueMapPerPort(it.second); } diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 4d7ebb25b1..7488e45693 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -144,6 +144,7 @@ class PortsOrch : public Orch, public Subject unique_ptr m_flexCounterGroupTable; std::string getQueueWatermarkFlexCounterTableKey(std::string s); + std::string getPortFlexCounterTableKey(std::string s); std::string getPriorityGroupWatermarkFlexCounterTableKey(std::string s); std::string getPortRateFlexCounterTableKey(std::string s); @@ -235,6 +236,7 @@ class PortsOrch : public Orch, public Subject bool addPort(const set &lane_set, uint32_t speed, int an=0, string fec=""); sai_status_t removePort(sai_object_id_t port_id); bool initPort(const string &alias, const int index, const set &lane_set); + void initCpuPort(Port &cpu_port); void deInitPort(string alias, sai_object_id_t port_id); bool setPortAdminStatus(Port &port, bool up);