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

Classes

struct  ipaddr
 
struct  ipv4_udp_packet
 
struct  ipv4_udp_packet_hdr
 

Enumerations

enum  { MIN_TOS = 0 , DEFAULT_TOS = MIN_TOS , DEFAULT_TTL = 8 }
 

Functions

rte_le16_t packet_fill (struct ipv4_udp_packet_hdr *packet_hdr)
 
void pktgen_udp_hdr_ctor (struct ipv4_udp_packet_hdr *packet_hdr, rte_le16_t packet_len, int sport=55677, int dport=55678)
 
void pktgen_ipv4_ctor (struct ipv4_udp_packet_hdr *packet_hdr, rte_le16_t packet_len, const std::string &src_ip_addr="0.0.0.0", const std::string &dst_ip_addr="0.0.0.0")
 
void pktgen_ether_hdr_ctor (struct ipv4_udp_packet_hdr *packet_hdr, const std::string &dst_mac_address="0a:00:10:c2:15:c1", const int port_id=0)
 
bool get_ether_addr6 (const char *s0, struct rte_ether_addr *ea)
 
void construct_packets_for_burst (const int port_id, const std::string &dst_mac_addr, const int payload_bytes, const int burst_size, rte_mbuf **bufs)
 
static int8_t get_xdigit (char ch)
 
std::uint16_t get_payload_size_udp_hdr (struct rte_udp_hdr *udp_hdr)
 
std::uint16_t get_payload_size (struct ipv4_udp_packet_hdr *ipv4_udp_hdr)
 
rte_be32_t ip_address_dotdecimal_to_binary (std::uint8_t byte1, std::uint8_t byte2, std::uint8_t byte3, std::uint8_t byte4)
 
struct ipaddr ip_address_binary_to_dotdecimal (rte_le32_t binary_ipv4_address)
 
std::string get_ipv4_decimal_addr_str (struct ipaddr ipv4_address)
 
char * get_udp_payload (const rte_mbuf *mbuf)
 
void hex_digits_to_stream (std::ostringstream &ostrs, int value, char separator=':', char fill='0', int digits=2)
 
std::string get_udp_header_str (struct rte_mbuf *mbuf)
 
std::string get_udp_packet_str (struct rte_mbuf *mbuf)
 
void add_file_contents_to_vector (const std::string &filename, std::vector< char > &buffervec)
 
std::vector< std::pair< const void *, int > > get_ethernet_packets (const std::vector< char > &buffervec)
 
void set_daqethheader_test_values (detdataformats::DAQEthHeader &daqethheader_obj) noexcept
 
std::string get_rte_mbuf_str (const rte_mbuf *mbuf) noexcept
 
std::string get_opmon_string (const StreamUID &sid)
 

Variables

struct dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr __rte_packed
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MIN_TOS 
DEFAULT_TOS 
DEFAULT_TTL 

Definition at line 19 of file PacketCtor.cpp.

Function Documentation

◆ add_file_contents_to_vector()

void dunedaq::dpdklibs::udp::add_file_contents_to_vector ( const std::string & filename,
std::vector< char > & buffervec )

Definition at line 168 of file Utils.cpp.

169{
170
171 char byte = 0x0;
172
173 std::ifstream packetfile;
174 packetfile.open(filename, std::ios::binary);
175
176 if (!packetfile) {
177 throw ::dunedaq::datahandlinglibs::CannotOpenFile(ERS_HERE, filename);
178 }
179
180 while (packetfile.get(byte)) {
181 buffervec.push_back(byte);
182 }
183
184 packetfile.close();
185}
#define ERS_HERE

◆ construct_packets_for_burst()

void dunedaq::dpdklibs::udp::construct_packets_for_burst ( const int port_id,
const std::string & dst_mac_addr,
const int payload_bytes,
const int burst_size,
rte_mbuf ** bufs )

Definition at line 202 of file PacketCtor.cpp.

