NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_ct_tcp_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 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 static uint16_t sessions = 0;
40 
41 DOCA_LOG_REGISTER(FLOW_CT_TCP);
42 
43 /*
44  * Create RSS pipe
45  *
46  * @port [in]: Pipe port
47  * @status [in]: user context for adding entry
48  * @pipe [out]: Created pipe pointer
49  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
50  */
51 static doca_error_t create_rss_pipe(struct doca_flow_port *port,
52  struct entries_status *status,
53  struct doca_flow_pipe **pipe)
54 {
55  struct doca_flow_match match;
56  struct doca_flow_pipe_cfg *cfg;
57  struct doca_flow_fwd fwd;
58  uint16_t rss_queues[1];
60 
61  memset(&match, 0, sizeof(match));
62  memset(&fwd, 0, sizeof(fwd));
63 
65  if (result != DOCA_SUCCESS) {
66  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
67  return result;
68  }
69 
70  result = set_flow_pipe_cfg(cfg, "RSS_PIPE", DOCA_FLOW_PIPE_BASIC, false);
71  if (result != DOCA_SUCCESS) {
72  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
73  goto destroy_pipe_cfg;
74  }
76  if (result != DOCA_SUCCESS) {
77  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
78  goto destroy_pipe_cfg;
79  }
80 
81  /* RSS queue - send matched traffic to queue 0 */
82  rss_queues[0] = 0;
87  fwd.rss.nr_queues = 1;
88 
90  if (result != DOCA_SUCCESS) {
91  DOCA_LOG_ERR("Failed to create RSS pipe: %s", doca_error_get_descr(result));
92  goto destroy_pipe_cfg;
93  }
95 
96  /* Match on any packet */
97  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, &fwd, 0, status, NULL);
98  if (result != DOCA_SUCCESS) {
99  DOCA_LOG_ERR("Failed to add RSS pipe entry: %s", doca_error_get_descr(result));
100  return result;
101  }
102 
104  if (result != DOCA_SUCCESS)
105  DOCA_LOG_ERR("Failed to process RSS entry: %s", doca_error_get_descr(result));
106 
107  return result;
108 
111  return result;
112 }
113 
114 /*
115  * Create egress pipe
116  *
117  * @port [in]: Pipe port
118  * @port_id [in]: Next pipe port id
119  * @status [in]: user context for adding entry
120  * @pipe [out]: Created pipe pointer
121  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
122  */
123 static doca_error_t create_egress_pipe(struct doca_flow_port *port,
124  int port_id,
125  struct entries_status *status,
126  struct doca_flow_pipe **pipe)
127 {
128  struct doca_flow_match match;
129  struct doca_flow_pipe_cfg *cfg;
130  struct doca_flow_fwd fwd;
132 
133  memset(&match, 0, sizeof(match));
134  memset(&fwd, 0, sizeof(fwd));
135 
137  if (result != DOCA_SUCCESS) {
138  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
139  return result;
140  }
141 
142  result = set_flow_pipe_cfg(cfg, "EGRESS_PIPE", DOCA_FLOW_PIPE_BASIC, false);
143  if (result != DOCA_SUCCESS) {
144  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
145  goto destroy_pipe_cfg;
146  }
148  if (result != DOCA_SUCCESS) {
149  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
150  goto destroy_pipe_cfg;
151  }
152 
154  fwd.port_id = port_id;
155 
157  if (result != DOCA_SUCCESS) {
158  DOCA_LOG_ERR("Failed to create EGRESS pipe: %s", doca_error_get_descr(result));
159  return result;
160  }
162 
163  /* Match on any packet */
164  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, &fwd, 0, status, NULL);
165  if (result != DOCA_SUCCESS) {
166  DOCA_LOG_ERR("Failed to add EGRESS pipe entry: %s", doca_error_get_descr(result));
167  return result;
168  }
169 
171  if (result != DOCA_SUCCESS)
172  DOCA_LOG_ERR("Failed to process EGRESS entry: %s", doca_error_get_descr(result));
173 
174  return result;
175 
178  return result;
179 }
180 
181 /*
182  * Create CT miss pipe
183  *
184  * @port [in]: Pipe port
185  * @fwd_pipe [in]: Forward pipe pointer
186  * @status [in]: user context for adding entry
187  * @pipe [out]: Created pipe pointer
188  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
189  */
190 static doca_error_t create_ct_miss_pipe(struct doca_flow_port *port,
191  struct doca_flow_pipe *fwd_pipe,
192  struct entries_status *status,
193  struct doca_flow_pipe **pipe)
194 {
195  struct doca_flow_match match;
196  struct doca_flow_pipe_cfg *cfg;
197  struct doca_flow_fwd fwd;
198  struct doca_flow_fwd fwd_miss;
200 
201  memset(&match, 0, sizeof(match));
202  memset(&fwd, 0, sizeof(fwd));
203  memset(&fwd_miss, 0, sizeof(fwd));
204 
206  if (result != DOCA_SUCCESS) {
207  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
208  return result;
209  }
210 
211  result = set_flow_pipe_cfg(cfg, "CT_MISS_PIPE", DOCA_FLOW_PIPE_BASIC, false);
212  if (result != DOCA_SUCCESS) {
213  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
214  goto destroy_pipe_cfg;
215  }
217  if (result != DOCA_SUCCESS) {
218  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
219  goto destroy_pipe_cfg;
220  }
221 
223  fwd.next_pipe = fwd_pipe;
224 
226  fwd_miss.next_pipe = fwd_pipe;
227 
229  if (result != DOCA_SUCCESS) {
230  DOCA_LOG_ERR("Failed to create CT miss pipe: %s", doca_error_get_descr(result));
231  return result;
232  }
234 
235  /* Match on any packet */
236  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, &fwd, 0, status, NULL);
237  if (result != DOCA_SUCCESS) {
238  DOCA_LOG_ERR("Failed to add CT miss pipe entry: %s", doca_error_get_descr(result));
239  return result;
240  }
241 
243  if (result != DOCA_SUCCESS)
244  DOCA_LOG_ERR("Failed to process CT miss entry: %s", doca_error_get_descr(result));
245 
246  return result;
247 
250  return result;
251 }
252 
253 /*
254  * Create DOCA Flow TCP state pipe to filter state on known TCP session
255  *
256  * @port [in]: Pipe port
257  * @status [in]: User context for adding entry
258  * @fwd_pipe [in]: Forward pipe
259  * @fwd_miss_pipe [in]: Forward miss pipe
260  * @pipe [out]: Created pipe pointer
261  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
262  */
263 static doca_error_t create_tcp_flags_filter_pipe(struct doca_flow_port *port,
264  struct entries_status *status,
265  struct doca_flow_pipe *fwd_pipe,
266  struct doca_flow_pipe *fwd_miss_pipe,
267  struct doca_flow_pipe **pipe)
268 {
269  struct doca_flow_match match;
270  struct doca_flow_match mask;
271  struct doca_flow_fwd fwd;
272  struct doca_flow_fwd fwd_miss;
273  struct doca_flow_pipe_cfg *cfg;
275 
276  memset(&match, 0, sizeof(match));
277  memset(&mask, 0, sizeof(mask));
278  memset(&fwd, 0, sizeof(fwd));
279  memset(&fwd_miss, 0, sizeof(fwd_miss));
280 
281  /* Match on non SYN, FIN and RST packets */
282  match.outer.tcp.flags = 0xff;
284 
288 
290  if (result != DOCA_SUCCESS) {
291  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
292  return result;
293  }
294 
295  result = set_flow_pipe_cfg(cfg, "TCP_FLAGS_FILTER_PIPE", DOCA_FLOW_PIPE_BASIC, false);
296  if (result != DOCA_SUCCESS) {
297  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
298  goto destroy_pipe_cfg;
299  }
300  result = doca_flow_pipe_cfg_set_match(cfg, &match, &mask);
301  if (result != DOCA_SUCCESS) {
302  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
303  goto destroy_pipe_cfg;
304  }
305 
307  fwd.next_pipe = fwd_pipe;
308 
310  fwd_miss.next_pipe = fwd_miss_pipe;
311 
313  if (result != DOCA_SUCCESS) {
314  DOCA_LOG_ERR("Failed to create TCP_FLAGS_FILTER pipe: %s", doca_error_get_descr(result));
315  return result;
316  }
318 
319  match.outer.tcp.flags = 0;
320  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, NULL, 0, status, NULL);
321  if (result != DOCA_SUCCESS) {
322  DOCA_LOG_ERR("Failed to create TCP flags filter pipe entry: %s", doca_error_get_descr(result));
323  return result;
324  }
325 
327  if (result != DOCA_SUCCESS)
328  DOCA_LOG_ERR("Failed to process TCP flags filter entry: %s", doca_error_get_descr(result));
329 
330  return result;
331 
334  return result;
335 }
336 
337 /*
338  * Create CT pipe
339  *
340  * @port [in]: Pipe port
341  * @fwd_pipe [in]: Forward pipe pointer
342  * @fwd_miss_pipe [in]: Forward miss pipe pointer
343  * @pipe [out]: Created pipe pointer
344  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
345  */
346 static doca_error_t create_ct_pipe(struct doca_flow_port *port,
347  struct doca_flow_pipe *fwd_pipe,
348  struct doca_flow_pipe *fwd_miss_pipe,
349  struct doca_flow_pipe **pipe)
350 {
351  struct doca_flow_match match;
352  struct doca_flow_pipe_cfg *cfg;
353  struct doca_flow_fwd fwd;
354  struct doca_flow_fwd fwd_miss;
356 
357  memset(&match, 0, sizeof(match));
358  memset(&fwd, 0, sizeof(fwd));
359  memset(&fwd_miss, 0, sizeof(fwd));
360 
362  if (result != DOCA_SUCCESS) {
363  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
364  return result;
365  }
366 
367  result = set_flow_pipe_cfg(cfg, "CT_PIPE", DOCA_FLOW_PIPE_CT, false);
368  if (result != DOCA_SUCCESS) {
369  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
370  goto destroy_pipe_cfg;
371  }
373  if (result != DOCA_SUCCESS) {
374  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
375  goto destroy_pipe_cfg;
376  }
377 
379  fwd.next_pipe = fwd_pipe;
380 
382  fwd_miss.next_pipe = fwd_miss_pipe;
383 
385  if (result != DOCA_SUCCESS)
386  DOCA_LOG_ERR("Failed to create CT pipe: %s", doca_error_get_descr(result));
389  return result;
390 }
391 
392 /*
393  * Parse TCP packet to update CT tables
394  *
395  * @packet [in]: Packet to parse
396  * @match_o [out]: Origin match struct to fill
397  * @match_r [out]: Reply match struct to fill
398  * @tcp_state [out]: Packet TCP state
399  */
400 static void parse_packet(struct rte_mbuf *packet,
401  struct doca_flow_ct_match *match_o,
402  struct doca_flow_ct_match *match_r,
403  uint8_t *tcp_state)
404 {
405  uint8_t *l4_hdr;
406  struct rte_ipv4_hdr *ipv4_hdr;
407  const struct rte_tcp_hdr *tcp_hdr;
408 
409  ipv4_hdr = rte_pktmbuf_mtod_offset(packet, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr));
410 
411  match_o->ipv4.src_ip = ipv4_hdr->src_addr;
412  match_o->ipv4.dst_ip = ipv4_hdr->dst_addr;
413  match_r->ipv4.src_ip = match_o->ipv4.dst_ip;
414  match_r->ipv4.dst_ip = match_o->ipv4.src_ip;
415 
416  l4_hdr = (typeof(l4_hdr))ipv4_hdr + rte_ipv4_hdr_len(ipv4_hdr);
417  tcp_hdr = (typeof(tcp_hdr))l4_hdr;
418 
419  match_o->ipv4.l4_port.src_port = tcp_hdr->src_port;
420  match_o->ipv4.l4_port.dst_port = tcp_hdr->dst_port;
421  match_r->ipv4.l4_port.src_port = match_o->ipv4.l4_port.dst_port;
422  match_r->ipv4.l4_port.dst_port = match_o->ipv4.l4_port.src_port;
423 
426 
427  *tcp_state = tcp_hdr->tcp_flags;
428 }
429 
430 /*
431  * Dequeue packets from DPDK queues, parse and update CT tables with new connection 5 tuple
432  *
433  * @port [in]: Port id to which an entry should be inserted
434  * @ct_queue [in]: DOCA Flow CT queue number
435  * @ct_status [in]: User context for adding CT entry
436  * @entry [in/out]: CT entry
437  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
438  */
439 static doca_error_t process_packets(struct doca_flow_port *port,
440  uint16_t ct_queue,
441  struct entries_status *ct_status,
442  struct doca_flow_pipe_entry **entry)
443 {
444  struct rte_mbuf *packets[PACKET_BURST];
445  struct doca_flow_ct_match match_o;
446  struct doca_flow_ct_match match_r;
448  uint8_t tcp_state;
450  int rc, i, nb_packets, nb_process = 0;
451 
452  memset(&match_o, 0, sizeof(match_o));
453  memset(&match_r, 0, sizeof(match_r));
454 
455  rc = rte_flow_dynf_metadata_register();
456  if (unlikely(rc)) {
457  DOCA_LOG_ERR("Enable metadata failed");
458  return DOCA_ERROR_BAD_STATE;
459  }
460 
461  nb_packets = rte_eth_rx_burst(0, 0, packets, PACKET_BURST);
462  if (nb_packets == 0) {
463  DOCA_LOG_INFO("Sample didn't receive packets to process");
464  return DOCA_ERROR_BAD_STATE;
465  }
466 
467  DOCA_LOG_INFO("%d packets received on rx_burst()", nb_packets);
468  for (i = 0; i < PACKET_BURST && i < nb_packets; i++) {
469  parse_packet(packets[i], &match_o, &match_r, &tcp_state);
470  if (tcp_state & DOCA_FLOW_MATCH_TCP_FLAG_SYN) {
471  if (sessions > 0) {
472  DOCA_LOG_INFO("Already have one alive session, cannot handle more, skip");
473  continue;
474  }
475  /* Allocate CT entry */
477  NULL,
479  &match_o,
480  0,
481  &match_r,
482  0,
483  entry,
484  NULL);
485  if (result != DOCA_SUCCESS) {
486  DOCA_LOG_ERR("Failed to prepare CT entry\n");
487  return result;
488  }
489  result = doca_flow_ct_add_entry(ct_queue,
490  NULL,
491  flags,
492  &match_o,
493  &match_r,
494  NULL,
495  NULL,
496  0,
497  0,
498  0,
499  ct_status,
500  *entry);
501  if (result != DOCA_SUCCESS) {
502  DOCA_LOG_ERR("Failed to add CT pipe an entry: %s", doca_error_get_descr(result));
503  return result;
504  }
505  sessions++;
506  nb_process++;
507  while (ct_status->nb_processed != nb_process) {
508  result = doca_flow_ct_entries_process(port, ct_queue, 0, 0, NULL);
509  if (result != DOCA_SUCCESS) {
510  DOCA_LOG_ERR("Failed to process Flow CT entries: %s",
512  return result;
513  }
514 
515  if (ct_status->failure) {
516  DOCA_LOG_ERR("Flow CT entries process returned with a failure");
517  return DOCA_ERROR_BAD_STATE;
518  }
519  }
521  "TCP session was created, waiting for 'FIN'/'RST' packet before ending the session");
522  } else if (tcp_state & DOCA_FLOW_MATCH_TCP_FLAG_FIN || tcp_state & DOCA_FLOW_MATCH_TCP_FLAG_RST) {
523  if (sessions == 0) {
524  DOCA_LOG_INFO("No alive session to destroy, skip destroy");
525  continue;
526  }
527  result = doca_flow_ct_rm_entry(ct_queue, NULL, flags, *entry);
528  if (result != DOCA_SUCCESS) {
529  DOCA_LOG_ERR("Failed to remove CT pipe entry: %s", doca_error_get_descr(result));
530  return result;
531  }
532  sessions--;
533  DOCA_LOG_INFO("TCP session was ended");
534  } else {
535  DOCA_LOG_WARN("Sample is only able to process 'SYN', 'FIN' and 'RST' packets");
536  continue;
537  }
538  rte_flow_dynf_metadata_set(packets[i], 1);
539  packets[i]->ol_flags |= RTE_MBUF_DYNFLAG_TX_METADATA;
540  rte_eth_tx_burst(0, 0, &packets[i], 1);
541  }
542  ct_status->nb_processed = 0;
543 
544  return DOCA_SUCCESS;
545 }
546 
547 /*
548  * Run flow_ct_tcp sample
549  *
550  * @nb_queues [in]: number of queues the sample will use
551  * @ct_dev [in]: Flow CT device
552  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
553  */
554 doca_error_t flow_ct_tcp(uint16_t nb_queues, struct doca_dev *ct_dev)
555 {
556  const int nb_ports = 2, nb_entries = 7;
557  struct flow_resources resource;
558  uint32_t nr_shared_resources[SHARED_RESOURCE_NUM_VALUES] = {0};
559  struct doca_flow_pipe_entry *tcp_entry;
560  struct doca_flow_pipe *egress_pipe, *ct_miss_pipe, *tcp_flags_filter_pipe, *rss_pipe, *tcp_pipe;
561  struct doca_flow_pipe *ct_pipe = NULL;
562  struct doca_flow_port *ports[nb_ports];
563  struct doca_flow_meta o_zone_mask, o_modify_mask, r_zone_mask, r_modify_mask;
564  struct doca_dev *dev_arr[nb_ports];
565  uint32_t actions_mem_size[nb_ports];
566  struct entries_status ctrl_status, ct_status;
567  uint32_t ct_flags, nb_arm_queues = 1, nb_ctrl_queues = 1, nb_user_actions = 0, nb_ipv4_sessions = 1024,
568  nb_ipv6_sessions = 0; /* On BF2 should always be 0 */
569  uint16_t ct_queue = nb_queues;
571 
572  memset(&ctrl_status, 0, sizeof(ctrl_status));
573  memset(&ct_status, 0, sizeof(ct_status));
574  memset(&resource, 0, sizeof(resource));
575 
576  resource.nr_counters = 1;
577 
578  result = init_doca_flow(nb_queues, "switch,hws", &resource, nr_shared_resources);
579  if (result != DOCA_SUCCESS) {
580  DOCA_LOG_ERR("Failed to init DOCA Flow: %s", doca_error_get_descr(result));
581  return result;
582  }
583 
584  /* Dont use zone masking */
585  memset(&o_zone_mask, 0, sizeof(o_zone_mask));
586  memset(&o_modify_mask, 0, sizeof(o_modify_mask));
587  memset(&r_zone_mask, 0, sizeof(r_zone_mask));
588  memset(&r_modify_mask, 0, sizeof(r_modify_mask));
589 
590  ct_flags = DOCA_FLOW_CT_FLAG_NO_AGING;
591  result = init_doca_flow_ct(ct_flags,
592  nb_arm_queues,
593  nb_ctrl_queues,
594  nb_user_actions,
595  NULL,
596  nb_ipv4_sessions,
597  nb_ipv6_sessions,
598  0,
599  false,
600  &o_zone_mask,
601  &o_modify_mask,
602  false,
603  &r_zone_mask,
604  &r_modify_mask);
605  if (result != DOCA_SUCCESS) {
607  return result;
608  }
609 
610  memset(dev_arr, 0, sizeof(struct doca_dev *) * nb_ports);
611  dev_arr[0] = ct_dev;
614  if (result != DOCA_SUCCESS) {
615  DOCA_LOG_ERR("Failed to init DOCA ports: %s", doca_error_get_descr(result));
618  return result;
619  }
620 
621  result = create_rss_pipe(ports[0], &ctrl_status, &rss_pipe);
622  if (result != DOCA_SUCCESS)
623  goto cleanup;
624 
625  result = create_egress_pipe(ports[0], 1, &ctrl_status, &egress_pipe);
626  if (result != DOCA_SUCCESS)
627  goto cleanup;
628 
629  result = create_tcp_flags_filter_pipe(ports[0], &ctrl_status, egress_pipe, rss_pipe, &tcp_flags_filter_pipe);
630  if (result != DOCA_SUCCESS)
631  goto cleanup;
632 
633  result = create_ct_miss_pipe(ports[0], rss_pipe, &ctrl_status, &ct_miss_pipe);
634  if (result != DOCA_SUCCESS)
635  goto cleanup;
636 
637  result = create_ct_pipe(ports[0], tcp_flags_filter_pipe, ct_miss_pipe, &ct_pipe);
638  if (result != DOCA_SUCCESS)
639  goto cleanup;
640 
641  result = create_ct_root_pipe(ports[0], true, false, DOCA_FLOW_L4_META_TCP, ct_pipe, &ctrl_status, &tcp_pipe);
642  if (result != DOCA_SUCCESS)
643  goto cleanup;
644 
646  if (result != DOCA_SUCCESS) {
647  DOCA_LOG_ERR("Failed to process Flow CT entries: %s", doca_error_get_descr(result));
648  goto cleanup;
649  }
650 
651  if (ctrl_status.nb_processed != nb_entries || ctrl_status.failure) {
652  DOCA_LOG_ERR("Failed to process entries");
654  goto cleanup;
655  }
656 
657  DOCA_LOG_INFO("Wait few seconds for 'SYN' packet to arrive");
658 
659  sleep(5);
660  result = process_packets(ports[0], ct_queue, &ct_status, &tcp_entry);
661  if (result != DOCA_SUCCESS)
662  goto cleanup;
663 
664  sleep(7);
665  result = process_packets(ports[0], ct_queue, &ct_status, &tcp_entry);
666  if (result != DOCA_SUCCESS)
667  goto cleanup;
668 
669 cleanup:
670  cleanup_procedure(ct_pipe, nb_ports, ports);
671  return result;
672 }
#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
static void cleanup(struct cache_invalidate_sample_state *state)
#define unlikely(x)
Definition: utils.h:42
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[])
static int nb_entries
#define PACKET_BURST
DOCA_LOG_REGISTER(FLOW_CT_TCP)
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 process_packets(struct doca_flow_port *port, uint16_t ct_queue, struct entries_status *ct_status, struct doca_flow_pipe_entry **entry)
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_egress_pipe(struct doca_flow_port *port, int port_id, struct entries_status *status, struct doca_flow_pipe **pipe)
static doca_error_t create_ct_miss_pipe(struct doca_flow_port *port, struct doca_flow_pipe *fwd_pipe, struct entries_status *status, struct doca_flow_pipe **pipe)
static doca_error_t create_tcp_flags_filter_pipe(struct doca_flow_port *port, struct entries_status *status, struct doca_flow_pipe *fwd_pipe, struct doca_flow_pipe *fwd_miss_pipe, struct doca_flow_pipe **pipe)
static void parse_packet(struct rte_mbuf *packet, struct doca_flow_ct_match *match_o, struct doca_flow_ct_match *match_r, uint8_t *tcp_state)
static uint16_t sessions
doca_error_t flow_ct_tcp(uint16_t nb_queues, struct doca_dev *ct_dev)
static doca_error_t destroy_pipe_cfg(struct doca_flow_pipe_cfg *cfg)
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_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
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_rm_entry(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_pipe_entry *entry)
remove CT entry.
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_FLAG_NO_AGING
Definition: doca_flow_ct.h:58
#define DOCA_FLOW_PROTO_TCP
Definition: doca_flow_net.h:41
@ DOCA_FLOW_L4_TYPE_EXT_TCP
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_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_FLOW_RSS_TCP
Definition: doca_flow.h:770
@ DOCA_FLOW_RSS_IPV4
Definition: doca_flow.h:764
@ DOCA_FLOW_PIPE_CT
Definition: doca_flow.h:227
@ DOCA_FLOW_PIPE_BASIC
Definition: doca_flow.h:221
@ DOCA_FLOW_MATCH_TCP_FLAG_FIN
Definition: doca_flow.h:403
@ DOCA_FLOW_MATCH_TCP_FLAG_RST
Definition: doca_flow.h:407
@ DOCA_FLOW_MATCH_TCP_FLAG_SYN
Definition: doca_flow.h:405
@ 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_TCP
Definition: doca_flow.h:308
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_WARN(format,...)
Generates a WARNING application log message.
Definition: doca_log.h:476
#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
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
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
enum doca_flow_l4_type_ext l4_type_ext
Definition: doca_flow.h:454
struct doca_flow_header_tcp tcp
Definition: doca_flow.h:461
doca flow matcher information
Definition: doca_flow.h:491
struct doca_flow_header_format outer
Definition: doca_flow.h:498
doca flow meta data
Definition: doca_flow.h:358
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 src_port
Definition: packets.h:80
uint8_t tcp_flags
Definition: packets.h:85
uint16_t dst_port
Definition: packets.h:81
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