diff --git a/orchagent/p4orch/tests/fake_portorch.cpp b/orchagent/p4orch/tests/fake_portorch.cpp index a21294d8dd..f16ff2409a 100644 --- a/orchagent/p4orch/tests/fake_portorch.cpp +++ b/orchagent/p4orch/tests/fake_portorch.cpp @@ -582,7 +582,7 @@ bool PortsOrch::getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uin return true; } -void PortsOrch::generateQueueMapPerPort(const Port &port) +void PortsOrch::generateQueueMapPerPort(const Port &port, bool voq) { } diff --git a/orchagent/port.h b/orchagent/port.h index a5e003584b..7df17edb20 100644 --- a/orchagent/port.h +++ b/orchagent/port.h @@ -144,6 +144,7 @@ class Port std::set m_members; std::set m_child_ports; std::vector m_queue_ids; + std::vector m_voq_ids; std::vector m_priority_group_ids; sai_port_priority_flow_control_mode_t m_pfc_asym = SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED; uint8_t m_pfc_bitmask = 0; // PFC enable bit mask diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 666c908734..057e7cbe1b 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -369,6 +369,8 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector(new DBConnector("COUNTERS_DB", 0)); m_counterTable = unique_ptr(new Table(m_counter_db.get(), COUNTERS_PORT_NAME_MAP)); + m_counterSysPortTable = unique_ptr
( + new Table(m_counter_db.get(), COUNTERS_SYSTEM_PORT_NAME_MAP)); m_counterLagTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_LAG_NAME_MAP)); FieldValueTuple tuple("", ""); vector defaultLagFv; @@ -383,6 +385,7 @@ PortsOrch::PortsOrch(DBConnector *db, DBConnector *stateDb, vector(new Table(m_counter_db.get(), COUNTERS_QUEUE_NAME_MAP)); + m_voqTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_VOQ_NAME_MAP)); m_queuePortTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_PORT_MAP)); m_queueIndexTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_INDEX_MAP)); m_queueTypeTable = unique_ptr
(new Table(m_counter_db.get(), COUNTERS_QUEUE_TYPE_MAP)); @@ -2465,6 +2468,9 @@ bool PortsOrch::getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uin case SAI_QUEUE_TYPE_MULTICAST: type = "SAI_QUEUE_TYPE_MULTICAST"; break; + case SAI_QUEUE_TYPE_UNICAST_VOQ: + type = "SAI_QUEUE_TYPE_UNICAST_VOQ"; + break; default: SWSS_LOG_ERROR("Got unsupported queue type %d for %" PRIu64 " queue", attr[0].value.s32, queue_id); throw runtime_error("Got unsupported queue type"); @@ -2797,7 +2803,7 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde /* when a port is added and queue map counter is enabled --> we need to add queue map counter for it */ if (m_isQueueMapGenerated) { - generateQueueMapPerPort(p); + generateQueueMapPerPort(p, false); } PortUpdate update = { p, true }; @@ -4512,6 +4518,51 @@ void PortsOrch::doTask(Consumer &consumer) } } +void PortsOrch::initializeVoqs(Port &port) +{ + SWSS_LOG_ENTER(); + + sai_attribute_t attr; + attr.id = SAI_SYSTEM_PORT_ATTR_QOS_NUMBER_OF_VOQS; + sai_status_t status = sai_system_port_api->get_system_port_attribute( + port.m_system_port_oid, 1, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to get number of voqs for port %s rv:%d", port.m_alias.c_str(), status); + task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status); + if (handle_status != task_process_status::task_success) + { + throw runtime_error("PortsOrch initialization failure."); + } + } + SWSS_LOG_INFO("Get %d voq for port %s", attr.value.u32, port.m_alias.c_str()); + + port.m_voq_ids.resize(attr.value.u32); + + if (attr.value.u32 == 0) + { + return; + } + + attr.id = SAI_SYSTEM_PORT_ATTR_QOS_VOQ_LIST; + attr.value.objlist.count = (uint32_t)port.m_voq_ids.size(); + attr.value.objlist.list = port.m_voq_ids.data(); + + status = sai_system_port_api->get_system_port_attribute( + port.m_system_port_oid, 1, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to get voq list for port %s rv:%d", port.m_alias.c_str(), status); + task_process_status handle_status = handleSaiGetStatus(SAI_API_PORT, status); + if (handle_status != task_process_status::task_success) + { + throw runtime_error("PortsOrch initialization failure."); + } + } + + SWSS_LOG_INFO("Get voqs for port %s", port.m_alias.c_str()); +} + void PortsOrch::initializeQueues(Port &port) { SWSS_LOG_ENTER(); @@ -5981,8 +6032,17 @@ void PortsOrch::generateQueueMap() { if (it.second.m_type == Port::PHY) { - generateQueueMapPerPort(it.second); + generateQueueMapPerPort(it.second, false); + if (gMySwitchType == "voq") + { + generateQueueMapPerPort(it.second, true); + } } + + if (it.second.m_type == Port::SYSTEM) + { + generateQueueMapPerPort(it.second, true); + } } m_isQueueMapGenerated = true; @@ -6026,7 +6086,7 @@ void PortsOrch::removeQueueMapPerPort(const Port& port) CounterCheckOrch::getInstance().removePort(port); } -void PortsOrch::generateQueueMapPerPort(const Port& port) +void PortsOrch::generateQueueMapPerPort(const Port& port, bool voq) { /* Create the Queue map in the Counter DB */ /* Add stat counters to flex_counter */ @@ -6034,32 +6094,61 @@ void PortsOrch::generateQueueMapPerPort(const Port& port) vector queuePortVector; vector queueIndexVector; vector queueTypeVector; + std::vector queue_ids; + if (voq) + { + queue_ids = port.m_voq_ids; + } + else + { + queue_ids = port.m_queue_ids; + } - for (size_t queueIndex = 0; queueIndex < port.m_queue_ids.size(); ++queueIndex) + for (size_t queueIndex = 0; queueIndex < queue_ids.size(); ++queueIndex) { std::ostringstream name; - name << port.m_alias << ":" << queueIndex; + if (voq) + { + name << port.m_system_port_info.alias << ":" << queueIndex; + } + else + { + name << port.m_alias << ":" << queueIndex; + } - const auto id = sai_serialize_object_id(port.m_queue_ids[queueIndex]); + const auto id = sai_serialize_object_id(queue_ids[queueIndex]); queueVector.emplace_back(name.str(), id); queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id)); string queueType; uint8_t queueRealIndex = 0; - if (getQueueTypeAndIndex(port.m_queue_ids[queueIndex], queueType, queueRealIndex)) + if (getQueueTypeAndIndex(queue_ids[queueIndex], queueType, queueRealIndex)) { queueTypeVector.emplace_back(id, queueType); queueIndexVector.emplace_back(id, to_string(queueRealIndex)); } + if (voq) + { + queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_system_port_oid)); + } + else + { + queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_port_id)); + } + // Install a flex counter for this queue to track stats std::unordered_set counter_stats; for (const auto& it: queue_stat_ids) { counter_stats.emplace(sai_serialize_queue_stat(it)); } - queue_stat_manager.setCounterIdList(port.m_queue_ids[queueIndex], CounterType::QUEUE, counter_stats); + queue_stat_manager.setCounterIdList(queue_ids[queueIndex], CounterType::QUEUE, counter_stats); + + if (voq) { + continue; + } /* add watermark queue counters */ string key = getQueueWatermarkFlexCounterTableKey(id); @@ -6078,7 +6167,14 @@ void PortsOrch::generateQueueMapPerPort(const Port& port) m_flexCounterTable->set(key, fieldValues); } - m_queueTable->set("", queueVector); + if (voq) + { + m_voqTable->set("", queueVector); + } + else + { + m_queueTable->set("", queueVector); + } m_queuePortTable->set("", queuePortVector); m_queueIndexTable->set("", queueIndexVector); m_queueTypeTable->set("", queueTypeVector); @@ -7361,7 +7457,14 @@ bool PortsOrch::addSystemPorts() port.m_system_port_info.speed = attrs[1].value.sysportconfig.speed; port.m_system_port_info.num_voq = attrs[1].value.sysportconfig.num_voq; + initializeVoqs( port ); setPort(port.m_alias, port); + /* Add system port name map to counter table */ + FieldValueTuple tuple(port.m_system_port_info.alias, + sai_serialize_object_id(system_port_oid)); + vector fields; + fields.push_back(tuple); + m_counterSysPortTable->set("", fields); if(m_port_ref_count.find(port.m_alias) == m_port_ref_count.end()) { m_port_ref_count[port.m_alias] = 0; diff --git a/orchagent/portsorch.h b/orchagent/portsorch.h index 46be1bd2c5..08e3e87f60 100755 --- a/orchagent/portsorch.h +++ b/orchagent/portsorch.h @@ -182,10 +182,12 @@ class PortsOrch : public Orch, public Subject private: unique_ptr
m_counterTable; + unique_ptr
m_counterSysPortTable; unique_ptr
m_counterLagTable; unique_ptr
m_portTable; unique_ptr
m_gearboxTable; unique_ptr
m_queueTable; + unique_ptr
m_voqTable; unique_ptr
m_queuePortTable; unique_ptr
m_queueIndexTable; unique_ptr
m_queueTypeTable; @@ -288,6 +290,7 @@ class PortsOrch : public Orch, public Subject void initializePriorityGroups(Port &port); void initializePortBufferMaximumParameters(Port &port); void initializeQueues(Port &port); + void initializeVoqs(Port &port); bool addHostIntfs(Port &port, string alias, sai_object_id_t &host_intfs_id); bool setHostIntfsStripTag(Port &port, sai_hostif_vlan_tag_t strip); @@ -344,7 +347,7 @@ class PortsOrch : public Orch, public Subject bool getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uint8_t &index); bool m_isQueueMapGenerated = false; - void generateQueueMapPerPort(const Port& port); + void generateQueueMapPerPort(const Port& port, bool voq); void removeQueueMapPerPort(const Port& port); bool m_isPriorityGroupMapGenerated = false;