202 {
203 struct ipv4_udp_packet_hdr packet_hdr;
204
205 constexpr int eth_header_bytes = 14;
206 constexpr int udp_header_bytes = 8;
207 constexpr int ipv4_header_bytes = 20;
208
209 int eth_packet_bytes = eth_header_bytes + ipv4_header_bytes + udp_header_bytes + sizeof(detdataformats::DAQEthHeader) + payload_bytes;
210 int ipv4_packet_bytes = eth_packet_bytes - eth_header_bytes;
211 int udp_datagram_bytes = ipv4_packet_bytes - ipv4_header_bytes;
212
213 // Get info for the ethernet header (protocol stack level 2)
214 pktgen_ether_hdr_ctor(&packet_hdr, dst_mac_addr, port_id);
215
216 // Get info for the internet header (protocol stack level 3)
217 pktgen_ipv4_ctor(&packet_hdr, ipv4_packet_bytes);
218
219 // Get info for the UDP header (protocol stack level 4)
220 pktgen_udp_hdr_ctor(&packet_hdr, udp_datagram_bytes);
221
222 detdataformats::DAQEthHeader daqethheader_obj;
223 set_daqethheader_test_values(daqethheader_obj);
224
225 void* dataloc = nullptr;
226 for (int i_pkt = 0; i_pkt < burst_size; ++i_pkt) {
227
228 dataloc = rte_pktmbuf_mtod(bufs[i_pkt], char*);
229 rte_memcpy(dataloc, &packet_hdr, sizeof(packet_hdr));
230
231 dataloc = rte_pktmbuf_mtod_offset(bufs[i_pkt], char*, sizeof(packet_hdr));
232 rte_memcpy(dataloc, &daqethheader_obj, sizeof(daqethheader_obj));
233
234 bufs[i_pkt]->pkt_len = eth_packet_bytes;
235 bufs[i_pkt]->data_len = eth_packet_bytes;
236 }
237}
void pktgen_ether_hdr_ctor(struct ipv4_udp_packet_hdr *packet_hdr, const std::string &dst_mac_address="0a:00:10:c2:15:c1", const int port_id=0)
void pktgen_ipv4_ctor(struct ipv4_udp_packet_hdr *packet_hdr, rte_le16_t packet_len, const std::string &src_ip_addr="0.0.0.0", const std::string &dst_ip_addr="0.0.0.0")
void set_daqethheader_test_values(detdataformats::DAQEthHeader &daqethheader_obj) noexcept
Definition Utils.cpp:232
void pktgen_udp_hdr_ctor(struct ipv4_udp_packet_hdr *packet_hdr, rte_le16_t packet_len, int sport=55677, int dport=55678)
DAQEthHeader is a versioned and unified structure for every FE electronics.

◆ get_ether_addr6()

bool dunedaq::dpdklibs::udp::get_ether_addr6 ( const char * s0,
struct rte_ether_addr * ea )

Definition at line 37 of file PacketCtor.cpp.

38{
39 const char *s = s0;
40 int i;
41
42 for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) {
43 int8_t x;
44
45 x = get_xdigit(*s++);
46 if (x < 0)
47 return false;
48
49 ea->addr_bytes[i] = x << 4;
50 x = get_xdigit(*s++);
51 if (x < 0)
52 return false;
53 ea->addr_bytes[i] |= x;
54
55 if (i < RTE_ETHER_ADDR_LEN - 1 &&
56 *s++ != ':')
57 return false;
58 }
59
60 /* return true if at end of string */
61 return *s == '\0';
62}
static int8_t get_xdigit(char ch)

◆ get_ethernet_packets()

std::vector< std::pair< const void *, int > > dunedaq::dpdklibs::udp::get_ethernet_packets ( const std::vector< char > & buffervec)

Definition at line 188 of file Utils.cpp.

