Skip to content

Commit

Permalink
Trying to build pcap++ with DPDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ol-imorozko committed Dec 24, 2024
1 parent 772a3eb commit 50e60a7
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 14 deletions.
1 change: 1 addition & 0 deletions autotest/autotest.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class tAutotest
pcaps;

std::tuple<size_t, void*> rawShmInfo;
//TODO: this should be DumpRingBase instead of PacketBufferRing.
std::map<std::string, common::PacketBufferRing> dumpRings;

std::vector<std::thread> threads;
Expand Down
1 change: 1 addition & 0 deletions autotest/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions common/bufferring.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <rte_build_config.h>
Expand Down
3 changes: 3 additions & 0 deletions dataplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
27 changes: 20 additions & 7 deletions dataplane/sharedmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,38 @@ 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)
{
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);
Expand Down
6 changes: 3 additions & 3 deletions dataplane/sharedmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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;

Expand All @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions logger/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if target_option.contains('librib')
subdir_done()
endif


libdpdk = subproject('dpdk', default_options: [
'platform=generic',
'cpu_instruction_set=corei7',
Expand All @@ -58,13 +59,33 @@ 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()
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',
})

Expand Down
2 changes: 1 addition & 1 deletion subprojects/pcap
Submodule pcap updated from 2bbad3 to 91160d

0 comments on commit 50e60a7

Please sign in to comment.