diff --git a/common/config.release.h b/common/config.release.h index c7a9df95..744d50a4 100644 --- a/common/config.release.h +++ b/common/config.release.h @@ -9,7 +9,7 @@ #define CONFIG_YADECAP_MTU (9000) #define CONFIG_YADECAP_IPV6_EXTENSIONS_MAX (8) #define CONFIG_YADECAP_IPV6_EXTENSION_SIZE_MAX (16) -#define CONFIG_YADECAP_LOGICALPORTS_SIZE (4096 * CONFIG_YADECAP_PORTS_SIZE) +#define CONFIG_YADECAP_LOGICALPORTS_SIZE (8192 * CONFIG_YADECAP_PORTS_SIZE) #define CONFIG_YADECAP_DECAPS_SIZE (16) #define CONFIG_YADECAP_TUN64_SIZE (8) #define CONFIG_YADECAP_TUN64_MAPPINGS_SIZE (32 * 1024) diff --git a/common/define.h b/common/define.h index 85807681..52770c0b 100644 --- a/common/define.h +++ b/common/define.h @@ -85,6 +85,8 @@ extern LogPriority logPriority; #define YANET_BALANCER_OPS_FLAG ((uint8_t)(1u << 1)) +#define CALCULATE_LOGICALPORT_ID(portId, vlanId) ((portId << 13) | ((vlanId & 0xFFF) << 1) | 1) + #if __cpp_exceptions #define YANET_THROW(string) throw string #else // __cpp_exceptions diff --git a/controlplane/configparser.cpp b/controlplane/configparser.cpp index c897aa55..a9a038e0 100644 --- a/controlplane/configparser.cpp +++ b/controlplane/configparser.cpp @@ -227,7 +227,7 @@ void config_parser_t::loadConfig_logicalPort(controlplane::base_t& baseNext, // - logicalPort.logicalPortId = (logicalPort.vlanId << 3) | logicalPort.physicalPortId; + logicalPort.logicalPortId = CALCULATE_LOGICALPORT_ID(logicalPort.physicalPortId, logicalPort.vlanId); baseNext.logicalport_id_to_name[logicalPort.logicalPortId] = moduleId; } diff --git a/dataplane/controlplane.cpp b/dataplane/controlplane.cpp index 0ea01183..382b4fd5 100644 --- a/dataplane/controlplane.cpp +++ b/dataplane/controlplane.cpp @@ -2595,11 +2595,11 @@ void cControlPlane::handlePacket_repeat(rte_mbuf* mbuf) { const rte_vlan_hdr* vlanHeader = rte_pktmbuf_mtod_offset(mbuf, rte_vlan_hdr*, sizeof(rte_ether_hdr)); - metadata->flow.data.logicalPortId = (rte_be_to_cpu_16(vlanHeader->vlan_tci & 0xFF0F) << 3) | metadata->fromPortId; + metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, rte_be_to_cpu_16(vlanHeader->vlan_tci)); } else { - metadata->flow.data.logicalPortId = metadata->fromPortId; + metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, 0); } /// @todo: opt diff --git a/dataplane/dataplane.cpp b/dataplane/dataplane.cpp index 7c16aa78..6509c272 100644 --- a/dataplane/dataplane.cpp +++ b/dataplane/dataplane.cpp @@ -1358,13 +1358,13 @@ eResult cDataPlane::allocateSharedMemory() { const auto& [dump_size, dump_count] = ring_cfg.second; - auto unit_size = sizeof(cSharedMemory::item_header_t) + dump_size; + auto unit_size = sizeof(sharedmemory::item_header_t) + dump_size; if (unit_size % RTE_CACHE_LINE_SIZE != 0) { unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up } - auto size = sizeof(cSharedMemory::ring_header_t) + unit_size * dump_count; + auto size = sizeof(sharedmemory::ring_header_t) + unit_size * dump_count; for (const auto& [socket_id, num] : number_of_workers_per_socket) { @@ -1462,13 +1462,13 @@ eResult cDataPlane::splitSharedMemoryPerWorkers() { const auto& [dump_size, units_number] = ring_cfg; - auto unit_size = sizeof(cSharedMemory::item_header_t) + dump_size; + auto unit_size = sizeof(sharedmemory::item_header_t) + dump_size; if (unit_size % RTE_CACHE_LINE_SIZE != 0) { unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up } - auto size = sizeof(cSharedMemory::ring_header_t) + unit_size * units_number; + auto size = sizeof(sharedmemory::ring_header_t) + unit_size * units_number; if (size % RTE_CACHE_LINE_SIZE != 0) { size += RTE_CACHE_LINE_SIZE - size % RTE_CACHE_LINE_SIZE; /// round up @@ -1480,7 +1480,7 @@ eResult cDataPlane::splitSharedMemoryPerWorkers() auto memaddr = (void*)((intptr_t)shm + offset); - cSharedMemory ring; + sharedmemory::cSharedMemory ring; ring.init(memaddr, unit_size, units_number); diff --git a/dataplane/sharedmemory.cpp b/dataplane/sharedmemory.cpp index dff82687..3168fba8 100644 --- a/dataplane/sharedmemory.cpp +++ b/dataplane/sharedmemory.cpp @@ -2,6 +2,8 @@ #include "common/type.h" #include "metadata.h" +using namespace sharedmemory; + eResult cSharedMemory::init(void* memory, int unit_size, int units_number) { buffer = common::bufferring(memory, unit_size, units_number); @@ -21,11 +23,11 @@ void cSharedMemory::write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_typ uint64_t wpos = (buffer.ring->header.before) % buffer.units_number; buffer.ring->header.before++; - common::bufferring::item_t* item = (common::bufferring::item_t*)((uintptr_t)buffer.ring->memory + (wpos * buffer.unit_size)); + item_t* item = (item_t*)((uintptr_t)buffer.ring->memory + (wpos * buffer.unit_size)); dataplane::metadata* metadata = YADECAP_METADATA(mbuf); - uint64_t memory_size = buffer.unit_size - sizeof(cSharedMemory::ring_header_t); + uint64_t memory_size = buffer.unit_size - sizeof(ring_header_t); uint64_t copy_size = RTE_MIN(memory_size, mbuf->data_len); item->header.size = copy_size; diff --git a/dataplane/sharedmemory.h b/dataplane/sharedmemory.h index cb365df3..b2ea8751 100644 --- a/dataplane/sharedmemory.h +++ b/dataplane/sharedmemory.h @@ -4,16 +4,21 @@ #include "common/result.h" #include "common/type.h" +namespace sharedmemory +{ + +using ring_header_t = common::bufferring::ring_header_t; +using ring_t = common::bufferring::ring_t; +using item_header_t = common::bufferring::item_header_t; +using item_t = common::bufferring::item_t; + class cSharedMemory { public: - using ring_header_t = common::bufferring::ring_header_t; - using ring_t = common::bufferring::ring_t; - using item_header_t = common::bufferring::item_header_t; - using item_t = common::bufferring::item_t; - eResult init(void* memory, int unit_size, int units_number); void write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type); common::bufferring buffer; }; + +} // namespace sharedmemory diff --git a/dataplane/worker.cpp b/dataplane/worker.cpp index bcc14c8c..1a5f1db1 100644 --- a/dataplane/worker.cpp +++ b/dataplane/worker.cpp @@ -1018,7 +1018,7 @@ inline void cWorker::handlePackets() } static_assert(CONFIG_YADECAP_PORTS_SIZE == 8, "(vlanId << 3) | metadata->fromPortId"); -static_assert(CONFIG_YADECAP_LOGICALPORTS_SIZE == CONFIG_YADECAP_PORTS_SIZE * 4096, "base.globalBase->logicalPorts[(vlanId << 3) | metadata->fromPortId]"); +static_assert(CONFIG_YADECAP_LOGICALPORTS_SIZE == CONFIG_YADECAP_PORTS_SIZE * 8192, "base.globalBase->logicalPorts[CALCULATE_LOGICALPORT_ID(metadata->fromPortId, vlanId)]"); inline void cWorker::physicalPort_ingress_handle(const unsigned int& worker_port_i) { @@ -1048,11 +1048,11 @@ inline void cWorker::physicalPort_ingress_handle(const unsigned int& worker_port { const rte_vlan_hdr* vlanHeader = rte_pktmbuf_mtod_offset(mbuf, rte_vlan_hdr*, sizeof(rte_ether_hdr)); - metadata->flow.data.logicalPortId = (rte_be_to_cpu_16(vlanHeader->vlan_tci & 0xFF0F) << 3) | metadata->fromPortId; + metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, rte_be_to_cpu_16(vlanHeader->vlan_tci)); } else { - metadata->flow.data.logicalPortId = metadata->fromPortId; + metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, 0); } metadata->in_logicalport_id = metadata->flow.data.logicalPortId; diff --git a/dataplane/worker.h b/dataplane/worker.h index cdf0f499..0ab5ad19 100644 --- a/dataplane/worker.h +++ b/dataplane/worker.h @@ -336,7 +336,7 @@ class cWorker // will decrease with each new packet sent to slow worker, replenishes each N mseconds int32_t packetsToSWNPRemainder; - cSharedMemory dumpRings[YANET_CONFIG_SHARED_RINGS_NUMBER]; + sharedmemory::cSharedMemory dumpRings[YANET_CONFIG_SHARED_RINGS_NUMBER]; samples::Sampler sampler;