189{
190
191 std::vector<std::pair<const void*, int>> ethernet_packets;
192 const std::vector<uint16_t> allowed_ethertypes{ 0x0800, 0x0806 };
193
194 for (int byte_index = 0; byte_index < buffervec.size();) {
195 const auto buf_ptr = &buffervec.at(byte_index);
196 auto hdr = reinterpret_cast<const ipv4_udp_packet_hdr*>(buf_ptr);
197
198 // A sanity check
199 bool match = false;
200 for (auto allowed_ethertype : allowed_ethertypes) {
201 if (hdr->eth_hdr.ether_type == rte_be_to_cpu_16(allowed_ethertype)) {
202 match = true;
203 break;
204 }
205 }
206
207 if (!match) {
208 std::stringstream msgstr;
209 msgstr << "Ether type in ethernet header (value " << std::hex << rte_be_to_cpu_16(hdr->eth_hdr.ether_type) << std::dec << ") either unknown or unsupported";
210 throw dunedaq::dpdklibs::BadPacketHeaderIssue(ERS_HERE, msgstr.str());
211 }
212
213 int ipv4_packet_size = rte_be_to_cpu_16(hdr->ipv4_hdr.total_length);
214 constexpr int min_packet_size = sizeof(rte_ipv4_hdr) + sizeof(rte_udp_hdr);
215 constexpr int max_packet_size = 10000;
216
217 if (ipv4_packet_size < min_packet_size || ipv4_packet_size > max_packet_size) {
218 std::stringstream msgstr;
219 msgstr << "Calculated IPv4 packet size of " << ipv4_packet_size << " bytes is out of the required range of (" << min_packet_size << ", " << max_packet_size << ") bytes";
220 throw dunedaq::dpdklibs::BadPacketHeaderIssue(ERS_HERE, msgstr.str());
221 }
222
223 int ethernet_packet_size = sizeof(rte_ether_hdr) + ipv4_packet_size;
224 ethernet_packets.emplace_back(std::pair<const void*, int>{ buf_ptr, ethernet_packet_size });
225 byte_index += ethernet_packet_size;
226 }
227
228 return ethernet_packets;
229}

◆ get_ipv4_decimal_addr_str()

std::string dunedaq::dpdklibs::udp::get_ipv4_decimal_addr_str ( struct ipaddr ipv4_address)

Definition at line 56 of file Utils.cpp.

57{
58 std::ostringstream ostrs;
59 ostrs << (unsigned)ipv4_address.addr_bytes[3] << '.' << (unsigned)ipv4_address.addr_bytes[2] << '.' << (unsigned)ipv4_address.addr_bytes[1] << '.' << (unsigned)ipv4_address.addr_bytes[0];
60 return ostrs.str();
61 /*printf("%i.%i.%i.%i",
62 ipv4_address.addr_bytes[3],
63 ipv4_address.addr_bytes[2],
64 ipv4_address.addr_bytes[1],
65 ipv4_address.addr_bytes[0]);
66 */
67}

◆ get_opmon_string()

std::string dunedaq::dpdklibs::udp::get_opmon_string ( const StreamUID & sid)

Definition at line 277 of file Utils.cpp.

278{
279 std::stringstream opmonstr;
280 opmonstr << "det" << sid.det_id << "_crt" << sid.crate_id << "_slt" << sid.slot_id << "_str" << sid.stream_id;
281 return opmonstr.str();
282}

◆ get_payload_size()

std::uint16_t dunedaq::dpdklibs::udp::get_payload_size ( struct ipv4_udp_packet_hdr * ipv4_udp_hdr)

Definition at line 35 of file Utils.cpp.

36{
37 return rte_be_to_cpu_16(ipv4_udp_hdr->udp_hdr.dgram_len) - sizeof(struct rte_udp_hdr);
38}

◆ get_payload_size_udp_hdr()

std::uint16_t dunedaq::dpdklibs::udp::get_payload_size_udp_hdr ( struct rte_udp_hdr * udp_hdr)

Definition at line 29 of file Utils.cpp.

30{
31 return rte_be_to_cpu_16(udp_hdr->dgram_len) - sizeof(struct rte_udp_hdr);
32}

◆ get_rte_mbuf_str()

std::string dunedaq::dpdklibs::udp::get_rte_mbuf_str ( const rte_mbuf * mbuf)
noexcept

Definition at line 246 of file Utils.cpp.

