NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_switch_to_wire_main.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 /*
27  * The application is to verify the unified switch model traffic.
28  * It can be used to verify the traffic from wire to wire, wire to
29  * vf and vf to vf.
30  * User can use different packets to verify different directions of
31  * traffic. The incoming traffic can be from wire or vf. It steers
32  * the pkt based on the pkt content, so user can send the traffic
33  * from different src and check if the pkt goes to the expected
34  * destinations.
35  * As this sample add the RSS pipe, so doca-flow isolated mode
36  * is chosen without any internal RSS pipes.
37  * In expert mode, the missed traffic will be tagged with port_id
38  * and the traffic will be sent to egress root.
39  *
40  * It requires 4 ports. It builds the pipe entries as below:
41  *
42  * Ingress pipe:
43  * Entry 0: IP src 1.2.3.4 / TCP src 1234 dst 80 -> egress pipe
44  * Entry 1: IP src 1.2.3.5 / TCP src 1234 dst 80 -> vport pipe
45  *
46  * Egress pipe(test ingress to egress cross domain):
47  * Entry 0: IP dst 8.8.8.8 / TCP src 1234 dst 80 -> port 0
48  * Entry 1: IP dst 8.8.8.9 / TCP src 1234 dst 80 -> port 1
49  * Entry 2: IP dst 8.8.8.10 / TCP src 1234 dst 80 -> port 2
50  *
51  * Vport pipe(test ingress direct to vport):
52  * Entry 0: IP dst 8.8.8.8 / TCP src 1234 -> port 0
53  * Entry 1: IP dst 8.8.8.9 / TCP src 1234 -> port 1
54  * Entry 2: IP dst 8.8.8.10 / TCP src 1234-> port 2
55  *
56  * RSS pipe(test miss traffic port_id get and dst port_id set):
57  * Entry 0: IPv4 / TCP -> port 0
58  * Entry 0: IPv4 / UDP -> port 1
59  * Entry 0: IPv4 / ICMP -> port 2
60  */
61 #include <stdlib.h>
62 
63 #include <rte_ethdev.h>
64 
65 #include <doca_argp.h>
66 #include <doca_dev.h>
67 #include <doca_flow.h>
68 #include <doca_log.h>
69 #include <doca_ctx.h>
70 
71 #include <dpdk_utils.h>
72 
73 #include "flow_switch_common.h"
74 
75 DOCA_LOG_REGISTER(FLOW_SWITCH_TO_WIRE::MAIN);
76 
77 #define SWITCH_TO_WIRE_PORTS 3
78 
79 /* Sample's Logic */
80 doca_error_t flow_switch_to_wire(int nb_queues, int nb_ports, struct flow_switch_ctx *ctx);
81 
82 /*
83  * Sample main function
84  *
85  * @argc [in]: command line arguments size
86  * @argv [in]: array of command line arguments
87  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
88  */
89 int main(int argc, char **argv)
90 {
92  struct doca_log_backend *sdk_log;
93  int exit_status = EXIT_FAILURE;
94  struct application_dpdk_config dpdk_config = {
96  .port_config.nb_queues = 1,
97  .port_config.isolated_mode = 1,
98  .port_config.switch_mode = 1,
99  };
100  struct flow_switch_ctx ctx = {0};
101  uint16_t nr_ports;
102 
103  /* Register a logger backend */
105  if (result != DOCA_SUCCESS)
106  goto sample_exit;
107 
108  /* Register a logger backend for internal SDK errors and warnings */
109  result = doca_log_backend_create_with_file_sdk(stderr, &sdk_log);
110  if (result != DOCA_SUCCESS)
111  goto sample_exit;
113  if (result != DOCA_SUCCESS)
114  goto sample_exit;
115 
117  if (result != DOCA_SUCCESS) {
118  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
119  goto sample_exit;
120  }
122  if (result != DOCA_SUCCESS) {
123  DOCA_LOG_ERR("Failed to register flow param: %s", doca_error_get_descr(result));
124  goto argp_cleanup;
125  }
127  result = doca_argp_start(argc, argv);
128  if (result != DOCA_SUCCESS) {
129  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
130  goto argp_cleanup;
131  }
132 
134  if (result != DOCA_SUCCESS) {
135  DOCA_LOG_ERR("Failed to init flow switch common: %s", doca_error_get_descr(result));
136  goto dpdk_cleanup;
137  }
138 
139  nr_ports = rte_eth_dev_count_avail();
140  if (nr_ports < SWITCH_TO_WIRE_PORTS) {
141  DOCA_LOG_ERR("Failed to init - lack of ports, probed:%d, needed:%d", nr_ports, SWITCH_TO_WIRE_PORTS);
142  goto sample_exit;
143  }
144 
145  /* update queues and ports */
146  result = dpdk_queues_and_ports_init(&dpdk_config);
147  if (result != DOCA_SUCCESS) {
148  DOCA_LOG_ERR("Failed to update ports and queues");
149  goto dpdk_cleanup;
150  }
151 
152  /* run sample */
154  if (result != DOCA_SUCCESS) {
155  DOCA_LOG_ERR("flow_switch_to_wire() encountered an error: %s", doca_error_get_descr(result));
156  goto dpdk_ports_queues_cleanup;
157  }
158 
159  exit_status = EXIT_SUCCESS;
160 
161 dpdk_ports_queues_cleanup:
162  dpdk_queues_and_ports_fini(&dpdk_config);
163 dpdk_cleanup:
164  dpdk_fini();
165 argp_cleanup:
167 sample_exit:
169  if (exit_status == EXIT_SUCCESS)
170  DOCA_LOG_INFO("Sample finished successfully");
171  else
172  DOCA_LOG_INFO("Sample finished with errors");
173  return exit_status;
174 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
void dpdk_fini(void)
Definition: dpdk_utils.c:919
doca_error_t dpdk_queues_and_ports_init(struct application_dpdk_config *app_dpdk_config)
Definition: dpdk_utils.c:515
void dpdk_queues_and_ports_fini(struct application_dpdk_config *app_dpdk_config)
Definition: dpdk_utils.c:564
doca_error_t init_doca_flow_switch_common(struct flow_switch_ctx *ctx)
void destroy_doca_flow_switch_common(struct flow_switch_ctx *ctx)
doca_error_t register_doca_flow_switch_param(void)
doca_error_t init_flow_switch_dpdk(int argc, char **dpdk_argv)
int main(int argc, char **argv)
doca_error_t flow_switch_to_wire(int nb_queues, int nb_ports, struct flow_switch_ctx *ctx)
#define SWITCH_TO_WIRE_PORTS
DOCA_LOG_REGISTER(FLOW_SWITCH_TO_WIRE::MAIN)
DOCA_EXPERIMENTAL doca_error_t doca_argp_start(int argc, char **argv)
Parse incoming arguments (cmd line/json).
DOCA_EXPERIMENTAL doca_error_t doca_argp_init(const char *program_name, void *program_config)
Initialize the parser interface.
DOCA_EXPERIMENTAL void doca_argp_set_dpdk_program(doca_argp_dpdk_cb_t callback)
Mark the program as based on DPDK API.
DOCA_EXPERIMENTAL doca_error_t doca_argp_destroy(void)
ARG Parser destroy.
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_SUCCESS
Definition: doca_error.h:38
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_standard(void)
Create default, non configurable backend for application messages.
#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
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_with_file_sdk(FILE *fptr, struct doca_log_backend **backend)
Create a logging backend with a FILE* stream for SDK messages.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_set_sdk_level(struct doca_log_backend *backend, uint32_t level)
Set the log level limit for SDK logging backends.
@ DOCA_LOG_LEVEL_WARNING
Definition: doca_log.h:47
struct application_port_config port_config
Definition: dpdk_utils.h:70
static int nb_ports
Definition: switch_core.c:44
struct upf_accel_ctx * ctx