DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dpdklibs
src
wibeth
WIBEthPacketBuilder.cpp
Go to the documentation of this file.
1
4
#include "
dpdklibs/wibeth/WIBEthPacketBuilder.hpp
"
5
6
#include "
detdataformats/DAQEthHeader.hpp
"
7
8
#include <rte_byteorder.h>
9
#include <rte_ether.h>
10
#include <rte_ip.h>
11
#include <rte_udp.h>
12
13
#include <arpa/inet.h>
14
#include <netinet/in.h>
15
16
#include <cstdint>
17
#include <cstring>
18
#include <stdexcept>
19
#include <string>
20
21
namespace
dunedaq::dpdklibs::wibeth
{
22
23
rte_be32_t
24
parse_ipv4_addr
(
const
std::string& addr)
25
{
26
in_addr parsed{};
27
if
(inet_pton(AF_INET, addr.c_str(), &parsed) != 1) {
28
throw
std::runtime_error(
"Invalid IPv4 address: "
+ addr);
29
}
30
return
static_cast<
rte_be32_t
>
(parsed.s_addr);
31
}
32
33
void
34
patch_daq_header
(
void
* wibeth_frame,
const
HeaderPatch
& patch)
35
{
36
// The frame is at Ethernet offset 42, which does not satisfy the 8-byte
37
// alignment of DAQEthHeader. Patch an aligned local copy and copy it back
38
// rather than writing 64-bit bitfields through an unaligned pointer.
39
dunedaq::detdataformats::DAQEthHeader
daq_header;
40
std::memcpy(&daq_header, wibeth_frame,
sizeof
(daq_header));
41
if
(patch.
set_det_id
) {
42
daq_header.
det_id
= patch.
det_id
;
43
}
44
if
(patch.
set_seq_id
) {
45
daq_header.
seq_id
= patch.
seq_id
% 4096;
46
}
47
if
(patch.
force_block_length
) {
48
daq_header.
block_length
=
kWIBEthBlockLength
;
49
}
50
std::memcpy(wibeth_frame, &daq_header,
sizeof
(daq_header));
51
}
52
53
void
54
construct_packet
(
void
* ethernet_packet,
const
void
* wibeth_frame,
const
PacketConfig
& cfg,
const
HeaderPatch
& patch)
55
{
56
// Build the 42-byte Ethernet/IPv4/UDP header in a local object and memcpy it
57
// into place. The destination may have any alignment (mbuf data offset, test
58
// buffer), so caller storage is never written through a typed pointer.
59
// Value-initialization covers the whole object; the packed header type has no
60
// padding.
61
dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr
header{};
62
63
header.
eth_hdr
.dst_addr = cfg.
dst_mac
;
64
header.
eth_hdr
.src_addr = cfg.
src_mac
;
65
header.
eth_hdr
.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
66
67
header.
ipv4_hdr
.version_ihl = (4 << 4) | (
kIPv4HeaderBytes
/ 4);
68
header.
ipv4_hdr
.type_of_service = 0;
69
header.
ipv4_hdr
.total_length = rte_cpu_to_be_16(
static_cast<
std::uint16_t
>
(
kIPv4TotalBytes
));
70
header.
ipv4_hdr
.packet_id = rte_cpu_to_be_16(cfg.
packet_id
);
71
header.
ipv4_hdr
.fragment_offset = rte_cpu_to_be_16(0);
72
header.
ipv4_hdr
.time_to_live = 64;
73
header.
ipv4_hdr
.next_proto_id = IPPROTO_UDP;
74
header.
ipv4_hdr
.hdr_checksum = 0;
75
header.
ipv4_hdr
.src_addr = cfg.
src_ip
;
76
header.
ipv4_hdr
.dst_addr = cfg.
dst_ip
;
77
header.
ipv4_hdr
.hdr_checksum = rte_ipv4_cksum(&header.
ipv4_hdr
);
78
79
header.
udp_hdr
.src_port = rte_cpu_to_be_16(cfg.
src_port
);
80
header.
udp_hdr
.dst_port = rte_cpu_to_be_16(cfg.
dst_port
);
81
header.
udp_hdr
.dgram_len = rte_cpu_to_be_16(
static_cast<
std::uint16_t
>
(
kUDPDatagramBytes
));
82
header.
udp_hdr
.dgram_cksum = 0;
83
84
std::memcpy(ethernet_packet, &header,
kPacketHeaderBytes
);
85
86
auto
* frame =
static_cast<
std::uint8_t*
>
(ethernet_packet) +
kPacketHeaderBytes
;
87
std::memcpy(frame, wibeth_frame,
kWIBEthFrameBytes
);
88
patch_daq_header
(frame, patch);
89
}
90
91
}
// namespace dunedaq::dpdklibs::wibeth
DAQEthHeader.hpp
WIBEthPacketBuilder.hpp
dunedaq::dpdklibs::wibeth
Definition
WIBEthPacketBuilder.hpp:24
dunedaq::dpdklibs::wibeth::kWIBEthFrameBytes
constexpr std::size_t kWIBEthFrameBytes
Definition
WIBEthPacketBuilder.hpp:31
dunedaq::dpdklibs::wibeth::construct_packet
void construct_packet(void *ethernet_packet, const void *wibeth_frame, const PacketConfig &cfg, const HeaderPatch &patch={})
Definition
WIBEthPacketBuilder.cpp:54
dunedaq::dpdklibs::wibeth::kPacketHeaderBytes
constexpr std::size_t kPacketHeaderBytes
Definition
WIBEthPacketBuilder.hpp:29
dunedaq::dpdklibs::wibeth::patch_daq_header
void patch_daq_header(void *wibeth_frame, const HeaderPatch &patch)
Definition
WIBEthPacketBuilder.cpp:34
dunedaq::dpdklibs::wibeth::kIPv4HeaderBytes
constexpr std::size_t kIPv4HeaderBytes
Definition
WIBEthPacketBuilder.hpp:27
dunedaq::dpdklibs::wibeth::parse_ipv4_addr
rte_be32_t parse_ipv4_addr(const std::string &addr)
Definition
WIBEthPacketBuilder.cpp:24
dunedaq::dpdklibs::wibeth::kIPv4TotalBytes
constexpr std::size_t kIPv4TotalBytes
Definition
WIBEthPacketBuilder.hpp:34
dunedaq::dpdklibs::wibeth::kWIBEthBlockLength
constexpr std::uint16_t kWIBEthBlockLength
Definition
WIBEthPacketBuilder.hpp:36
dunedaq::dpdklibs::wibeth::kUDPDatagramBytes
constexpr std::size_t kUDPDatagramBytes
Definition
WIBEthPacketBuilder.hpp:35
dunedaq::detdataformats::DAQEthHeader
DAQEthHeader is a versioned and unified structure for every FE electronics.
Definition
DAQEthHeader.hpp:23
dunedaq::detdataformats::DAQEthHeader::det_id
word_t det_id
Definition
DAQEthHeader.hpp:26
dunedaq::detdataformats::DAQEthHeader::seq_id
word_t seq_id
Definition
DAQEthHeader.hpp:26
dunedaq::detdataformats::DAQEthHeader::block_length
word_t block_length
Definition
DAQEthHeader.hpp:27
dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr
Definition
IPV4UDPPacket.hpp:25
dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr::udp_hdr
struct rte_udp_hdr udp_hdr
Definition
IPV4UDPPacket.hpp:54
dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr::ipv4_hdr
struct rte_ipv4_hdr ipv4_hdr
Definition
IPV4UDPPacket.hpp:37
dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr::eth_hdr
struct rte_ether_hdr eth_hdr
Definition
IPV4UDPPacket.hpp:26
dunedaq::dpdklibs::wibeth::HeaderPatch
Definition
WIBEthPacketBuilder.hpp:64
dunedaq::dpdklibs::wibeth::HeaderPatch::set_det_id
bool set_det_id
Definition
WIBEthPacketBuilder.hpp:65
dunedaq::dpdklibs::wibeth::HeaderPatch::force_block_length
bool force_block_length
Definition
WIBEthPacketBuilder.hpp:69
dunedaq::dpdklibs::wibeth::HeaderPatch::seq_id
std::uint64_t seq_id
Definition
WIBEthPacketBuilder.hpp:68
dunedaq::dpdklibs::wibeth::HeaderPatch::set_seq_id
bool set_seq_id
Definition
WIBEthPacketBuilder.hpp:67
dunedaq::dpdklibs::wibeth::HeaderPatch::det_id
std::uint64_t det_id
Definition
WIBEthPacketBuilder.hpp:66
dunedaq::dpdklibs::wibeth::PacketConfig
Definition
WIBEthPacketBuilder.hpp:53
dunedaq::dpdklibs::wibeth::PacketConfig::dst_port
std::uint16_t dst_port
Definition
WIBEthPacketBuilder.hpp:59
dunedaq::dpdklibs::wibeth::PacketConfig::dst_ip
rte_be32_t dst_ip
Definition
WIBEthPacketBuilder.hpp:57
dunedaq::dpdklibs::wibeth::PacketConfig::dst_mac
rte_ether_addr dst_mac
Definition
WIBEthPacketBuilder.hpp:54
dunedaq::dpdklibs::wibeth::PacketConfig::packet_id
std::uint16_t packet_id
Definition
WIBEthPacketBuilder.hpp:60
dunedaq::dpdklibs::wibeth::PacketConfig::src_port
std::uint16_t src_port
Definition
WIBEthPacketBuilder.hpp:58
dunedaq::dpdklibs::wibeth::PacketConfig::src_mac
rte_ether_addr src_mac
Definition
WIBEthPacketBuilder.hpp:55
dunedaq::dpdklibs::wibeth::PacketConfig::src_ip
rte_be32_t src_ip
Definition
WIBEthPacketBuilder.hpp:56
Generated on
for DUNE-DAQ by
1.18.0