247{
248 std::stringstream ss;
249
250 ss << "\nrte_mbuf info:";
251 ss << "\npkt_len: " << mbuf->pkt_len;
252 ss << "\ndata_len: " << mbuf->data_len;
253 ss << "\nBuffer address: " << std::hex << mbuf->buf_addr;
254 ss << "\nRef count: " << std::dec << rte_mbuf_refcnt_read(mbuf);
255 ss << "\nport: " << mbuf->port;
256 ss << "\nol_flags: " << std::hex << mbuf->ol_flags;
257 ss << "\npacket_type: " << std::dec << mbuf->packet_type;
258 ss << "\nl2 type: " << static_cast<int>(mbuf->l2_type);
259 ss << "\nl3 type: " << static_cast<int>(mbuf->l3_type);
260 ss << "\nl4 type: " << static_cast<int>(mbuf->l4_type);
261 ss << "\ntunnel type: " << static_cast<int>(mbuf->tun_type);
262 ss << "\nInner l2 type: " << static_cast<int>(mbuf->inner_l2_type);
263 ss << "\nInner l3 type: " << static_cast<int>(mbuf->inner_l3_type);
264 ss << "\nInner l4 type: " << static_cast<int>(mbuf->inner_l4_type);
265 ss << "\nbuf_len: " << mbuf->buf_len;
266 ss << "\nl2_len: " << mbuf->l2_len;
267 ss << "\nl3_len: " << mbuf->l3_len;
268 ss << "\nl4_len: " << mbuf->l4_len;
269 ss << "\nouter_l2_len: " << mbuf->outer_l2_len;
270 ss << "\nouter_l3_len: " << mbuf->outer_l3_len;
271 ss << std::dec;
272
273 return ss.str();
274}

◆ get_udp_header_str()

std::string dunedaq::dpdklibs::udp::get_udp_header_str ( struct rte_mbuf * mbuf)

Definition at line 108 of file Utils.cpp.

109{
110 struct ipv4_udp_packet_hdr* pkt = rte_pktmbuf_mtod(mbuf, struct ipv4_udp_packet_hdr*);
111 std::ostringstream ostrs;
112 ostrs << "\n------ start of packet ----- \n";
113 ostrs << "dst mac addr: ";
114 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.dst_addr.addr_bytes[0]);
115 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.dst_addr.addr_bytes[1]);
116 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.dst_addr.addr_bytes[2]);
117 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.dst_addr.addr_bytes[3]);
118 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.dst_addr.addr_bytes[4]);
119 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.dst_addr.addr_bytes[5], '\n');
120 ostrs << "src mac addr: ";
121 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.src_addr.addr_bytes[0]);
122 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.src_addr.addr_bytes[1]);
123 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.src_addr.addr_bytes[2]);
124 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.src_addr.addr_bytes[3]);
125 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.src_addr.addr_bytes[4]);
126 hex_digits_to_stream(ostrs, (int)pkt->eth_hdr.src_addr.addr_bytes[5], '\n');
127 ostrs << "ethtype: " << (unsigned)pkt->eth_hdr.ether_type << '\n';
128
129 ostrs << "------ IP header ----- \n";
130 ostrs << "ipv4 version: " << (unsigned)pkt->ipv4_hdr.version_ihl << '\n';
131 ostrs << "ipv4 type_of_service: " << (unsigned)pkt->ipv4_hdr.type_of_service << '\n';
132 ostrs << "ipv4 total lenght: " << (unsigned)rte_be_to_cpu_16(pkt->ipv4_hdr.total_length) << '\n';
133 ostrs << "ipv4 packet_id: " << (unsigned)pkt->ipv4_hdr.packet_id << '\n';
134 ostrs << "ipv4 fragment_offset: " << (unsigned)pkt->ipv4_hdr.fragment_offset << '\n';
135 ostrs << "ipv4 time_to_live: " << (unsigned)pkt->ipv4_hdr.time_to_live << '\n';
136 ostrs << "ipv4 next_proto_id: " << (unsigned)pkt->ipv4_hdr.next_proto_id << '\n';
137 ostrs << "ipv4 checksum: " << (unsigned)rte_be_to_cpu_16(pkt->ipv4_hdr.hdr_checksum) << '\n';
138 std::string srcaddr = get_ipv4_decimal_addr_str(ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(pkt->ipv4_hdr.src_addr)));
139 std::string dstaddr = get_ipv4_decimal_addr_str(ip_address_binary_to_dotdecimal(rte_be_to_cpu_32(pkt->ipv4_hdr.dst_addr)));
140 ostrs << "src_addr: " << srcaddr << '\n';
141 ostrs << "dst_addr: " << dstaddr << '\n';
142
143 ostrs << "------ UDP header ----- \n";
144 ostrs << "UDP src_port: " << (unsigned)rte_be_to_cpu_16(pkt->udp_hdr.src_port) << '\n';
145 ostrs << "UDP dst_port: " << (unsigned)rte_be_to_cpu_16(pkt->udp_hdr.dst_port) << '\n';
146 ostrs << "UDP len: " << (unsigned)rte_be_to_cpu_16(pkt->udp_hdr.dgram_len) << '\n';
147 ostrs << "UDP checksum: " << (unsigned)rte_be_to_cpu_16(pkt->udp_hdr.dgram_cksum) << '\n';
148
149 return ostrs.str();
150}
std::string get_ipv4_decimal_addr_str(struct ipaddr ipv4_address)
Definition Utils.cpp:56
struct ipaddr ip_address_binary_to_dotdecimal(rte_le32_t binary_ipv4_address)
Definition Utils.cpp:48

