NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_ct_udp_query_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 #define DEFAULT_UDP_DELAY_S 2
40 #define DEFAULT_CNT_QUERY_INTERVAL 1
41 
42 DOCA_LOG_REGISTER(FLOW_CT_UDP);
43 
44 /*
45  * Create RSS pipe
46  *
47  * @port [in]: Pipe port
48  * @status [in]: User context for adding entry
49  * @pipe [out]: Created pipe pointer
50  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
51  */
52 static doca_error_t create_rss_pipe(struct doca_flow_port *port,
53  struct entries_status *status,
54  struct doca_flow_pipe **pipe)
55 {
56  struct doca_flow_match match;
57  struct doca_flow_pipe_cfg *cfg;
58  struct doca_flow_fwd fwd;
59  uint16_t rss_queues[1];
61 
62  memset(&match, 0, sizeof(match));
63  memset(&fwd, 0, sizeof(fwd));
64 
66  if (result != DOCA_SUCCESS) {
67  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
68  return result;
69  }
70 
71  result = set_flow_pipe_cfg(cfg, "RSS_PIPE", DOCA_FLOW_PIPE_BASIC, false);
72  if (result != DOCA_SUCCESS) {
73  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
74  goto destroy_pipe_cfg;
75  }
77  if (result != DOCA_SUCCESS) {
78  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
79  goto destroy_pipe_cfg;
80  }
81 
82  /* RSS queue - send matched traffic to queue 0 */
83  rss_queues[0] = 0;
88  fwd.rss.nr_queues = 1;
89 
91  if (result != DOCA_SUCCESS) {
92  DOCA_LOG_ERR("Failed to create RSS pipe: %s", doca_error_get_descr(result));
93  goto destroy_pipe_cfg;
94  }
96 
97  /* Match on any packet */
98  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, &fwd, 0, status, NULL);
99  if (result != DOCA_SUCCESS) {
100  DOCA_LOG_ERR("Failed to add RSS pipe entry: %s", doca_error_get_descr(result));
101  return result;
102  }
103 
105  if (result != DOCA_SUCCESS)
106  DOCA_LOG_ERR("Failed to process RSS entry: %s", doca_error_get_descr(result));
107 
108  return result;
109 
112  return result;
113 }
114 
115 /*
116  * Create CT pipe
117  *
118  * @port [in]: Pipe port
119  * @fwd_pipe [in]: Forward pipe pointer
120  * @fwd_miss_pipe [in]: Forward miss pipe pointer
121  * @pipe [out]: Created pipe pointer
122  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
123  */
124 static doca_error_t create_ct_pipe(struct doca_flow_port *port,
125  struct doca_flow_pipe *fwd_pipe,
126  struct doca_flow_pipe *fwd_miss_pipe,
127  struct doca_flow_pipe **pipe)
128 {
129  struct doca_flow_match match;
130  struct doca_flow_match mask;
131  struct doca_flow_pipe_cfg *cfg;
132  struct doca_flow_fwd fwd;
133  struct doca_flow_fwd fwd_miss;
135 
136  memset(&match, 0, sizeof(match));
137  memset(&mask, 0, sizeof(mask));
138  memset(&fwd, 0, sizeof(fwd));
139  memset(&fwd_miss, 0, sizeof(fwd));
140 
142  if (result != DOCA_SUCCESS) {
143  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
144  return result;
145  }
146 
147  result = set_flow_pipe_cfg(cfg, "CT_PIPE", DOCA_FLOW_PIPE_CT, false);
148  if (result != DOCA_SUCCESS) {
149  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
150  goto destroy_pipe_cfg;
151  }
152  result = doca_flow_pipe_cfg_set_match(cfg, &match, &mask);
153  if (result != DOCA_SUCCESS) {
154  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
155  goto destroy_pipe_cfg;
156  }
157 
159  fwd.next_pipe = fwd_pipe;
160 
162  fwd_miss.next_pipe = fwd_miss_pipe;
163 
165  if (result != DOCA_SUCCESS)
166  DOCA_LOG_ERR("Failed to add CT pipe: %s", doca_error_get_descr(result));
169  return result;
170 }
171 
172 /*
173  * Create VxLAN encapsulation pipe
174  *
175  * @port [in]: Pipe port
176  * @port_id [in]: Forward port ID
177  * @status [in]: User context for adding entry
178  * @pipe [out]: Created pipe pointer
179  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
180  */
181 static doca_error_t create_vxlan_encap_pipe(struct doca_flow_port *port,
182  int port_id,
183  struct entries_status *status,
184  struct doca_flow_pipe **pipe)
185 {
186  struct doca_flow_match match;
187  struct doca_flow_actions actions;
188  struct doca_flow_actions *actions_list[] = {&actions};
189  struct doca_flow_fwd fwd;
190  struct doca_flow_pipe_cfg *pipe_cfg;
191  uint8_t src_mac[] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
192  uint8_t dst_mac[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
194 
195  memset(&match, 0, sizeof(match));
196  memset(&actions, 0, sizeof(actions));
197  memset(&fwd, 0, sizeof(fwd));
198 
199  SET_MAC_ADDR(actions.encap_cfg.encap.outer.eth.src_mac, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
200  SET_MAC_ADDR(actions.encap_cfg.encap.outer.eth.dst_mac, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
202  actions.encap_cfg.encap.outer.ip4.src_ip = 0xffffffff;
203  actions.encap_cfg.encap.outer.ip4.dst_ip = 0xffffffff;
208  actions.encap_cfg.encap.tun.vxlan_tun_id = 0xffffffff;
210  actions.encap_cfg.is_l2 = true;
211 
212  result = doca_flow_pipe_cfg_create(&pipe_cfg, port);
213  if (result != DOCA_SUCCESS) {
214  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
215  return result;
216  }
217 
218  result = set_flow_pipe_cfg(pipe_cfg, "VXLAN_ENCAP_PIPE", DOCA_FLOW_PIPE_BASIC, true);
219  if (result != DOCA_SUCCESS) {
220  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
221  goto destroy_pipe_cfg;
222  }
224  if (result != DOCA_SUCCESS) {
225  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg domain: %s", doca_error_get_descr(result));
226  goto destroy_pipe_cfg;
227  }
228  result = doca_flow_pipe_cfg_set_match(pipe_cfg, &match, NULL);
229  if (result != DOCA_SUCCESS) {
230  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
231  goto destroy_pipe_cfg;
232  }
233  result = doca_flow_pipe_cfg_set_actions(pipe_cfg, actions_list, NULL, NULL, 1);
234  if (result != DOCA_SUCCESS) {
235  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg actions: %s", doca_error_get_descr(result));
236  goto destroy_pipe_cfg;
237  }
238 
240  fwd.port_id = port_id;
241 
242  result = doca_flow_pipe_create(pipe_cfg, &fwd, NULL, pipe);
243  if (result != DOCA_SUCCESS) {
244  DOCA_LOG_ERR("Failed to create VxLAN Encap pipe: %s", doca_error_get_descr(result));
245  goto destroy_pipe_cfg;
246  }
247  doca_flow_pipe_cfg_destroy(pipe_cfg);
248 
249  memset(&actions, 0, sizeof(actions));
251  src_mac[0],
252  src_mac[1],
253  src_mac[2],
254  src_mac[3],
255  src_mac[4],
256  src_mac[5]);
258  dst_mac[0],
259  dst_mac[1],
260  dst_mac[2],
261  dst_mac[3],
262  dst_mac[4],
263  dst_mac[5]);
264  actions.encap_cfg.encap.outer.ip4.src_ip = BE_IPV4_ADDR(11, 21, 31, 41);
265  actions.encap_cfg.encap.outer.ip4.dst_ip = BE_IPV4_ADDR(81, 81, 81, 81);
268  actions.action_idx = 0;
269 
270  result = doca_flow_pipe_add_entry(0, *pipe, &match, &actions, NULL, NULL, 0, status, NULL);
271  if (result != DOCA_SUCCESS) {
272  DOCA_LOG_ERR("Failed to add VxLAN Encap pipe entry: %s", doca_error_get_descr(result));
273  return result;
274  }
275 
277  if (result != DOCA_SUCCESS)
278  DOCA_LOG_ERR("Failed to process UDP entry: %s", doca_error_get_descr(result));
279 
280  return result;
281 
283  doca_flow_pipe_cfg_destroy(pipe_cfg);
284  return result;
285 }
286 
287 /*
288  * Create pipe to count packets based on 5 tuple match
289  *
290  * @port [in]: Pipe port
291  * @fwd_pipe [in]: Next pipe pointer
292  * @status [in]: User context for adding entry
293  * @pipe [out]: Created pipe pointer
294  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
295  */
296 static doca_error_t create_count_pipe(struct doca_flow_port *port,
297  struct doca_flow_pipe *fwd_pipe,
298  struct entries_status *status,
299  struct doca_flow_pipe **pipe)
300 {
301  struct doca_flow_match match;
302  struct doca_flow_monitor monitor;
303  struct doca_flow_fwd fwd;
304  struct doca_flow_fwd fwd_miss;
305  struct doca_flow_pipe_cfg *pipe_cfg;
307 
308  memset(&match, 0, sizeof(match));
309  memset(&monitor, 0, sizeof(monitor));
310  memset(&fwd, 0, sizeof(fwd));
311  memset(&fwd_miss, 0, sizeof(fwd_miss));
312 
313  /* 5 tuple match */
318  match.outer.ip4.src_ip = 0xffffffff;
319  match.outer.ip4.dst_ip = 0xffffffff;
320  match.outer.udp.l4_port.src_port = 0xffff;
321  match.outer.udp.l4_port.dst_port = 0xffff;
322 
324 
325  result = doca_flow_pipe_cfg_create(&pipe_cfg, port);
326  if (result != DOCA_SUCCESS) {
327  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
328  return result;
329  }
330 
331  result = set_flow_pipe_cfg(pipe_cfg, "COUNT_PIPE", DOCA_FLOW_PIPE_BASIC, false);
332  if (result != DOCA_SUCCESS) {
333  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
334  goto destroy_pipe_cfg;
335  }
336  result = doca_flow_pipe_cfg_set_match(pipe_cfg, &match, NULL);
337  if (result != DOCA_SUCCESS) {
338  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
339  goto destroy_pipe_cfg;
340  }
342  if (result != DOCA_SUCCESS) {
343  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg monitor: %s", doca_error_get_descr(result));
344  goto destroy_pipe_cfg;
345  }
346 
348  fwd.next_pipe = fwd_pipe;
349 
351  fwd_miss.next_pipe = fwd_pipe;
352 
353  result = doca_flow_pipe_create(pipe_cfg, &fwd, &fwd_miss, pipe);
354  if (result != DOCA_SUCCESS) {
355  DOCA_LOG_ERR("Failed to create count pipe: %s", doca_error_get_descr(result));
356  goto destroy_pipe_cfg;
357  }
358  doca_flow_pipe_cfg_destroy(pipe_cfg);
359 
360  memset(&match, 0, sizeof(match));
361  match.outer.ip4.dst_ip = BE_IPV4_ADDR(8, 8, 8, 8);
362  match.outer.ip4.src_ip = BE_IPV4_ADDR(1, 2, 3, 4);
363  match.outer.udp.l4_port.dst_port = rte_cpu_to_be_16(80);
364  match.outer.udp.l4_port.src_port = rte_cpu_to_be_16(1234);
365 
366  result = doca_flow_pipe_add_entry(0, *pipe, &match, NULL, NULL, NULL, 0, status, NULL);
367  if (result != DOCA_SUCCESS) {
368  DOCA_LOG_ERR("Failed to add count pipe entry: %s", doca_error_get_descr(result));
369  return result;
370  }
371 
373  if (result != DOCA_SUCCESS)
374  DOCA_LOG_ERR("Failed to process count entry: %s", doca_error_get_descr(result));
375 
376  return result;
377 
379  doca_flow_pipe_cfg_destroy(pipe_cfg);
380  return result;
381 }
382 
383 /*
384  * Parse UDP packet to update CT tables
385  *
386  * @packet [in]: Packet to parse
387  * @match_o [out]: Origin match struct to fill
388  * @match_r [out]: Reply match struct to fill
389  */
390 static void parse_packet(struct rte_mbuf *packet,
391  struct doca_flow_ct_match *match_o,
392  struct doca_flow_ct_match *match_r)
393 {
394  uint8_t *l4_hdr;
395  struct rte_ipv4_hdr *ipv4_hdr;
396  const struct rte_udp_hdr *udp_hdr;
397 
398  ipv4_hdr = rte_pktmbuf_mtod_offset(packet, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr));
399 
400  match_o->ipv4.src_ip = ipv4_hdr->src_addr;
401  match_o->ipv4.dst_ip = ipv4_hdr->dst_addr;
402  match_r->ipv4.src_ip = match_o->ipv4.dst_ip;
403  match_r->ipv4.dst_ip = match_o->ipv4.src_ip;
404 
405  l4_hdr = (typeof(l4_hdr))ipv4_hdr + rte_ipv4_hdr_len(ipv4_hdr);
406  udp_hdr = (typeof(udp_hdr))l4_hdr;
407 
408  match_o->ipv4.l4_port.src_port = udp_hdr->src_port;
409  match_o->ipv4.l4_port.dst_port = udp_hdr->dst_port;
410  match_r->ipv4.l4_port.src_port = match_o->ipv4.l4_port.dst_port;
411  match_r->ipv4.l4_port.dst_port = match_o->ipv4.l4_port.src_port;
412 
415 }
416 
417 /*
418  * Dequeue packets from DPDK queues, parse and update CT tables with new connection 5 tuple
419  *
420  * @port [in]: Port id to which an entry should be inserted
421  * @ct_queue [in]: DOCA Flow CT queue number
422  * @ct_status [in]: User context for adding CT entry
423  * @entry [out]: CT entry to create
424  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
425  */
426 static doca_error_t process_packets(struct doca_flow_port *port,
427  uint16_t ct_queue,
428  struct entries_status *ct_status,
429  struct doca_flow_pipe_entry **entry)
430 {
431  struct rte_mbuf *packets[PACKET_BURST];
432  struct doca_flow_ct_match match_o;
433  struct doca_flow_ct_match match_r;
434  uint32_t flags;
436  int i, entries, nb_packets = 0;
437  bool conn_found = false;
438 
439  memset(&match_o, 0, sizeof(match_o));
440  memset(&match_r, 0, sizeof(match_r));
441 
442  nb_packets = rte_eth_rx_burst(0, 0, packets, PACKET_BURST);
443  if (nb_packets == 0) {
444  DOCA_LOG_INFO("Sample didn't receive packets to process");
445  return DOCA_ERROR_BAD_STATE;
446  }
447 
448  entries = 0;
449  DOCA_LOG_INFO("Sample received %d packets", nb_packets);
450  for (i = 0; i < PACKET_BURST && i < nb_packets; i++) {
451  parse_packet(packets[i], &match_o, &match_r);
454  /* Allocate CT entry */
456  NULL,
457  flags,
458  &match_o,
459  packets[i]->hash.rss,
460  &match_r,
461  packets[i]->hash.rss,
462  entry,
463  &conn_found);
464  if (result != DOCA_SUCCESS) {
465  DOCA_LOG_ERR("Failed to prepare CT entry\n");
466  return result;
467  }
468 
469  if (!conn_found) {
472  result = doca_flow_ct_add_entry(ct_queue,
473  NULL,
474  flags,
475  &match_o,
476  &match_r,
477  NULL,
478  NULL,
479  0,
480  0,
481  0,
482  ct_status,
483  *entry);
484  if (result != DOCA_SUCCESS) {
485  DOCA_LOG_ERR("Failed to add CT pipe an entry: %s", doca_error_get_descr(result));
486  return result;
487  }
488  entries++;
489  }
490  }
491 
492  while (ct_status->nb_processed != entries) {
493  result = doca_flow_ct_entries_process(port, ct_queue, 0, 0, NULL);
494  if (result != DOCA_SUCCESS) {
495  DOCA_LOG_ERR("Failed to process Flow CT entries: %s", doca_error_get_descr(result));
496  return result;
497  }
498 
499  if (ct_status->failure) {
500  DOCA_LOG_ERR("Flow CT entries process returned with a failure");
501  return DOCA_ERROR_BAD_STATE;
502  }
503  }
504 
505  return DOCA_SUCCESS;
506 }
507 
508 /*
509  * Run flow_ct_udp_query sample
510  *
511  * @nb_queues [in]: number of queues the sample will use
512  * @ct_dev [in]: Flow CT device
513  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
514  */
515 doca_error_t flow_ct_udp_query(uint16_t nb_queues, struct doca_dev *ct_dev)
516 {
517  const int nb_ports = 2, nb_entries = 6;
518  struct flow_resources resource;
519  uint32_t nr_shared_resources[SHARED_RESOURCE_NUM_VALUES] = {0};
520  struct doca_flow_pipe_entry *ct_entry;
521  struct doca_flow_pipe *rss_pipe, *encap_pipe, *count_pipe, *ct_pipe = NULL, *udp_pipe;
522  struct doca_flow_port *ports[nb_ports];
523  struct doca_flow_meta o_zone_mask, o_modify_mask, r_zone_mask, r_modify_mask;
524  struct doca_flow_resource_query query_o, query_r;
525  struct doca_dev *dev_arr[nb_ports];
526  uint32_t actions_mem_size[nb_ports];
527  struct entries_status ctrl_status, ct_status;
528  uint64_t last_hit_s = 0;
529  uint32_t ct_flags, nb_arm_queues = 1, nb_ctrl_queues = 1, nb_user_actions = 0, nb_ipv4_sessions = 1024,
530  nb_ipv6_sessions = 0; /* On BF2 should always be 0 */
531  uint16_t ct_queue = nb_queues;
533  FILE *fd;
534 
535  memset(&ctrl_status, 0, sizeof(ctrl_status));
536  memset(&ct_status, 0, sizeof(ct_status));
537  memset(&resource, 0, sizeof(resource));
538 
539  resource.nr_counters = 1;
540 
541  result = init_doca_flow(nb_queues, "switch,hws", &resource, nr_shared_resources);
542  if (result != DOCA_SUCCESS) {
543  DOCA_LOG_ERR("Failed to init DOCA Flow: %s", doca_error_get_descr(result));
544  return result;
545  }
546 
547  /* Dont use zone masking */
548  memset(&o_zone_mask, 0, sizeof(o_zone_mask));
549  memset(&o_modify_mask, 0, sizeof(o_modify_mask));
550  memset(&r_zone_mask, 0, sizeof(r_zone_mask));
551  memset(&r_modify_mask, 0, sizeof(r_modify_mask));
552 
553  ct_flags = DOCA_FLOW_CT_FLAG_NO_AGING;
554  result = init_doca_flow_ct(ct_flags,
555  nb_arm_queues,
556  nb_ctrl_queues,
557  nb_user_actions,
558  NULL,
559  nb_ipv4_sessions,
560  nb_ipv6_sessions,
562  false,
563  &o_zone_mask,
564  &o_modify_mask,
565  false,
566  &r_zone_mask,
567  &r_modify_mask);
568  if (result != DOCA_SUCCESS) {
570  return result;
571  }
572 
573  memset(dev_arr, 0, sizeof(struct doca_dev *) * nb_ports);
574  dev_arr[0] = ct_dev;
577  if (result != DOCA_SUCCESS) {
578  DOCA_LOG_ERR("Failed to init DOCA ports: %s", doca_error_get_descr(result));
581  return result;
582  }
583 
584  result = create_rss_pipe(ports[0], &ctrl_status, &rss_pipe);
585  if (result != DOCA_SUCCESS)
586  goto cleanup;
587 
588  result = create_vxlan_encap_pipe(ports[0], 0, &ctrl_status, &encap_pipe);
589  if (result != DOCA_SUCCESS)
590  goto cleanup;
591 
592  result = create_count_pipe(ports[0], rss_pipe, &ctrl_status, &count_pipe);
593  if (result != DOCA_SUCCESS)
594  goto cleanup;
595 
596  result = create_ct_pipe(ports[0], encap_pipe, count_pipe, &ct_pipe);
597  if (result != DOCA_SUCCESS)
598  goto cleanup;
599 
600  result = create_ct_root_pipe(ports[0], true, false, DOCA_FLOW_L4_META_UDP, ct_pipe, &ctrl_status, &udp_pipe);
601  if (result != DOCA_SUCCESS)
602  goto cleanup;
603 
604  if (ctrl_status.nb_processed != nb_entries || ctrl_status.failure) {
605  DOCA_LOG_ERR("Failed to process control path entries");
607  goto cleanup;
608  }
609 
610  DOCA_LOG_INFO("Wait few seconds for packets to arrive");
611  sleep(5);
612 
613  result = process_packets(ports[0], ct_queue, &ct_status, &ct_entry);
614  if (result != DOCA_SUCCESS)
615  goto cleanup;
616 
618 
619  DOCA_LOG_INFO("Same UDP packet should be resent");
620  sleep(5);
621 
622  fd = fopen("port_0_info.txt", "w");
623  if (fd == NULL) {
624  DOCA_LOG_ERR("Failed to open the file");
626  goto cleanup;
627  }
628 
629  /* dump port 0 info to a file */
631  fclose(fd);
632 
633  result = doca_flow_ct_query_entry(ct_queue,
634  ct_pipe,
636  ct_entry,
637  &query_o,
638  &query_r,
639  &last_hit_s);
640  if (result != DOCA_SUCCESS) {
641  DOCA_LOG_ERR("Failed to query CT entry: %s", doca_error_get_descr(result));
642  goto cleanup;
643  }
644 
645  DOCA_LOG_INFO("Port 0:");
646  DOCA_LOG_INFO("Origin Total bytes: %ld", query_o.counter.total_bytes);
647  DOCA_LOG_INFO("Origin Total packets: %ld", query_o.counter.total_pkts);
648  DOCA_LOG_INFO("Reply Total bytes: %ld", query_r.counter.total_bytes);
649  DOCA_LOG_INFO("Reply Total packets: %ld", query_r.counter.total_pkts);
650  DOCA_LOG_INFO("Last hit since Epoch (sec) : %ld", last_hit_s);
651 
652 cleanup:
653  cleanup_procedure(ct_pipe, nb_ports, ports);
654  return result;
655 }
#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 struct doca_flow_pipe_entry * ct_entry
static int nb_entries
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)
#define PACKET_BURST
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)
DOCA_LOG_REGISTER(FLOW_CT_UDP)
static doca_error_t create_rss_pipe(struct doca_flow_port *port, struct entries_status *status, struct doca_flow_pipe **pipe)
doca_error_t flow_ct_udp_query(uint16_t nb_queues, struct doca_dev *ct_dev)
#define DEFAULT_UDP_DELAY_S
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, struct doca_flow_ct_match *match_r)
#define DEFAULT_CNT_QUERY_INTERVAL
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_ERROR_IO_FAILED
Definition: doca_error.h:55
@ 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_query_entry(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_pipe_entry *entry, struct doca_flow_resource_query *stats_origin, struct doca_flow_resource_query *stats_reply, uint64_t *last_hit_s)
Extract information about specific entry.
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_COUNTER_REPLY
Definition: doca_flow_ct.h:677
@ 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_REPLY
Definition: doca_flow_ct.h:687
@ DOCA_FLOW_CT_ENTRY_FLAGS_DUP_FILTER_ORIGIN
Definition: doca_flow_ct.h:685
@ DOCA_FLOW_CT_ENTRY_FLAGS_COUNTER_ORIGIN
Definition: doca_flow_ct.h:675
@ 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 void doca_flow_port_pipes_dump(struct doca_flow_port *port, FILE *f)
Dump pipes of one port.
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
flow resource query
Definition: doca_flow.h:1101
struct doca_flow_resource_query::@115::@117 counter
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