NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_switch_hot_upgrade_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 <stdint.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <signal.h>
30 #include <errno.h>
31 #include <sys/time.h>
32 
33 #include <doca_dev.h>
34 #include <doca_log.h>
35 #include <doca_flow.h>
36 #include "doca_error.h"
37 
38 #include "flow_common.h"
39 
40 DOCA_LOG_REGISTER(FLOW_SWITCH_HOT_UPGRADE);
41 
42 #define FLOW_SWITCH_PROXY_PORT_NB 2
43 
44 #define INTERVAL_QUERY_TIME 1
45 
46 #define SEC2USEC(sec) ((sec) * (1000000L))
47 
48 #define DEFAULT_CTRL_PIPE_SIZE (8192)
49 
50 /* Structure to control all port logic */
51 struct port_control {
52  struct doca_flow_port *port; /* DOCA Flow switch port */
53  struct doca_flow_pipe *pipe; /* Root pipe of the port */
54  struct doca_flow_pipe_entry *tcp_entry; /* Entry matching TCP packets */
55  struct doca_flow_pipe_entry *udp_entry; /* Entry matching UDP packets */
56  char pci_dev[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* PCI address as string */
57  char iface_name[DOCA_DEVINFO_IFACE_NAME_SIZE]; /* Port interface name */
58  uint64_t last_hit_tcp; /* Number TCP packets received so far */
59  uint64_t last_hit_udp; /* Number UDP packets received so far */
60  uint64_t last_miss; /* Number miss packets received so far */
61  uint64_t last_total; /* Total packets received so far */
62 };
63 
64 static struct doca_flow_port *switch_ports[FLOW_SWITCH_PROXY_PORT_NB];
65 static uint8_t waiting_for_traffic;
66 
67 /* The current operation state of the switch ports in this instance */
69 
70 /*
71  * Create DOCA Flow pipe with L3/L4 match on the switch port.
72  * Matched traffic will be forwarded to the port defined per entry.
73  * Unmatched traffic will be dropped.
74  *
75  * @port [in]: switch port
76  * @pipe [out]: created pipe pointer
77  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
78  */
79 static doca_error_t create_switch_pipe(struct doca_flow_port *port, struct doca_flow_pipe **pipe)
80 {
81  struct doca_flow_match match;
83  struct doca_flow_fwd fwd;
84  struct doca_flow_fwd fwd_miss;
85  struct doca_flow_pipe_cfg *pipe_cfg;
87 
88  memset(&match, 0, sizeof(match));
89  memset(&monitor, 0, sizeof(monitor));
90  memset(&fwd, 0, sizeof(fwd));
91  memset(&fwd_miss, 0, sizeof(fwd_miss));
92 
93  result = doca_flow_pipe_cfg_create(&pipe_cfg, port);
94  if (result != DOCA_SUCCESS) {
95  DOCA_LOG_ERR("Failed to create doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
96  return result;
97  }
98 
99  result = set_flow_pipe_cfg(pipe_cfg, "SWITCH_PIPE", DOCA_FLOW_PIPE_BASIC, true);
100  if (result != DOCA_SUCCESS) {
101  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg: %s", doca_error_get_descr(result));
102  goto destroy_pipe_cfg;
103  }
104 
106  if (result != DOCA_SUCCESS) {
107  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg nr_entries: %s", doca_error_get_descr(result));
108  goto destroy_pipe_cfg;
109  }
110 
112  if (result != DOCA_SUCCESS) {
113  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg nr_entries: %s", doca_error_get_descr(result));
114  goto destroy_pipe_cfg;
115  }
116 
117  match.parser_meta.outer_l3_type = DOCA_FLOW_L3_META_IPV4; /* specific */
118  match.parser_meta.outer_l4_type = UINT32_MAX; /* changeable */
119  result = doca_flow_pipe_cfg_set_match(pipe_cfg, &match, NULL);
120  if (result != DOCA_SUCCESS) {
121  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg match: %s", doca_error_get_descr(result));
122  goto destroy_pipe_cfg;
123  }
124 
127  if (result != DOCA_SUCCESS) {
128  DOCA_LOG_ERR("Failed to set doca_flow_pipe_cfg monitor: %s", doca_error_get_descr(result));
129  goto destroy_pipe_cfg;
130  }
131 
133  fwd.port_id = 0xffff; /* changeable */
135 
136  result = doca_flow_pipe_create(pipe_cfg, &fwd, &fwd_miss, pipe);
138  doca_flow_pipe_cfg_destroy(pipe_cfg);
139  return result;
140 }
141 
142 /*
143  * Add DOCA Flow pipe entry to the pipe.
144  *
145  * @switch_port_idx [in]: switch port index.
146  * @control [in]: port control with all needed information.
147  * @status [in]: user context for adding entries.
148  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
149  */
150 static doca_error_t add_switch_pipe_entries(uint8_t switch_port_idx,
151  struct port_control *control,
152  struct entries_status *status)
153 {
154  struct doca_flow_match match;
155  struct doca_flow_fwd fwd;
157 
158  memset(&fwd, 0, sizeof(fwd));
159  memset(&match, 0, sizeof(match));
160  memset(status, 0, sizeof(*status));
161 
164  fwd.port_id = (switch_port_idx * 3) + 1; /* first representor of this port */
165 
167  control->pipe,
168  &match,
169  NULL,
170  NULL,
171  &fwd,
173  status,
174  &control->tcp_entry);
175  if (result != DOCA_SUCCESS) {
176  DOCA_LOG_ERR("Failed to add TCP pipe entry: %s", doca_error_get_descr(result));
177  return result;
178  }
179 
181  fwd.port_id = (switch_port_idx * 3) + 2; /* second representor of this port */
182 
184  control->pipe,
185  &match,
186  NULL,
187  NULL,
188  &fwd,
190  status,
191  &control->udp_entry);
192  if (result != DOCA_SUCCESS) {
193  DOCA_LOG_ERR("Failed to add UDP pipe entry: %s", doca_error_get_descr(result));
194  return result;
195  }
196 
197  result = flow_process_entries(control->port, status, 2);
198  if (result != DOCA_SUCCESS) {
199  DOCA_LOG_ERR("Failed to process entries: %s", doca_error_get_descr(result));
200  return result;
201  }
202 
203  return DOCA_SUCCESS;
204 }
205 
206 /*
207  * Initializes control structure including pipe and entries creation for single switch port.
208  *
209  * @port [in]: switch port.
210  * @dev [in]: DOCA device connected to this port.
211  * @switch_port_idx [in]: switch port index.
212  * @state [in]: the operation state of this instance.
213  * @status [in]: user context for adding entries.
214  * @control [out]: pointer to control port structure.
215  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
216  */
217 static doca_error_t port_control_init(struct doca_flow_port *port,
218  struct doca_dev *dev,
219  uint8_t switch_port_idx,
221  struct entries_status *status,
222  struct port_control *control)
223 {
224  struct doca_devinfo *devinfo;
226 
227  devinfo = doca_dev_as_devinfo(dev);
228  if (devinfo == NULL) {
229  DOCA_LOG_ERR("Failed to convert DOCA device to devinfo for port %u", switch_port_idx);
230  return DOCA_ERROR_NOT_FOUND;
231  }
232 
234  if (result != DOCA_SUCCESS) {
235  DOCA_LOG_ERR("Failed to get interface name for port %u: %s",
236  switch_port_idx,
238  return result;
239  }
240 
241  result = doca_devinfo_get_pci_addr_str(devinfo, control->pci_dev);
242  if (result != DOCA_SUCCESS) {
243  DOCA_LOG_ERR("Failed to get PCI string for port %u: %s", switch_port_idx, doca_error_get_descr(result));
244  return result;
245  }
246 
247  control->port = doca_flow_port_switch_get(port);
248  result = create_switch_pipe(control->port, &control->pipe);
249  if (result != DOCA_SUCCESS) {
250  DOCA_LOG_ERR("Failed to create pipe for port %u", switch_port_idx);
251  return result;
252  }
253 
254  result = add_switch_pipe_entries(switch_port_idx, control, status);
255  if (result != DOCA_SUCCESS) {
256  DOCA_LOG_ERR("Failed to add pipe entries for port %u", switch_port_idx);
257  return result;
258  }
259 
261  if (result != DOCA_SUCCESS) {
262  DOCA_LOG_ERR("Failed to modify operation state for port %u: %s",
263  switch_port_idx,
265  return result;
266  }
267 
268  control->last_hit_tcp = 0;
269  control->last_hit_udp = 0;
270  control->last_miss = 0;
271  control->last_total = 0;
272 
273  switch_ports[switch_port_idx] = control->port;
274 
275  return DOCA_SUCCESS;
276 }
277 
278 /*
279  * Modify operation state for all proxy ports.
280  *
281  * @state [in]: next operation state.
282  */
284 {
285  struct doca_flow_port *port;
287  uint8_t i;
288 
289  for (i = 0; i < FLOW_SWITCH_PROXY_PORT_NB; ++i) {
290  port = switch_ports[i];
291 
293  if (result != DOCA_SUCCESS) {
294  DOCA_LOG_ERR("Failed to modify operation state from %u to %u for port %u: %s",
296  state,
297  i,
299  return;
300  }
301 
302  DOCA_LOG_DBG("Port %u operation state was successfully modified from %u to %u", i, current_state, state);
303  }
304 
305  current_state = state;
306 }
307 
308 /*
309  * Signal handler triggering switch port activation for hot upgrade.
310  *
311  * @signum [in]: signal number.
312  */
313 static void activate_signal_handler(int signum)
314 {
316 
317  printf("\n");
318  DOCA_LOG_INFO("CTRL-C is pressed, running over the ports and activating them");
319 
320  switch (current_state) {
323  break;
326  break;
329  default:
331  break;
332  }
333 
335  (void)signum;
336 }
337 
338 /*
339  * Signal handler for quit.
340  *
341  * @signum [in]: signal number.
342  */
343 static void quit_signal_handler(int signum)
344 {
345  printf("\n");
346  DOCA_LOG_INFO("Signal %d is triggered, quit the sample", signum);
347 
349 
350  /*
351  * Pause for one second before setting the 'waiting_for_traffic' flag to false.
352  * This delay ensures that the query counters loop is stopped at the right time.
353  * The hardware updates the counters every second, so we wait to ensure all
354  * counters are updated before performing the last query.
355  */
356  sleep(1);
357  __atomic_store_n(&waiting_for_traffic, 0, __ATOMIC_RELAXED);
358 }
359 
360 /*
361  * Register the signal handler functions.
362  *
363  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
364  */
365 static int signal_handler_register(void)
366 {
367  struct sigaction action = {0};
368 
369  action.sa_handler = activate_signal_handler;
370  if (sigaction(SIGINT, &action, NULL) == -1) {
371  DOCA_LOG_ERR("Failed to take SIGINT signal for hot upgrade, errno=%d", errno);
372  return -errno;
373  }
374 
375  action.sa_handler = quit_signal_handler;
376  if (sigaction(SIGQUIT, &action, NULL) == -1) {
377  DOCA_LOG_ERR("Failed to take SIGQUIT signal for quit program, errno=%d", errno);
378  return -errno;
379  }
380 
381  return 0;
382 }
383 
384 /*
385  * Query all counters in port.
386  *
387  * Query both UDP and TCP entries as same as miss counter.
388  * When at least one of them is increased, all counter results are printed in this format:
389  * | <type> new_value (old_value)
390  *
391  * @control [in]: pointer to port control structure
392  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
393  */
395 {
396  struct doca_flow_resource_query miss_stats = {0};
397  struct doca_flow_resource_query udp_stats = {0};
398  struct doca_flow_resource_query tcp_stats = {0};
399  uint64_t total;
401 
402  result = doca_flow_resource_query_pipe_miss(control->pipe, &miss_stats);
403  if (result != DOCA_SUCCESS) {
404  DOCA_LOG_ERR("Failed to query pipe miss: %s", doca_error_get_descr(result));
405  return result;
406  }
407 
408  result = doca_flow_resource_query_entry(control->tcp_entry, &tcp_stats);
409  if (result != DOCA_SUCCESS) {
410  DOCA_LOG_ERR("Failed to query TCP entry: %s", doca_error_get_descr(result));
411  return result;
412  }
413 
414  result = doca_flow_resource_query_entry(control->udp_entry, &udp_stats);
415  if (result != DOCA_SUCCESS) {
416  DOCA_LOG_ERR("Failed to query UDP entry: %s", doca_error_get_descr(result));
417  return result;
418  }
419 
420  total = miss_stats.counter.total_pkts + udp_stats.counter.total_pkts + tcp_stats.counter.total_pkts;
421  if (total == control->last_total)
422  return DOCA_SUCCESS;
423 
424  DOCA_LOG_INFO("Device %s with PCI address %s receive new traffic:", control->iface_name, control->pci_dev);
425  DOCA_LOG_INFO("Total traffic %lu (%lu) | TCP %lu (%lu) | UDP %lu (%lu) | miss %lu (%lu)",
426  total,
427  control->last_total,
428  tcp_stats.counter.total_pkts,
429  control->last_hit_tcp,
430  udp_stats.counter.total_pkts,
431  control->last_hit_udp,
432  miss_stats.counter.total_pkts,
433  control->last_miss);
434 
435  control->last_hit_tcp = tcp_stats.counter.total_pkts;
436  control->last_hit_udp = udp_stats.counter.total_pkts;
437  control->last_miss = miss_stats.counter.total_pkts;
438  control->last_total = total;
439 
440  return DOCA_SUCCESS;
441 }
442 
443 /*
444  * Run flow_switch_hot_upgrade sample
445  *
446  * @nb_queues [in]: number of queues the sample will use.
447  * @nb_ports [in]: number of ports the sample will use.
448  * @dev_main [in]: the main doca proxy port.
449  * @dev_sec [in]: the second doca proxy port.
450  * @state [in]: the operation state of this instance.
451  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
452  */
454  int nb_ports,
455  struct doca_dev *dev_main,
456  struct doca_dev *dev_sec,
458 {
459  struct flow_resources resource = {.nr_counters = 6};
460  uint32_t nr_shared_resources[SHARED_RESOURCE_NUM_VALUES] = {0};
461  struct doca_flow_port *ports[nb_ports];
462  struct doca_dev *dev_arr[nb_ports];
463  uint32_t actions_mem_size[nb_ports];
465  struct port_control port_control_list[FLOW_SWITCH_PROXY_PORT_NB];
466  struct entries_status status;
467  struct timeval start, end;
468  long query_time, sleep_time;
469  uint8_t switch_port_idx;
471 
472  result = init_doca_flow(nb_queues, "switch,isolated", &resource, nr_shared_resources);
473  if (result != DOCA_SUCCESS) {
474  DOCA_LOG_ERR("Failed to init DOCA Flow: %s", doca_error_get_descr(result));
475  return result;
476  }
477 
478  memset(dev_arr, 0, sizeof(struct doca_dev *) * nb_ports);
479  dev_arr[0] = dev_main;
480  dev_arr[3] = dev_sec;
481  memset(states, 0, sizeof(enum doca_flow_port_operation_state) * nb_ports);
486  ports,
487  false /* is_hairpin */,
488  dev_arr,
489  states,
491  if (result != DOCA_SUCCESS) {
492  DOCA_LOG_ERR("Failed to init DOCA ports: %s", doca_error_get_descr(result));
494  return result;
495  }
496 
497  for (switch_port_idx = 0; switch_port_idx < FLOW_SWITCH_PROXY_PORT_NB; ++switch_port_idx) {
498  uint8_t port_id = switch_port_idx * 3;
499 
500  result = port_control_init(ports[port_id],
501  dev_arr[port_id],
502  switch_port_idx,
503  state,
504  &status,
505  &port_control_list[switch_port_idx]);
506  if (result != DOCA_SUCCESS) {
507  DOCA_LOG_ERR("Failed to init port control %u", switch_port_idx);
510  return result;
511  }
512  }
513 
514  current_state = state;
515  gettimeofday(&start, NULL);
516 
517  if (signal_handler_register() < 0) {
518  DOCA_LOG_ERR("Failed to register signal handlers");
522  }
523 
524  DOCA_LOG_INFO("Waiting for traffic to arrived, press CTRL+C to make process active or CTRL+\\ for quit");
525  __atomic_store_n(&waiting_for_traffic, 1, __ATOMIC_RELAXED);
526 
527  while (__atomic_load_n(&waiting_for_traffic, __ATOMIC_RELAXED)) {
528  gettimeofday(&end, NULL);
529  query_time = SEC2USEC(end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
530  sleep_time = SEC2USEC(INTERVAL_QUERY_TIME) - query_time;
531  if (sleep_time > 0)
532  usleep(sleep_time);
533 
534  gettimeofday(&start, NULL);
535 
536  for (switch_port_idx = 0; switch_port_idx < FLOW_SWITCH_PROXY_PORT_NB; ++switch_port_idx) {
537  result = port_control_query(&port_control_list[switch_port_idx]);
538  if (result != DOCA_SUCCESS) {
539  DOCA_LOG_ERR("Failed to query port control %u", switch_port_idx);
542  return result;
543  }
544  }
545  }
546 
549  return result;
550 }
#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 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 struct doca_flow_monitor monitor
Definition: flow_parser.c:108
static struct doca_flow_fwd fwd
Definition: flow_parser.c:109
#define FLOW_SWITCH_PROXY_PORT_NB
static uint8_t waiting_for_traffic
doca_error_t flow_switch_hot_upgrade(int nb_queues, int nb_ports, struct doca_dev *dev_main, struct doca_dev *dev_sec, enum doca_flow_port_operation_state state)
static doca_error_t create_switch_pipe(struct doca_flow_port *port, struct doca_flow_pipe **pipe)
static doca_error_t port_control_query(struct port_control *control)
#define INTERVAL_QUERY_TIME
static enum doca_flow_port_operation_state current_state
static doca_error_t port_control_init(struct doca_flow_port *port, struct doca_dev *dev, uint8_t switch_port_idx, enum doca_flow_port_operation_state state, struct entries_status *status, struct port_control *control)
#define DEFAULT_CTRL_PIPE_SIZE
#define SEC2USEC(sec)
static void activate_signal_handler(int signum)
DOCA_LOG_REGISTER(FLOW_SWITCH_HOT_UPGRADE)
static struct doca_flow_port * switch_ports[FLOW_SWITCH_PROXY_PORT_NB]
static doca_error_t add_switch_pipe_entries(uint8_t switch_port_idx, struct port_control *control, struct entries_status *status)
static void ports_operation_state_modify(enum doca_flow_port_operation_state state)
static int signal_handler_register(void)
static void quit_signal_handler(int signum)
#define DOCA_DEVINFO_IFACE_NAME_SIZE
Buffer size to hold network interface name. Including a null terminator.
Definition: doca_dev.h:305
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
DOCA_STABLE doca_error_t doca_devinfo_get_iface_name(const struct doca_devinfo *devinfo, char *iface_name, uint32_t size)
Get the name of the ethernet interface of a DOCA devinfo.
DOCA_STABLE doca_error_t doca_devinfo_get_pci_addr_str(const struct doca_devinfo *devinfo, char *pci_addr_str)
Get the PCI address of a DOCA devinfo.
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_OPERATING_SYSTEM
Definition: doca_error.h:58
@ DOCA_ERROR_NOT_FOUND
Definition: doca_error.h:54
@ DOCA_SUCCESS
Definition: doca_error.h:38
doca_flow_port_operation_state
Defines the operation states for a port instance.
Definition: doca_flow.h:1147
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_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_miss_counter(struct doca_flow_pipe_cfg *cfg, bool miss_counter)
Set to enable pipe's miss counter.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_operation_state_modify(struct doca_flow_port *port, enum doca_flow_port_operation_state state)
Modifies the operation state of a port instance.
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_nr_entries(struct doca_flow_pipe_cfg *cfg, uint32_t nr_entries)
Set pipe's maximum number of flow rules.
DOCA_EXPERIMENTAL doca_error_t doca_flow_resource_query_pipe_miss(struct doca_flow_pipe *pipe, struct doca_flow_resource_query *query_stats)
Extract information about pipe miss entry.
DOCA_STABLE struct doca_flow_port * doca_flow_port_switch_get(const struct doca_flow_port *port)
Get doca flow switch port.
DOCA_EXPERIMENTAL doca_error_t doca_flow_resource_query_entry(struct doca_flow_pipe_entry *entry, struct doca_flow_resource_query *query_stats)
Extract information about specific entry.
@ DOCA_FLOW_PORT_OPERATION_STATE_UNCONNECTED
Definition: doca_flow.h:1154
@ DOCA_FLOW_PORT_OPERATION_STATE_STANDBY
Definition: doca_flow.h:1152
@ DOCA_FLOW_PORT_OPERATION_STATE_ACTIVE
Definition: doca_flow.h:1148
@ DOCA_FLOW_PORT_OPERATION_STATE_ACTIVE_READY_TO_SWAP
Definition: doca_flow.h:1150
@ DOCA_FLOW_PIPE_BASIC
Definition: doca_flow.h:221
@ DOCA_FLOW_L3_META_IPV4
Definition: doca_flow.h:296
@ DOCA_FLOW_NO_WAIT
Definition: doca_flow.h:115
@ DOCA_FLOW_WAIT_FOR_BATCH
Definition: doca_flow.h:117
@ DOCA_FLOW_RESOURCE_TYPE_NON_SHARED
Definition: doca_flow.h:615
@ DOCA_FLOW_FWD_PORT
Definition: doca_flow.h:744
@ DOCA_FLOW_FWD_DROP
Definition: doca_flow.h:748
@ DOCA_FLOW_L4_META_UDP
Definition: doca_flow.h:310
@ 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_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
#define DOCA_LOG_DBG(format,...)
Generates a DEBUG application log message.
Definition: doca_log.h:496
doca_error_t flow_process_entries(struct doca_flow_port *port, struct entries_status *status, uint32_t nr_entries)
Definition: flow_common.c:338
doca_error_t stop_doca_flow_ports(int nb_ports, struct doca_flow_port *ports[])
Definition: flow_common.c:240
doca_error_t init_doca_flow_ports_with_op_state(int nb_ports, struct doca_flow_port *ports[], bool is_hairpin, struct doca_dev *dev_arr[], enum doca_flow_port_operation_state *states, uint32_t actions_mem_size[])
Definition: flow_common.c:260
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
forwarding configuration
Definition: doca_flow.h:779
uint16_t port_id
Definition: doca_flow.h:795
enum doca_flow_fwd_type type
Definition: doca_flow.h:780
doca flow matcher information
Definition: doca_flow.h:491
struct doca_flow_parser_meta parser_meta
Definition: doca_flow.h:496
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
flow resource query
Definition: doca_flow.h:1101
struct doca_flow_resource_query::@115::@117 counter
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
char iface_name[DOCA_DEVINFO_IFACE_NAME_SIZE]
struct doca_flow_pipe * pipe
char pci_dev[DOCA_DEVINFO_PCI_ADDR_SIZE]
struct doca_flow_pipe_entry * udp_entry
struct doca_flow_pipe_entry * tcp_entry
struct doca_flow_port * port
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