◆ get_udp_packet_str()

std::string dunedaq::dpdklibs::udp::get_udp_packet_str ( struct rte_mbuf * mbuf)

Definition at line 153 of file Utils.cpp.

154{
155 struct ipv4_udp_packet_hdr* pkt = rte_pktmbuf_mtod(mbuf, struct ipv4_udp_packet_hdr*);
156 char* payload = (char*)(pkt);
157 std::ostringstream ostrs;
158 std::uint8_t byte;
159 for (byte = 0; byte < rte_be_to_cpu_16(pkt->udp_hdr.dgram_len); byte++) {
160 hex_digits_to_stream(ostrs, (unsigned)(*(payload + byte)), ' ');
161 // printf("%02x ", *(payload + byte) & 0xFF);
162 // printf("%s", (payload + byte));
163 }
164 return ostrs.str();
165}

◆ get_udp_payload()

char * dunedaq::dpdklibs::udp::get_udp_payload ( const rte_mbuf * mbuf)

Definition at line 70 of file Utils.cpp.

71{
72 struct ipv4_udp_packet_hdr* udp_packet = rte_pktmbuf_mtod(mbuf, struct ipv4_udp_packet_hdr*);
73 // dump_udp_header(udp_packet);
74 // uint16_t payload_size = get_payload_size(udp_packet);
75 char* payload = (char*)(udp_packet + 1);
76 return payload;
77
78 /*
79 if (dump_mode == 10) {
80 return payload;
81 }
82
83 if (dump_mode == 0 || dump_mode == 3) {
84 printf("UDP Payload size: %i\n", payload_size);
85 uint byte;
86 for (byte = 0; byte < payload_size; byte++) {
87 printf("%02x ", *(payload + byte) & 0xFF);
88 //printf("%s", (payload + byte));
89 }
90 printf("\n");
91 }
92
93 if (dump_mode == 1 || dump_mode == 3) {
94 printf("%s\n", payload);
95 }
96 return payload;
97 */
98}

◆ get_xdigit()

static int8_t dunedaq::dpdklibs::udp::get_xdigit ( char ch)
static

Definition at line 25 of file PacketCtor.cpp.

26{
27 if (ch >= '0' && ch <= '9')
28 return ch - '0';
29 if (ch >= 'a' && ch <= 'f')
30 return ch - 'a' + 10;
31 if (ch >= 'A' && ch <= 'F')
32 return ch - 'A' + 10;
33 return -1;
34}
PDS Frame with unphysical timestamp detected with ch

◆ hex_digits_to_stream()

void dunedaq::dpdklibs::udp::hex_digits_to_stream ( std::ostringstream & ostrs,
int value,
char separator = ':',
char fill = '0',
int digits = 2 )
inline

Definition at line 101 of file Utils.cpp.

101 :', char fill = '0', int digits = 2)
102{
103 ostrs << std::setfill(fill) << std::setw(digits) << std::hex << value << std::dec << separator;
104}

