DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::dpdklibs::wibeth Namespace Reference

Classes

struct  PacketConfig
struct  HeaderPatch

Functions

rte_be32_t parse_ipv4_addr (const std::string &addr)
void patch_daq_header (void *wibeth_frame, const HeaderPatch &patch)
void construct_packet (void *ethernet_packet, const void *wibeth_frame, const PacketConfig &cfg, const HeaderPatch &patch={})

Variables

constexpr std::size_t kEthernetHeaderBytes = sizeof(rte_ether_hdr)
constexpr std::size_t kIPv4HeaderBytes = sizeof(rte_ipv4_hdr)
constexpr std::size_t kUDPHeaderBytes = sizeof(rte_udp_hdr)
constexpr std::size_t kPacketHeaderBytes = sizeof(dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr)
constexpr std::size_t kDAQEthHeaderBytes = sizeof(dunedaq::detdataformats::DAQEthHeader)
constexpr std::size_t kWIBEthFrameBytes = sizeof(dunedaq::fddetdataformats::WIBEthFrame)
constexpr std::size_t kEthernetPacketBytes
constexpr std::size_t kIPv4TotalBytes = kIPv4HeaderBytes + kUDPHeaderBytes + kWIBEthFrameBytes
constexpr std::size_t kUDPDatagramBytes = kUDPHeaderBytes + kWIBEthFrameBytes
constexpr std::uint16_t kWIBEthBlockLength
constexpr std::uint64_t kDefaultTimestampStep = 2048
constexpr double kDefaultRateHz = 62500000.0 / static_cast<double>(kDefaultTimestampStep)

Function Documentation

◆ construct_packet()

void dunedaq::dpdklibs::wibeth::construct_packet ( void * ethernet_packet,
const void * wibeth_frame,
const PacketConfig & cfg,
const HeaderPatch & patch = {} )

Definition at line 54 of file WIBEthPacketBuilder.cpp.

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.
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}
constexpr std::size_t kWIBEthFrameBytes
constexpr std::size_t kPacketHeaderBytes
void patch_daq_header(void *wibeth_frame, const HeaderPatch &patch)
constexpr std::size_t kIPv4HeaderBytes
constexpr std::size_t kIPv4TotalBytes
constexpr std::size_t kUDPDatagramBytes

◆ parse_ipv4_addr()

rte_be32_t dunedaq::dpdklibs::wibeth::parse_ipv4_addr ( const std::string & addr)

Definition at line 24 of file WIBEthPacketBuilder.cpp.

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}

◆ patch_daq_header()

void dunedaq::dpdklibs::wibeth::patch_daq_header ( void * wibeth_frame,
const HeaderPatch & patch )

Definition at line 34 of file WIBEthPacketBuilder.cpp.

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.
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) {
49 }
50 std::memcpy(wibeth_frame, &daq_header, sizeof(daq_header));
51}
constexpr std::uint16_t kWIBEthBlockLength
DAQEthHeader is a versioned and unified structure for every FE electronics.

Variable Documentation

◆ kDAQEthHeaderBytes

std::size_t dunedaq::dpdklibs::wibeth::kDAQEthHeaderBytes = sizeof(dunedaq::detdataformats::DAQEthHeader)
constexpr

Definition at line 30 of file WIBEthPacketBuilder.hpp.

◆ kDefaultRateHz

double dunedaq::dpdklibs::wibeth::kDefaultRateHz = 62500000.0 / static_cast<double>(kDefaultTimestampStep)
constexpr

Definition at line 39 of file WIBEthPacketBuilder.hpp.

◆ kDefaultTimestampStep

std::uint64_t dunedaq::dpdklibs::wibeth::kDefaultTimestampStep = 2048
constexpr

Definition at line 38 of file WIBEthPacketBuilder.hpp.

◆ kEthernetHeaderBytes

std::size_t dunedaq::dpdklibs::wibeth::kEthernetHeaderBytes = sizeof(rte_ether_hdr)
constexpr

Definition at line 26 of file WIBEthPacketBuilder.hpp.

◆ kEthernetPacketBytes

std::size_t dunedaq::dpdklibs::wibeth::kEthernetPacketBytes
constexpr
Initial value:

Definition at line 32 of file WIBEthPacketBuilder.hpp.

◆ kIPv4HeaderBytes

std::size_t dunedaq::dpdklibs::wibeth::kIPv4HeaderBytes = sizeof(rte_ipv4_hdr)
constexpr

Definition at line 27 of file WIBEthPacketBuilder.hpp.

◆ kIPv4TotalBytes

std::size_t dunedaq::dpdklibs::wibeth::kIPv4TotalBytes = kIPv4HeaderBytes + kUDPHeaderBytes + kWIBEthFrameBytes
constexpr

Definition at line 34 of file WIBEthPacketBuilder.hpp.

◆ kPacketHeaderBytes

std::size_t dunedaq::dpdklibs::wibeth::kPacketHeaderBytes = sizeof(dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr)
constexpr

Definition at line 29 of file WIBEthPacketBuilder.hpp.

◆ kUDPDatagramBytes

std::size_t dunedaq::dpdklibs::wibeth::kUDPDatagramBytes = kUDPHeaderBytes + kWIBEthFrameBytes
constexpr

Definition at line 35 of file WIBEthPacketBuilder.hpp.

◆ kUDPHeaderBytes

std::size_t dunedaq::dpdklibs::wibeth::kUDPHeaderBytes = sizeof(rte_udp_hdr)
constexpr

Definition at line 28 of file WIBEthPacketBuilder.hpp.

◆ kWIBEthBlockLength

std::uint16_t dunedaq::dpdklibs::wibeth::kWIBEthBlockLength
constexpr
Initial value:
=
static_cast<std::uint16_t>((kWIBEthFrameBytes / sizeof(std::uint64_t)) - 1)

Definition at line 36 of file WIBEthPacketBuilder.hpp.

◆ kWIBEthFrameBytes

std::size_t dunedaq::dpdklibs::wibeth::kWIBEthFrameBytes = sizeof(dunedaq::fddetdataformats::WIBEthFrame)
constexpr

Definition at line 31 of file WIBEthPacketBuilder.hpp.