NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_ct_udp_single_match_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <unistd.h>
27 
28 #include <rte_ethdev.h>
29 
30 #include <doca_log.h>
31 #include <doca_flow.h>
32 #include <doca_flow_ct.h>
33 
34 #include "flow_ct_common.h"
35 #include "flow_common.h"
36 
37 #define PACKET_BURST 128
38 
39 DOCA_LOG_REGISTER(FLOW_CT_UDP_SINGLE_MATCH);
40 
41 /*
42  * Create RSS pipe
43  *
44  * @port [in]: Pipe port
45  * @status [in]: User context for adding entry
46  * @pipe [out]: Created pipe pointer
47  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
48  */
49 static doca_error_t create_rss_pipe(struct doca_flow_port *port,
50  struct entries_status *status,
51  struct doca_flow_pipe **pipe)
52 {
53  struct doca_flow_match match;
54  struct doca_flow_pipe_cfg *cfg;
55  struct doca_flow_fwd fwd;
56  uint16_t rss_queues[1];
58 
59  memset(&match, 0, sizeof(match));
60  memset(&fwd, 0, sizeof(fwd));
61 
63  if (result != DOCA_SUCCESS) {
64  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
65  return result;
66  }
67 
68  result = set_flow_pipe_cfg(cfg, "RSS_PIPE", DOCA_FLOW_PIPE_BASIC, false);
69  if (result != DOCA_SUCCESS) {
70  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
71  goto destroy_pipe_cfg;
72  }
74  if (result != DOCA_SUCCESS) {
75  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
76  goto destroy_pipe_cfg;
77  }
78 
79  /* RSS queue - send matched traffic to queue 0 */
80  rss_queues[0] = 0;
85  fwd.rss.nr_queues = 1;
86 
88  if (result != DOCA_SUCCESS) {
89  DOCA_LOG_ERR("Failed to create RSS pipe: %s", doca_error_get_descr(result));
90  goto destroy_pipe_cfg;
91  }
93 
94  /* Match on any packet */
95  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, &fwd, 0, status, NULL);
96  if (result != DOCA_SUCCESS) {
97  DOCA_LOG_ERR("Failed to add RSS pipe entry: %s", doca_error_get_descr(result));
98  return result;
99  }
100 
102  if (result != DOCA_SUCCESS)
103  DOCA_LOG_ERR("Failed to process RSS entry: %s", doca_error_get_descr(result));
104 
105  return result;
106 
109  return result;
110 }
111 
112 /*
113  * Create CT pipe
114  *
115  * @port [in]: Pipe port
116  * @fwd_pipe [in]: Forward pipe pointer
117  * @fwd_miss_pipe [in]: Forward miss pipe pointer
118  * @pipe [out]: Created pipe pointer
119  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
120  */
121 static doca_error_t create_ct_pipe(struct doca_flow_port *port,
122  struct doca_flow_pipe *fwd_pipe,
123  struct doca_flow_pipe *fwd_miss_pipe,
124  struct doca_flow_pipe **pipe)
125 {
126  struct doca_flow_match match;
127  struct doca_flow_match mask;
128  struct doca_flow_pipe_cfg *cfg;
129  struct doca_flow_fwd fwd;
130  struct doca_flow_fwd fwd_miss;
132 
133  memset(&match, 0, sizeof(match));
134  memset(&mask, 0, sizeof(mask));
135  memset(&fwd, 0, sizeof(fwd));
136  memset(&fwd_miss, 0, sizeof(fwd));
137 
139  if (result != DOCA_SUCCESS) {
140  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
141  return result;
142  }
143 
144  result = set_flow_pipe_cfg(cfg, "CT_PIPE", DOCA_FLOW_PIPE_CT, false);
145  if (result != DOCA_SUCCESS) {
146  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
147  goto destroy_pipe_cfg;
148  }
149  result = doca_flow_pipe_cfg_set_match(cfg, &match, &mask);
150  if (result != DOCA_SUCCESS) {
151  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
152  goto destroy_pipe_cfg;
153  }
154 
156  fwd.next_pipe = fwd_pipe;
157 
159  fwd_miss.next_pipe = fwd_miss_pipe;
160 
162  if (result != DOCA_SUCCESS)
163  DOCA_LOG_ERR("Failed to add CT pipe: %s", doca_error_get_descr(result));
166  return result;
167 }
168 
169 /*
170  * Create VxLAN encapsulation pipe
171  *
172  * @port [in]: Pipe port
173  * @port_id [in]: Forward port ID
174  * @status [in]: User context for adding entry
175  * @pipe [out]: Created pipe pointer
176  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
177  */
178 static doca_error_t create_vxlan_encap_pipe(struct doca_flow_port *port,
179  int port_id,
180  struct entries_status *status,
181  struct doca_flow_pipe **pipe)
182 {
183  struct doca_flow_match match;
184  struct doca_flow_actions actions;
185  struct doca_flow_actions *actions_list[] = {&actions};
186  struct doca_flow_fwd fwd;
187  struct doca_flow_pipe_cfg *pipe_cfg;
188  uint8_t src_mac[] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
189  uint8_t dst_mac[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
191 
192  memset(&match, 0, sizeof(match));
193  memset(&actions, 0, sizeof(actions));
194  memset(&fwd, 0, sizeof(fwd));
195 
197  actions.encap_cfg.is_l2 = true;
198  SET_MAC_ADDR(actions.encap_cfg.encap.outer.eth.src_mac, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
199  SET_MAC_ADDR(actions.encap_cfg.encap.outer.eth.dst_mac, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
201  actions.encap_cfg.encap.outer.ip4.src_ip = 0xffffffff;
202  actions.encap_cfg.encap.outer.ip4.dst_ip = 0xffffffff;
207  actions.encap_cfg.encap.tun.vxlan_tun_id = 0xffffffff;
208 
209  result = doca_flow_pipe_cfg_create(&pipe_cfg, port);
210  if (result != DOCA_SUCCESS) {
211  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
212  return result;
213  }
214 
215  result = set_flow_pipe_cfg(pipe_cfg, "VXLAN_ENCAP_PIPE", DOCA_FLOW_PIPE_BASIC, true);
216  if (result != DOCA_SUCCESS) {
217  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
218  goto destroy_pipe_cfg;
219  }
221  if (result != DOCA_SUCCESS) {
222  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
223  goto destroy_pipe_cfg;
224  }
225  result = doca_flow_pipe_cfg_set_match(pipe_cfg, &match, NULL);
226  if (result != DOCA_SUCCESS) {
227  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
228  goto destroy_pipe_cfg;
229  }
230  result = doca_flow_pipe_cfg_set_actions(pipe_cfg, actions_list, NULL, NULL, 1);
231  if (result != DOCA_SUCCESS) {
232  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg actions: %s", doca_error_get_descr(result));
233  goto destroy_pipe_cfg;
234  }
235 
237  fwd.port_id = port_id;
238 
239  result = doca_flow_pipe_create(pipe_cfg, &fwd, NULL, pipe);
240  if (result != DOCA_SUCCESS) {
241  DOCA_LOG_ERR("Failed to create VxLAN Encap pipe: %s", doca_error_get_descr(result));
242  goto destroy_pipe_cfg;
243  }
244  doca_flow_pipe_cfg_destroy(pipe_cfg);
245 
246  memset(&actions, 0, sizeof(actions));
248  src_mac[0],
249  src_mac[1],
250  src_mac[2],
251  src_mac[3],
252  src_mac[4],
253  src_mac[5]);
255  dst_mac[0],
256  dst_mac[1],
257  dst_mac[2],
258  dst_mac[3],
259  dst_mac[4],
260  dst_mac[5]);
261  actions.encap_cfg.encap.outer.ip4.src_ip = BE_IPV4_ADDR(11, 21, 31, 41);
262  actions.encap_cfg.encap.outer.ip4.dst_ip = BE_IPV4_ADDR(81, 81, 81, 81);
265  actions.action_idx = 0;
266 
267  result = doca_flow_pipe_add_entry(0, *pipe, &match, &actions, NULL, NULL, 0, status, NULL);
268  if (result != DOCA_SUCCESS) {
269  DOCA_LOG_ERR("Failed to add VxLAN Encap pipe entry: %s", doca_error_get_descr(result));
270  return result;
271  }
272 
274  if (result != DOCA_SUCCESS)
275  DOCA_LOG_ERR("Failed to process UDP entry: %s", doca_error_get_descr(result));
276 
277  return result;
278 
280  doca_flow_pipe_cfg_destroy(pipe_cfg);
281  return result;
282 }
283 
284 /*
285  * Create pipe to count packets based on 5 tuple match
286  *
287  * @port [in]: Pipe port
288  * @fwd_pipe [in]: Next pipe pointer
289  * @status [in]: User context for adding entry
290  * @pipe [out]: Created pipe pointer
291  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
292  */
293 static doca_error_t create_count_pipe(struct doca_flow_port *port,
294  struct doca_flow_pipe *fwd_pipe,
295  struct entries_status *status,
296  struct doca_flow_pipe **pipe)
297 {
298  struct doca_flow_match match;
299  struct doca_flow_monitor monitor;
300  struct doca_flow_fwd fwd;
301  struct doca_flow_fwd fwd_miss;
302  struct doca_flow_pipe_cfg *pipe_cfg;
304 
305  memset(&match, 0, sizeof(match));
306  memset(&monitor, 0, sizeof(monitor));
307  memset(&fwd, 0, sizeof(fwd));
308  memset(&fwd_miss, 0, sizeof(fwd_miss));
309 
310  /* 5 tuple match */
315  match.outer.ip4.src_ip = 0xffffffff;
316  match.outer.ip4.dst_ip = 0xffffffff;
317  match.outer.udp.l4_port.src_port = 0xffff;
318  match.outer.udp.l4_port.dst_port = 0xffff;
319 
321 
322  result = doca_flow_pipe_cfg_create(&pipe_cfg, port);
323  if (result != DOCA_SUCCESS) {
324  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
325  return result;
326  }
327 
328  result = set_flow_pipe_cfg(pipe_cfg, "COUNT_PIPE", DOCA_FLOW_PIPE_BASIC, false);
329  if (result != DOCA_SUCCESS) {
330  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
331  goto destroy_pipe_cfg;
332  }
333  result = doca_flow_pipe_cfg_set_match(pipe_cfg, &match, NULL);
334  if (result != DOCA_SUCCESS) {
335  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
336  goto destroy_pipe_cfg;
337  }
339  if (result != DOCA_SUCCESS) {
340  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg monitor: %s", doca_error_get_descr(result));
341  goto destroy_pipe_cfg;
342  }
343 
345  fwd.next_pipe = fwd_pipe;
346 
348  fwd_miss.next_pipe = fwd_pipe;
349 
350  result = doca_flow_pipe_create(pipe_cfg, &fwd, &fwd_miss, pipe);
351  if (result != DOCA_SUCCESS) {
352  DOCA_LOG_ERR("Failed to create count pipe: %s", doca_error_get_descr(result));
353  goto destroy_pipe_cfg;
354  }
355  doca_flow_pipe_cfg_destroy(pipe_cfg);
356 
357  memset(&match, 0, sizeof(match));
358  match.outer.ip4.dst_ip = BE_IPV4_ADDR(8, 8, 8, 8);
359  match.outer.ip4.src_ip = BE_IPV4_ADDR(1, 2, 3, 4);
360  match.outer.udp.l4_port.dst_port = rte_cpu_to_be_16(80);
361  match.outer.udp.l4_port.src_port = rte_cpu_to_be_16(1234);
362 
363  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, NULL, 0, status, NULL);
364  if (result != DOCA_SUCCESS) {
365  DOCA_LOG_ERR("Failed to add count pipe entry: %s", doca_error_get_descr(result));
366  return result;
367  }
368 
370  if (result != DOCA_SUCCESS)
371  DOCA_LOG_ERR("Failed to process count entry: %s", doca_error_get_descr(result));
372 
373  return result;
374 
376  doca_flow_pipe_cfg_destroy(pipe_cfg);
377  return result;
378 }
379 
380 /*
381  * Parse UDP packet to update CT tables
382  *
383  * @packet [in]: Packet to parse
384  * @match_o [out]: Origin match struct to fill
385  */
386 static void parse_packet(struct rte_mbuf *packet, struct doca_flow_ct_match *match_o)
387 {
388  uint8_t *l4_hdr;
389  struct rte_ipv4_hdr *ipv4_hdr;
390  const struct rte_udp_hdr *udp_hdr;
391 
392  ipv4_hdr = rte_pktmbuf_mtod_offset(packet, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr));
393 
394  match_o->ipv4.src_ip = ipv4_hdr->src_addr;
395  match_o->ipv4.dst_ip = ipv4_hdr->dst_addr;
396 
397  l4_hdr = (typeof(l4_hdr))ipv4_hdr + rte_ipv4_hdr_len(ipv4_hdr);
398  udp_hdr = (typeof(udp_hdr))l4_hdr;
399 
400  match_o->ipv4.l4_port.src_port = udp_hdr->src_port;
401  match_o->ipv4.l4_port.dst_port = udp_hdr->dst_port;
402 
404 }
405 
406 /*
407  * Dequeue packets from DPDK queues, parse and update CT tables with new connection 5 tuple
408  *
409  * @port [in]: Port id to which an entry should be inserted
410  * @ct_queue [in]: DOCA Flow CT queue number
411  * @ct_status [in]: User context for adding CT entry
412  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
413  */
414 static doca_error_t process_packets(struct doca_flow_port *port, uint16_t ct_queue, struct entries_status *ct_status)
415 {
416  struct rte_mbuf *packets[PACKET_BURST];
417  struct doca_flow_ct_match match_o;
418  struct doca_flow_pipe_entry *entry;
419  uint32_t flags;
421  int i, entries, nb_packets = 0;
422  bool conn_found = false;
423 
424  memset(&match_o, 0, sizeof(match_o));
425 
426  nb_packets = rte_eth_rx_burst(0, 0, packets, PACKET_BURST);
427  if (nb_packets == 0) {
428  DOCA_LOG_INFO("Sample didn't receive packets to process");
429  return DOCA_ERROR_BAD_STATE;
430  }
431 
432  entries = 0;
433  DOCA_LOG_INFO("Sample received %d packets", nb_packets);
434  for (i = 0; i < PACKET_BURST && i < nb_packets; i++) {
435  parse_packet(packets[i], &match_o);
437  /* Allocate CT entry */
439  NULL,
440  flags,
441  &match_o,
442  packets[i]->hash.rss,
443  NULL,
444  0,
445  &entry,
446  &conn_found);
447  if (result != DOCA_SUCCESS) {
448  DOCA_LOG_ERR("Failed to prepare CT entry\n");
449  return result;
450  }
451 
452  if (!conn_found) {
454  /* Add origin match only */
455  result = doca_flow_ct_add_entry(ct_queue,
456  NULL,
457  flags,
458  &match_o,
459  NULL,
460  0,
461  0,
462  0,
463  0,
464  0,
465  ct_status,
466  entry);
467  if (result != DOCA_SUCCESS) {
468  DOCA_LOG_ERR("Failed to add CT pipe an entry: %s", doca_error_get_descr(result));
469  return result;
470  }
471  entries++;
472  }
473  }
474 
475  while (ct_status->nb_processed != entries) {
476  result = doca_flow_ct_entries_process(port, ct_queue, 0, 0, NULL);
477  if (result != DOCA_SUCCESS) {
478  DOCA_LOG_ERR("Failed to process Flow CT entries: %s", doca_error_get_descr(result));
479  return result;
480  }
481 
482  if (ct_status->failure) {
483  DOCA_LOG_ERR("Flow CT entries process returned with a failure");
484  return DOCA_ERROR_BAD_STATE;
485  }
486  }
487 
488  return DOCA_SUCCESS;
489 }
490 
491 /*
492  * Run flow_ct_udp_single_match sample
493  *
494  * @nb_queues [in]: number of queues the sample will use
495  * @ct_dev [in]: Flow CT device
496  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
497  */
498 doca_error_t flow_ct_udp_single_match(uint16_t nb_queues, struct doca_dev *ct_dev)
499 {
500  const int nb_ports = 2, nb_entries = 6;
501  struct flow_resources resource;
502  uint32_t nr_shared_resources[SHARED_RESOURCE_NUM_VALUES] = {0};
503  struct doca_flow_pipe *rss_pipe, *encap_pipe, *count_pipe, *ct_pipe = NULL, *udp_pipe;
504  struct doca_flow_port *ports[nb_ports];
505  struct doca_flow_meta o_zone_mask, o_modify_mask, r_zone_mask, r_modify_mask;
506  struct doca_dev *dev_arr[nb_ports];
507  uint32_t actions_mem_size[nb_ports];
508  struct entries_status ctrl_status, ct_status;
509  uint32_t ct_flags, nb_arm_queues = 1, nb_ctrl_queues = 1, nb_user_actions = 0, nb_ipv4_sessions = 1024,
510  nb_ipv6_sessions = 0; /* On BF2 should always be 0 */
511  uint16_t ct_queue = nb_queues;
513 
514  memset(&ctrl_status, 0, sizeof(ctrl_status));
515  memset(&ct_status, 0, sizeof(ct_status));
516  memset(&resource, 0, sizeof(resource));
517 
518  resource.nr_counters = 1;
519 
520  result = init_doca_flow(nb_queues, "switch,hws", &resource, nr_shared_resources);
521  if (result != DOCA_SUCCESS) {
522  DOCA_LOG_ERR("Failed to init DOCA Flow: %s", doca_error_get_descr(result));
523  return result;
524  }
525 
526  /* Dont use zone masking */
527  memset(&o_zone_mask, 0, sizeof(o_zone_mask));
528  memset(&o_modify_mask, 0, sizeof(o_modify_mask));
529  memset(&r_zone_mask, 0, sizeof(r_zone_mask));
530  memset(&r_modify_mask, 0, sizeof(r_modify_mask));
531 
533  result = init_doca_flow_ct(ct_flags,
534  nb_arm_queues,
535  nb_ctrl_queues,
536  nb_user_actions,
537  NULL,
538  nb_ipv4_sessions,
539  nb_ipv6_sessions,
541  false,
542  &o_zone_mask,
543  &o_modify_mask,
544  false,
545  &r_zone_mask,
546  &r_modify_mask);
547  if (result != DOCA_SUCCESS) {
549  return result;
550  }
551 
552  memset(dev_arr, 0, sizeof(struct doca_dev *) * nb_ports);
553  dev_arr[0] = ct_dev;
556  if (result != DOCA_SUCCESS) {
557  DOCA_LOG_ERR("Failed to init DOCA ports: %s", doca_error_get_descr(result));
560  return result;
561  }
562 
563  result = create_rss_pipe(ports[0], &ctrl_status, &rss_pipe);
564  if (result != DOCA_SUCCESS)
565  goto cleanup;
566 
567  result = create_vxlan_encap_pipe(ports[0], 0, &ctrl_status, &encap_pipe);
568  if (result != DOCA_SUCCESS)
569  goto cleanup;
570 
571  result = create_count_pipe(ports[0], rss_pipe, &ctrl_status, &count_pipe);
572  if (result != DOCA_SUCCESS)
573  goto cleanup;
574 
575  result = create_ct_pipe(ports[0], encap_pipe, count_pipe, &ct_pipe);
576  if (result != DOCA_SUCCESS)
577  goto cleanup;
578 
579  result = create_ct_root_pipe(ports[0], true, false, DOCA_FLOW_L4_META_UDP, ct_pipe, &ctrl_status, &udp_pipe);
580  if (result != DOCA_SUCCESS)
581  goto cleanup;
582 
583  if (ctrl_status.nb_processed != nb_entries || ctrl_status.failure) {
584  DOCA_LOG_ERR("Failed to process control path entries");
586  goto cleanup;
587  }
588 
589  DOCA_LOG_INFO("Wait few seconds for packets to arrive");
590  sleep(5);
591 
592  result = process_packets(ports[0], ct_queue, &ct_status);
593  if (result != DOCA_SUCCESS)
594  goto cleanup;
595 
596  DOCA_LOG_INFO("Same UDP packet should be resent");
597  sleep(5);
598 
599 cleanup:
600  cleanup_procedure(ct_pipe, nb_ports, ports);
601  return result;
602 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
struct doca_flow_port * init_doca_flow(uint16_t port_id, uint8_t rxq_num)
Definition: flow.c:37
#define SET_MAC_ADDR(addr, a, b, c, d, e, f)
Definition: flow_common.h:60
static void cleanup(struct cache_invalidate_sample_state *state)
doca_error_t init_doca_flow_ct(uint32_t flags, uint32_t nb_arm_queues, uint32_t nb_ctrl_queues, uint32_t nb_user_actions, doca_flow_ct_entry_finalize_cb entry_finalize_cb, uint32_t nb_ipv4_sessions, uint32_t nb_ipv6_sessions, uint32_t dup_filter_sz, bool o_match_inner, struct doca_flow_meta *o_zone_mask, struct doca_flow_meta *o_modify_mask, bool r_match_inner, struct doca_flow_meta *r_zone_mask, struct doca_flow_meta *r_modify_mask)
doca_error_t create_ct_root_pipe(struct doca_flow_port *port, bool is_ipv4, bool is_ipv6, enum doca_flow_l4_meta l4_type, struct doca_flow_pipe *fwd_pipe, struct entries_status *status, struct doca_flow_pipe **pipe)
void cleanup_procedure(struct doca_flow_pipe *ct_pipe, int nb_ports, struct doca_flow_port *ports[])
#define DUP_FILTER_CONN_NUM
static int nb_entries
DOCA_LOG_REGISTER(FLOW_CT_UDP_SINGLE_MATCH)
static doca_error_t create_count_pipe(struct doca_flow_port *port, struct doca_flow_pipe *fwd_pipe, struct entries_status *status, struct doca_flow_pipe **pipe)
doca_error_t flow_ct_udp_single_match(uint16_t nb_queues, struct doca_dev *ct_dev)
#define PACKET_BURST
static doca_error_t process_packets(struct doca_flow_port *port, uint16_t ct_queue, struct entries_status *ct_status)
static doca_error_t create_ct_pipe(struct doca_flow_port *port, struct doca_flow_pipe *fwd_pipe, struct doca_flow_pipe *fwd_miss_pipe, struct doca_flow_pipe **pipe)
static doca_error_t create_rss_pipe(struct doca_flow_port *port, struct entries_status *status, struct doca_flow_pipe **pipe)
static doca_error_t create_vxlan_encap_pipe(struct doca_flow_port *port, int port_id, struct entries_status *status, struct doca_flow_pipe **pipe)
static void parse_packet(struct rte_mbuf *packet, struct doca_flow_ct_match *match_o)
static doca_error_t destroy_pipe_cfg(struct doca_flow_pipe_cfg *cfg)
static struct doca_flow_pipe_entry * entries[NB_ENTRIES]
static struct doca_flow_fwd fwd_miss
Definition: flow_parser.c:110
static uint16_t * rss_queues
Definition: flow_parser.c:114
static struct doca_flow_actions actions
Definition: flow_parser.c:107
#define BE_IPV4_ADDR(a, b, c, d)
Definition: flow_parser.c:64
static struct doca_flow_monitor monitor
Definition: flow_parser.c:108
static struct doca_flow_fwd fwd
Definition: flow_parser.c:109
static struct doca_flow_pipe_entry * entry[MAX_ENTRIES]
#define DEFAULT_TIMEOUT_US
Definition: flow_skeleton.c:36
#define DOCA_HTOBE32(_x)
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_BAD_STATE
Definition: doca_error.h:56
@ DOCA_SUCCESS
Definition: doca_error.h:38
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_entries_process(struct doca_flow_port *port, uint16_t pipe_queue, uint32_t min_room, uint32_t max_processed_entries, uint32_t *queue_room)
Process CT entries in queue.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_add_entry(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_ct_match *match_origin, struct doca_flow_ct_match *match_reply, const struct doca_flow_ct_actions *actions_origin, const struct doca_flow_ct_actions *actions_reply, uint32_t fwd_handle_origin, uint32_t fwd_handle_reply, uint32_t timeout_s, void *usr_ctx, struct doca_flow_pipe_entry *entry)
Add new entry to doca flow CT pipe.
DOCA_EXPERIMENTAL void doca_flow_ct_destroy(void)
Destroy the doca flow ct.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_entry_prepare(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_ct_match *match_origin, uint32_t hash_origin, struct doca_flow_ct_match *match_reply, uint32_t hash_reply, struct doca_flow_pipe_entry **entry, bool *conn_found)
Lookup recent CT entry and create on miss.
@ DOCA_FLOW_CT_ENTRY_FLAGS_DIR_ORIGIN
Definition: doca_flow_ct.h:667
@ DOCA_FLOW_CT_ENTRY_FLAGS_NO_WAIT
Definition: doca_flow_ct.h:665
@ DOCA_FLOW_CT_ENTRY_FLAGS_ALLOC_ON_MISS
Definition: doca_flow_ct.h:683
@ DOCA_FLOW_CT_ENTRY_FLAGS_DUP_FILTER_ORIGIN
Definition: doca_flow_ct.h:685
@ DOCA_FLOW_CT_FLAG_NO_COUNTER
Definition: doca_flow_ct.h:60
@ DOCA_FLOW_CT_FLAG_NO_AGING
Definition: doca_flow_ct.h:58
#define DOCA_FLOW_VXLAN_DEFAULT_PORT
Definition: doca_flow_net.h:49
#define DOCA_FLOW_PROTO_UDP
Definition: doca_flow_net.h:42
@ DOCA_FLOW_L4_TYPE_EXT_UDP
@ DOCA_FLOW_L3_TYPE_IP4
@ DOCA_FLOW_TUN_VXLAN
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_destroy(struct doca_flow_pipe_cfg *cfg)
Destroy DOCA Flow pipe configuration struct.
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_create(struct doca_flow_pipe_cfg **cfg, struct doca_flow_port *port)
Create DOCA Flow pipe configuration struct.
DOCA_STABLE doca_error_t doca_flow_entries_process(struct doca_flow_port *port, uint16_t pipe_queue, uint64_t timeout, uint32_t max_processed_entries)
Process entries in queue.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_cfg_set_match(struct doca_flow_pipe_cfg *cfg, const struct doca_flow_match *match, const struct doca_flow_match *match_mask)
Set pipe's match and match mask.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_create(const struct doca_flow_pipe_cfg *cfg, const struct doca_flow_fwd *fwd, const struct doca_flow_fwd *fwd_miss, struct doca_flow_pipe **pipe)
Create one new pipe.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_cfg_set_actions(struct doca_flow_pipe_cfg *cfg, struct doca_flow_actions *const *actions, struct doca_flow_actions *const *actions_masks, struct doca_flow_action_descs *const *action_descs, size_t nr_actions)
Set pipe's actions, actions mask and actions descriptor.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_cfg_set_monitor(struct doca_flow_pipe_cfg *cfg, const struct doca_flow_monitor *monitor)
Set pipe's monitor.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_add_entry(uint16_t pipe_queue, struct doca_flow_pipe *pipe, const struct doca_flow_match *match, const struct doca_flow_actions *actions, const struct doca_flow_monitor *monitor, const struct doca_flow_fwd *fwd, uint32_t flags, void *usr_ctx, struct doca_flow_pipe_entry **entry)
Add one new entry to a pipe.
DOCA_STABLE void doca_flow_destroy(void)
Destroy the doca flow.
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_set_domain(struct doca_flow_pipe_cfg *cfg, enum doca_flow_pipe_domain domain)
Set pipe's domain.
@ DOCA_FLOW_RSS_IPV4
Definition: doca_flow.h:764
@ DOCA_FLOW_RSS_UDP
Definition: doca_flow.h:768
@ DOCA_FLOW_PIPE_CT
Definition: doca_flow.h:227
@ DOCA_FLOW_PIPE_BASIC
Definition: doca_flow.h:221
@ DOCA_FLOW_L3_META_IPV4
Definition: doca_flow.h:296
@ DOCA_FLOW_RESOURCE_TYPE_NON_SHARED
Definition: doca_flow.h:615
@ DOCA_FLOW_FWD_PORT
Definition: doca_flow.h:744
@ DOCA_FLOW_FWD_PIPE
Definition: doca_flow.h:746
@ DOCA_FLOW_FWD_RSS
Definition: doca_flow.h:742
@ DOCA_FLOW_L4_META_UDP
Definition: doca_flow.h:310
@ DOCA_FLOW_PIPE_DOMAIN_EGRESS
Definition: doca_flow.h:245
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
struct tcp_hdr l4_hdr
Definition: packets.h:2
doca_error_t init_doca_flow_ports(int nb_ports, struct doca_flow_port *ports[], bool is_hairpin, struct doca_dev *dev_arr[], uint32_t actions_mem_size[])
Definition: flow_common.c:296
doca_error_t set_flow_pipe_cfg(struct doca_flow_pipe_cfg *cfg, const char *name, enum doca_flow_pipe_type type, bool is_root)
Definition: flow_common.c:305
#define SHARED_RESOURCE_NUM_VALUES
Definition: flow_common.h:59
#define ACTIONS_MEM_SIZE(nr_queues, entries)
Definition: flow_common.h:66
#define ARRAY_INIT(array, val)
Definition: flow_common.h:71
doca flow actions information
Definition: doca_flow.h:684
struct doca_flow_resource_encap_cfg encap_cfg
Definition: doca_flow.h:710
enum doca_flow_resource_type encap_type
Definition: doca_flow.h:707
uint8_t action_idx
Definition: doca_flow.h:685
struct doca_flow_header_l4_port l4_port
Definition: doca_flow_ct.h:623
doca_be32_t src_ip
Definition: doca_flow_ct.h:625
doca_be32_t dst_ip
Definition: doca_flow_ct.h:627
doca flow CT match pattern
Definition: doca_flow_ct.h:654
struct doca_flow_ct_match4 ipv4
Definition: doca_flow_ct.h:656
struct doca_flow_tun tun
Definition: doca_flow.h:569
struct doca_flow_header_format outer
Definition: doca_flow.h:567
forwarding configuration
Definition: doca_flow.h:779
struct doca_flow_pipe * next_pipe
Definition: doca_flow.h:800
struct doca_flow_pipe * pipe
Definition: doca_flow.h:806
uint16_t port_id
Definition: doca_flow.h:795
enum doca_flow_fwd_type type
Definition: doca_flow.h:780
enum doca_flow_resource_type rss_type
Definition: doca_flow.h:784
struct doca_flow_resource_rss_cfg rss
Definition: doca_flow.h:787
uint8_t dst_mac[DOCA_FLOW_ETHER_ADDR_LEN]
uint8_t src_mac[DOCA_FLOW_ETHER_ADDR_LEN]
struct doca_flow_header_ip4 ip4
Definition: doca_flow.h:449
enum doca_flow_l4_type_ext l4_type_ext
Definition: doca_flow.h:454
struct doca_flow_header_eth eth
Definition: doca_flow.h:440
struct doca_flow_header_udp udp
Definition: doca_flow.h:459
enum doca_flow_l3_type l3_type
Definition: doca_flow.h:446
struct doca_flow_header_l4_port l4_port
doca flow matcher information
Definition: doca_flow.h:491
struct doca_flow_parser_meta parser_meta
Definition: doca_flow.h:496
struct doca_flow_header_format outer
Definition: doca_flow.h:498
doca flow meta data
Definition: doca_flow.h:358
doca monitor action configuration
Definition: doca_flow.h:968
enum doca_flow_resource_type counter_type
Definition: doca_flow.h:988
enum doca_flow_l3_meta outer_l3_type
Definition: doca_flow.h:382
enum doca_flow_l4_meta outer_l4_type
Definition: doca_flow.h:383
struct doca_flow_encap_action encap
Definition: doca_flow.h:663
enum doca_flow_tun_type type
doca_be32_t vxlan_tun_id
user context struct that will be used in entries process callback
Definition: flow_common.h:78
uint32_t nr_counters
Definition: flow_common.h:96
uint32_t src_addr
Definition: packets.h:75
uint32_t dst_addr
Definition: packets.h:76
uint16_t dst_port
Definition: packets.h:99
uint16_t src_port
Definition: packets.h:98
static int nb_ports
Definition: switch_core.c:44
static uint32_t actions_mem_size[FLOW_SWITCH_PORTS_MAX]
Definition: switch_core.c:43
static struct doca_flow_port * ports[FLOW_SWITCH_PORTS_MAX]
Definition: switch_core.c:42