◆ ip_address_binary_to_dotdecimal()

struct ipaddr dunedaq::dpdklibs::udp::ip_address_binary_to_dotdecimal ( rte_le32_t binary_ipv4_address)

Definition at line 48 of file Utils.cpp.

49{
50 struct ipaddr addr;
51 memcpy(&addr, &binary_ipv4_address, sizeof(rte_le32_t));
52 return addr;
53}

◆ ip_address_dotdecimal_to_binary()

rte_be32_t dunedaq::dpdklibs::udp::ip_address_dotdecimal_to_binary ( std::uint8_t byte1,
std::uint8_t byte2,
std::uint8_t byte3,
std::uint8_t byte4 )

Definition at line 41 of file Utils.cpp.

42{
43 rte_le32_t ip_address = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
44 return rte_cpu_to_be_32(ip_address);
45}

◆ packet_fill()

rte_le16_t dunedaq::dpdklibs::udp::packet_fill ( struct ipv4_udp_packet_hdr * packet_hdr)

Definition at line 66 of file PacketCtor.cpp.

67{
68 //rte_le16_t total_length = 64;
69 //char message[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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EEEEEEEEEEEEE";
74
75
76
77 char * payload = (char *)(packet_hdr + 1);
78 memcpy(payload, message, total_length);
79 return total_length;
80}

◆ pktgen_ether_hdr_ctor()

void dunedaq::dpdklibs::udp::pktgen_ether_hdr_ctor ( struct ipv4_udp_packet_hdr * packet_hdr,
const std::string & router_mac_address,
const int port_id )

pktgen_ether_hdr_ctor - Ethernet header constructor routine.

DESCRIPTION Construct the ethernet header for a given packet buffer.

RETURNS: Pointer to memory after the ethernet header.

SEE ALSO:

Definition at line 183 of file PacketCtor.cpp.

184{
185 //pg_ether_addr_copy(&pkt->eth_src_addr, &eth->src_addr);
186 //pg_ether_addr_copy(&pkt->eth_dst_addr, &eth->dst_addr);
187
188 /* src and dest addr */
189 // See definition dpdk-20.08/lib/librte_net/rte_ether.c is defined as static -> not exposed to the lib... redefining here
190
191 get_ether_addr6(router_mac_address.c_str(), &packet_hdr->eth_hdr.dst_addr);
192
193 rte_eth_macaddr_get(port_id, &packet_hdr->eth_hdr.src_addr);
194
195 /* normal ethernet header */
196 packet_hdr->eth_hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
197 return;
198}
bool get_ether_addr6(const char *s0, struct rte_ether_addr *ea)

◆ pktgen_ipv4_ctor()

void dunedaq::dpdklibs::udp::pktgen_ipv4_ctor ( struct ipv4_udp_packet_hdr * packet_hdr,
rte_le16_t packet_len,
const std::string & src_ip_addr,
const std::string & dst_ip_addr )

pktgen_ipv4_ctor - Construct the IPv4 header for a packet

DESCRIPTION Constructor for the IPv4 header for a given packet.

RETURNS: N/A

SEE ALSO:

Definition at line 119 of file PacketCtor.cpp.

