From 50e60a77040982691d92777847c6e23c1b41daf8 Mon Sep 17 00:00:00 2001 From: Ivan Morozko Date: Tue, 24 Dec 2024 19:33:44 +0400 Subject: [PATCH] Trying to build pcap++ with DPDK --- autotest/autotest.h | 1 + autotest/meson.build | 1 + common/bufferring.h | 2 ++ dataplane/controlplane.cpp | 3 +++ dataplane/sharedmemory.cpp | 27 ++++++++++++++++++++------- dataplane/sharedmemory.h | 6 +++--- logger/meson.build | 4 +--- meson.build | 21 +++++++++++++++++++++ subprojects/pcap | 2 +- 9 files changed, 53 insertions(+), 14 deletions(-) diff --git a/autotest/autotest.h b/autotest/autotest.h index 9d57a889..4c69292f 100644 --- a/autotest/autotest.h +++ b/autotest/autotest.h @@ -107,6 +107,7 @@ class tAutotest pcaps; std::tuple rawShmInfo; + //TODO: this should be DumpRingBase instead of PacketBufferRing. std::map dumpRings; std::vector threads; diff --git a/autotest/meson.build b/autotest/meson.build index 7982a0fa..adbef75e 100644 --- a/autotest/meson.build +++ b/autotest/meson.build @@ -2,6 +2,7 @@ sources = files('autotest.cpp', 'main.cpp') dependencies = [] +dependencies += libdpdk.get_variable('dpdk_dep') dependencies += libjson.get_variable('nlohmann_json_dep') dependencies += dependency('libsystemd') dependencies += dependency('yaml-cpp', static: true) diff --git a/common/bufferring.h b/common/bufferring.h index 105a158e..1db01144 100644 --- a/common/bufferring.h +++ b/common/bufferring.h @@ -1,3 +1,5 @@ +#pragma once + #include #include #include diff --git a/dataplane/controlplane.cpp b/dataplane/controlplane.cpp index 4675293d..56c47f87 100644 --- a/dataplane/controlplane.cpp +++ b/dataplane/controlplane.cpp @@ -1038,9 +1038,11 @@ common::idp::get_shm_info::response cControlPlane::get_shm_info() return response; } +// I won't need this.. common::idp::hexdump_ring::response cControlPlane::hexdump_ring(const common::idp::hexdump_ring::request& request) { common::idp::hexdump_ring::response response; +#if 0 const std::string& requested_tag = request; std::string combined_hexdump; @@ -1073,6 +1075,7 @@ common::idp::hexdump_ring::response cControlPlane::hexdump_ring(const common::id } response.hexdumped_ring = combined_hexdump; +#endif #if 0 common::idp::get_shm_info::response shm_info = dataPlane->getShmInfo(); diff --git a/dataplane/sharedmemory.cpp b/dataplane/sharedmemory.cpp index ff0239f0..048dcd60 100644 --- a/dataplane/sharedmemory.cpp +++ b/dataplane/sharedmemory.cpp @@ -62,17 +62,30 @@ DumpRingPcap::DumpRingPcap(void* memory, size_t max_pkt_size, size_t pkt_count) * This class allows initialization with an already-created mbuf, making it * possible to safely pass the object to a Writer instance as the base class * RawPacket. In the original `MBufRawPacket` class, the `setMBuf` method - * was protected, but it has been incorporated into a new constructor. + * was protected, plus is requires to build PcapPlusPlus with DPDK support, + * which is unnecessary for such a small change. */ -struct MBufRawPacketCopy : public pcpp::MBufRawPacket +class MBufRawPacketCopy : public pcpp::RawPacket { - using MBufRawPacket::MBufRawPacket; + void SetMBuf(rte_mbuf* mbuf, timespec timestamp) + { + if (mbuf == nullptr) + { + std::cerr << "mbuf to set is nullptr" << std::endl; + return; + } + + setRawData(rte_pktmbuf_mtod(mbuf, const uint8_t*), rte_pktmbuf_pkt_len(mbuf), timestamp, pcpp::LINKTYPE_ETHERNET); + } - MBufRawPacketCopy(rte_mbuf* mBuf, const timespec& timestamp) : - MBufRawPacket() +public: + MBufRawPacketCopy(rte_mbuf* mbuf, const timespec& timestamp) : + RawPacket() { - setMBuf(mBuf, timestamp); + m_DeleteRawDataAtDestructor = false; + SetMBuf(mbuf, timestamp); } + }; void DumpRingPcap::Write(rte_mbuf* mbuf, [[maybe_unused]] common::globalBase::eFlowType flow_type, uint32_t time) @@ -80,7 +93,7 @@ void DumpRingPcap::Write(rte_mbuf* mbuf, [[maybe_unused]] common::globalBase::eF timespec ts = {.tv_sec = time, .tv_nsec = 0}; MBufRawPacketCopy raw_packet(mbuf, ts); - // TODO: can I do this, or should I use time obtained from basePermanently.globalBaseAtomic->currentTime? + // TODO: can I do this, or should I use time obtained from basePermanently.globalBaseAtomic->currentTime like I do now? /* timespec_get(&ts, TIME_UTC); */ dev_.WritePacket(raw_packet); diff --git a/dataplane/sharedmemory.h b/dataplane/sharedmemory.h index 387c0313..c33f9840 100644 --- a/dataplane/sharedmemory.h +++ b/dataplane/sharedmemory.h @@ -16,7 +16,7 @@ using DumpConfig = tDataPlaneConfig::DumpConfig; struct DumpRingBase { - virtual ~DumpRingBase(); + virtual ~DumpRingBase() = default; virtual void Write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type, uint32_t time) = 0; }; @@ -34,7 +34,7 @@ class DumpRingRaw : public DumpRingBase public: DumpRingRaw(void* memory, size_t max_pkt_size, size_t pkt_count); - ~DumpRingRaw() override = default; + ~DumpRingRaw() override = default; void Write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type, uint32_t time) override; @@ -48,7 +48,7 @@ class DumpRingPcap : public DumpRingBase public: DumpRingPcap(void* memory, size_t max_pkt_size, size_t pkt_count); - ~DumpRingPcap() override = default; + ~DumpRingPcap() override = default; void Write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type, uint32_t time) override; diff --git a/logger/meson.build b/logger/meson.build index c07d93eb..e37a4253 100644 --- a/logger/meson.build +++ b/logger/meson.build @@ -6,9 +6,7 @@ dependencies += dependency('threads') sources = files('main.cpp') -cpp_args = [] -cpp_args += '-fno-rtti' -cpp_args += '-march=corei7' +cpp_args = ['-fno-rtti', '-march=corei7'] executable('yanet-logger', sources, diff --git a/meson.build b/meson.build index 3386bf81..6a1d6cf0 100644 --- a/meson.build +++ b/meson.build @@ -47,6 +47,7 @@ if target_option.contains('librib') subdir_done() endif + libdpdk = subproject('dpdk', default_options: [ 'platform=generic', 'cpu_instruction_set=corei7', @@ -58,6 +59,19 @@ libdpdk = subproject('dpdk', default_options: [ libjson = subproject('json') +# # Run the fix_dpdk_pc.sh script immediately after configuring DPDK +# fix_dpdk_pc = run_command( +# find_program('sh'), +# 'fix_dpdk_pc.sh', +# meson.current_build_dir(), +# check: true +# ) + +# # Ensure the script ran successfully +# if fix_dpdk_pc.returncode() != 0 +# error('fix_dpdk_pc.sh failed to execute successfully.') +# endif + cmake = import('cmake') pcapplusplus_options = cmake.subproject_options() @@ -65,6 +79,13 @@ pcapplusplus_options.add_cmake_defines({ 'PCAPPP_BUILD_EXAMPLES': 'OFF', 'PCAPPP_BUILD_TESTS': 'OFF', 'PCAPPP_INSTALL': 'OFF', + + # 'PCAPPP_USE_DPDK': 'ON', + # 'DPDK_ROOT': meson.current_build_dir() / 'meson-private', + + # 'PKG_CONFIG_PATH': meson.current_build_dir() / 'meson-private', + # 'DPDK_ROOT': meson.current_source_dir() / 'subprojects' / 'dpdk', + # 'DPDK_BUILD_DIR': meson.current_build_dir() / 'subprojects' / 'dpdk', 'CMAKE_CXX_FLAGS': '-fexceptions', }) diff --git a/subprojects/pcap b/subprojects/pcap index 2bbad3fd..91160dc8 160000 --- a/subprojects/pcap +++ b/subprojects/pcap @@ -1 +1 @@ -Subproject commit 2bbad3fd662b055c92b22093aa514d4e796a748c +Subproject commit 91160dc8e158027a86c9208ad7f4982d83338f5f