diff --git a/dataplane/base.h b/dataplane/base.h index 7924576d..45afe6ea 100644 --- a/dataplane/base.h +++ b/dataplane/base.h @@ -64,6 +64,7 @@ class permanently tQueueId inQueueId; } workerPorts[CONFIG_YADECAP_WORKER_PORTS_SIZE]; + tPortId ports[CONFIG_YADECAP_PORTS_SIZE]; unsigned int ports_count; tQueueId outQueueId; diff --git a/dataplane/controlplane.cpp b/dataplane/controlplane.cpp index 382b4fd5..fe110f16 100644 --- a/dataplane/controlplane.cpp +++ b/dataplane/controlplane.cpp @@ -102,8 +102,10 @@ void cControlPlane::start() } /// start devices - for (tPortId portId = 0; portId < rte_eth_dev_count_avail(); portId++) + for (const auto& portIter : dataPlane->ports) { + const tPortId& portId = portIter.first; + int rc = rte_eth_dev_start(portId); if (rc) { @@ -319,11 +321,9 @@ common::idp::getWorkerStats::response cControlPlane::getWorkerStats(const common const auto& worker = dataPlane->workers.find(coreId)->second; std::map portsStats; - for (tPortId portId = 0; - portId < dataPlane->ports.size(); - portId++) + for (const auto& portIter : dataPlane->ports) { - portsStats[portId] = worker->statsPorts[portId]; + portsStats[portIter.first] = worker->statsPorts[portIter.first]; } response[coreId] = {worker->iteration, @@ -338,11 +338,9 @@ common::idp::getWorkerStats::response cControlPlane::getWorkerStats(const common for (const auto& [coreId, worker] : dataPlane->workers) { std::map portsStats; - for (tPortId portId = 0; - portId < dataPlane->ports.size(); - portId++) + for (const auto& portIter : dataPlane->ports) { - portsStats[portId] = worker->statsPorts[portId]; + portsStats[portIter.first] = worker->statsPorts[portIter.first]; } response[coreId] = {worker->iteration, diff --git a/dataplane/dataplane.cpp b/dataplane/dataplane.cpp index f171881b..598ad581 100644 --- a/dataplane/dataplane.cpp +++ b/dataplane/dataplane.cpp @@ -160,15 +160,6 @@ eResult cDataPlane::init(const std::string& binaryPath, return result; } - /// sanity check - if (rte_eth_dev_count_avail() != ports.size()) - { - YADECAP_LOG_ERROR("invalid ports count: %u != %lu\n", - rte_eth_dev_count_avail(), - ports.size()); - return eResult::invalidPortsCount; - } - mempool_log = rte_mempool_create("log", YANET_CONFIG_SAMPLES_SIZE, sizeof(samples::sample_t), 0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, MEMPOOL_F_NO_IOVA_CONTIG); result = initGlobalBases(); @@ -465,16 +456,17 @@ eResult cDataPlane::initPorts() for (const auto& configPortIter : config.ports) { const std::string& interfaceName = configPortIter.first; - const auto& [pci, symmetric_mode, rss_flags] = configPortIter.second; + const auto& [pci, name, symmetric_mode, rss_flags] = configPortIter.second; + (void)pci; tPortId portId; - if (strncmp(pci.data(), SOCK_DEV_PREFIX, strlen(SOCK_DEV_PREFIX)) == 0) + if (strncmp(name.data(), SOCK_DEV_PREFIX, strlen(SOCK_DEV_PREFIX)) == 0) { - portId = sock_dev_create(pci.data(), 0); + portId = sock_dev_create(name.data(), 0); } - else if (rte_eth_dev_get_port_by_name(pci.data(), &portId)) + else if (rte_eth_dev_get_port_by_name(name.data(), &portId)) { - YADECAP_LOG_ERROR("invalid pci: '%s'\n", pci.data()); + YADECAP_LOG_ERROR("invalid name: '%s'\n", name.data()); remove_keys.emplace_back(interfaceName); continue; } @@ -588,17 +580,6 @@ eResult cDataPlane::initPorts() config.ports.erase(interface_name); } - for (const auto& [port_id, port] : ports) - { - (void)port; - - if (port_id >= ports.size()) - { - YADECAP_LOG_ERROR("invalid portId: '%u'\n", port_id); - return eResult::invalidPortId; - } - } - return eResult::success; } @@ -853,7 +834,12 @@ eResult cDataPlane::initWorkers() dataplane::base::permanently basePermanently; basePermanently.globalBaseAtomic = globalBaseAtomics[socket_id]; basePermanently.outQueueId = outQueueId; ///< 0 - basePermanently.ports_count = ports.size(); + basePermanently.ports_count = 0; + for (const auto& portIter : ports) + { + basePermanently.ports[basePermanently.ports_count++] = portIter.first; + } + basePermanently.SWNormalPriorityRateLimitPerWorker = config.SWNormalPriorityRateLimitPerWorker; dataplane::base::generation base; @@ -929,12 +915,15 @@ eResult cDataPlane::initWorkers() basePermanently.nat64stateful_numa_id = rte_cpu_to_be_16(socket_id); } + basePermanently.ports_count = 0; for (const auto& [port_id, port] : ports) { const auto& [interface_name, rx_queues, tx_queues_count, mac_address, pci, symmetric_mode] = port; (void)mac_address; (void)pci; + basePermanently.ports[basePermanently.ports_count++] = port_id; + if (exist(rx_queues, coreId)) { YANET_LOG_DEBUG("worker[%u]: add_worker_port(port_id: %u, queue_id: %u)\n", @@ -999,7 +988,6 @@ eResult cDataPlane::initWorkers() } basePermanently.outQueueId = outQueueId; - basePermanently.ports_count = ports.size(); dataplane::base::generation base; { @@ -1759,6 +1747,7 @@ eResult cDataPlane::parseJsonPorts(const nlohmann::json& json) { std::string interfaceName = portJson["interfaceName"]; std::string pci = portJson["pci"]; + std::string name = pci; bool symmetric_mode = false; uint64_t rss_flags = 0; @@ -1768,6 +1757,11 @@ eResult cDataPlane::parseJsonPorts(const nlohmann::json& json) return eResult::invalidConfigurationFile; } + if (exist(portJson, "name")) + { + name = portJson["name"]; + } + if (exist(portJson, "symmetric_mode")) { symmetric_mode = portJson["symmetric_mode"]; @@ -1787,7 +1781,7 @@ eResult cDataPlane::parseJsonPorts(const nlohmann::json& json) rss_flags = RTE_ETH_RSS_IP; } - config.ports[interfaceName] = {pci, symmetric_mode, rss_flags}; + config.ports[interfaceName] = {pci, name, symmetric_mode, rss_flags}; for (tCoreId coreId : portJson["coreIds"]) { @@ -2036,20 +2030,21 @@ eResult cDataPlane::checkConfig() } { - std::set pcis; + std::set names; for (const auto& portIter : config.ports) { - const auto& [pci, symmetric_mode, rss_flags] = portIter.second; + const auto& [pci, name, symmetric_mode, rss_flags] = portIter.second; + (void)pci; (void)symmetric_mode; (void)rss_flags; - if (exist(pcis, pci)) + if (exist(names, name)) { - YADECAP_LOG_ERROR("pci '%s' already exist\n", pci.data()); + YADECAP_LOG_ERROR("pci '%s' already exist\n", name.data()); return eResult::invalidConfigurationFile; } - pcis.emplace(pci); + names.emplace(name); } } @@ -2133,7 +2128,8 @@ eResult cDataPlane::initEal(const std::string& binaryPath, for (const auto& port : config.ports) { - const auto& [pci, symmetric_mode, rss_flags] = port.second; + const auto& [pci, name, symmetric_mode, rss_flags] = port.second; + (void)name; (void)symmetric_mode; (void)rss_flags; diff --git a/dataplane/dataplane.h b/dataplane/dataplane.h index 26077ea2..6519ea58 100644 --- a/dataplane/dataplane.h +++ b/dataplane/dataplane.h @@ -80,6 +80,7 @@ struct tDataPlaneConfig */ std::map> diff --git a/dataplane/globalbase.cpp b/dataplane/globalbase.cpp index 6be5dbe2..0b019e4e 100644 --- a/dataplane/globalbase.cpp +++ b/dataplane/globalbase.cpp @@ -623,7 +623,7 @@ eResult generation::updateLogicalPort(const common::idp::updateGlobalBase::updat YADECAP_LOG_ERROR("invalid logicalPortId: '%u'\n", logicalPortId); return eResult::invalidLogicalPortId; } - if (portId >= dataPlane->ports.size()) + if (!exist(dataPlane->ports, portId)) { YADECAP_LOG_ERROR("invalid portId: '%u'\n", portId); return eResult::invalidPortId; diff --git a/dataplane/worker.cpp b/dataplane/worker.cpp index 1a5f1db1..7dfb9089 100644 --- a/dataplane/worker.cpp +++ b/dataplane/worker.cpp @@ -1091,10 +1091,11 @@ inline void cWorker::physicalPort_ingress_handle(const unsigned int& worker_port inline void cWorker::physicalPort_egress_handle() { - for (tPortId portId = 0; - portId < basePermanently.ports_count; - portId++) + for (uint32_t portId_i = 0; + portId_i < basePermanently.ports_count; + portId_i++) { + const auto portId = basePermanently.ports[portId_i]; if (unlikely(physicalPort_stack[portId].mbufsCount == 0)) { continue;