120{
121 /* IPv4 Header constructor */
122
123 /* Zero out the header space */
124 memset((char *) &packet_hdr->ipv4_hdr, 0, sizeof(struct rte_ipv4_hdr));
125
126 IpAddr src(src_ip_addr);
127 IpAddr dst(dst_ip_addr);
128
129 struct ipaddr src_reversed_order;
130 src_reversed_order.addr_bytes[3] = src.addr_bytes[0];
131 src_reversed_order.addr_bytes[2] = src.addr_bytes[1];
132 src_reversed_order.addr_bytes[1] = src.addr_bytes[2];
133 src_reversed_order.addr_bytes[0] = src.addr_bytes[3];
134
135 struct ipaddr dst_reversed_order;
136 dst_reversed_order.addr_bytes[3] = dst.addr_bytes[0];
137 dst_reversed_order.addr_bytes[2] = dst.addr_bytes[1];
138 dst_reversed_order.addr_bytes[1] = dst.addr_bytes[2];
139 dst_reversed_order.addr_bytes[0] = dst.addr_bytes[3];
140
141 rte_le32_t src_addr_ser = *((rte_le32_t *) &src_reversed_order);
142 rte_le32_t dst_addr_ser = *((rte_le32_t *) &dst_reversed_order);
143
144 packet_hdr->ipv4_hdr.src_addr = rte_cpu_to_be_32(src_addr_ser);
145 packet_hdr->ipv4_hdr.dst_addr = rte_cpu_to_be_32(dst_addr_ser);
146
147 packet_hdr->ipv4_hdr.version_ihl = (IPV4_VERSION << 4) | (sizeof(struct rte_ipv4_hdr) / 4);
148
149 packet_hdr->ipv4_hdr.total_length = rte_cpu_to_be_16(packet_len); // Payload + udp_hdr + iphdr
150 packet_hdr->ipv4_hdr.time_to_live = DEFAULT_TTL;
151 packet_hdr->ipv4_hdr.type_of_service = DEFAULT_TOS;
152
153 // https://perso.telecom-paristech.fr/drossi/paper/rossi17ipid.pdf
154 packet_hdr->ipv4_hdr.packet_id = rte_cpu_to_be_16(0); // I put a constant here..
155 packet_hdr->ipv4_hdr.fragment_offset = 0;
156 packet_hdr->ipv4_hdr.next_proto_id = IPPROTO_UDP;
157
158 packet_hdr->ipv4_hdr.hdr_checksum = 0;
159 //packet_hdr->ipv4_hdr.hdr_checksum = rte_ipv4_cksum(&packet_hdr->ipv4_hdr);
160
161 //UDP checksum
162 packet_hdr->udp_hdr.dgram_cksum = 0;
163 //packet_hdr->udp_hdr.dgram_cksum = rte_ipv4_udptcp_cksum(&packet_hdr->ipv4_hdr, (void *) &packet_hdr->udp_hdr);
164 //if (packet_hdr->udp_hdr.dgram_cksum == 0) {
165 // packet_hdr->udp_hdr.dgram_cksum = 0xFFFF;
166 //}
167 return ;
168}
#define IPV4_VERSION
Definition PacketCtor.cpp:9

◆ pktgen_udp_hdr_ctor()

void dunedaq::dpdklibs::udp::pktgen_udp_hdr_ctor ( struct ipv4_udp_packet_hdr * packet_hdr,
rte_le16_t packet_len,
int sport,
int dport )

pktgen_udp_hdr_ctor - UDP header constructor routine.

DESCRIPTION Construct the UDP header in a packer buffer.

RETURNS: next header location

SEE ALSO:

Definition at line 95 of file PacketCtor.cpp.

96{
97 packet_hdr->udp_hdr.dgram_len = rte_cpu_to_be_16(packet_len);
98
99 packet_hdr->udp_hdr.src_port = rte_cpu_to_be_16(sport);
100 packet_hdr->udp_hdr.dst_port = rte_cpu_to_be_16(dport);
101
102 packet_hdr->udp_hdr.dgram_cksum = 0; // checksum must be set to 0 in the L4 header by the caller.
103 //TODO I think that the payload must be already there and continuous in memory..
104 return ;
105}

◆ set_daqethheader_test_values()

void dunedaq::dpdklibs::udp::set_daqethheader_test_values ( detdataformats::DAQEthHeader & daqethheader_obj)
noexcept

Definition at line 232 of file Utils.cpp.

233{
234 daqethheader_obj.version = 0;
235 daqethheader_obj.det_id = 1;
236 daqethheader_obj.crate_id = 2;
237 daqethheader_obj.slot_id = 3;
238 daqethheader_obj.stream_id = 4;
239 daqethheader_obj.reserved = 5;
240 daqethheader_obj.seq_id = 6;
241 daqethheader_obj.block_length = 7;
242 daqethheader_obj.timestamp = 8;
243}

Variable Documentation

◆ __rte_packed

struct dunedaq::dpdklibs::udp::ipv4_udp_packet_hdr dunedaq::dpdklibs::udp::__rte_packed