NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_vxlan_encap_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 <stdlib.h>
27 
28 #include <doca_argp.h>
29 #include <doca_flow.h>
30 #include <doca_log.h>
31 
32 #include <dpdk_utils.h>
33 
34 DOCA_LOG_REGISTER(FLOW_VXLAN_ENCAP::MAIN);
35 
36 /* Sample's Logic */
37 doca_error_t flow_vxlan_encap(int nb_queues, enum doca_flow_tun_ext_vxlan_type vxlan_type);
38 
39 /*
40  * Config for vxlan_encap params
41  */
43  /* vxlan_type to create flow */
45 };
46 
47 /*
48  * Callback for arg vxlan-type
49  *
50  * @param [in]: parameter
51  * @config [in]: app dpdk config
52  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
53  */
54 static doca_error_t vxlan_type_callback(void *param, void *config)
55 {
56  struct vxlan_encap_config *app_config = (struct vxlan_encap_config *)config;
57  const char *str = (const char *)param;
58 
59  if (strcmp(str, "gbp") == 0)
61  else if (strcmp(str, "gpe") == 0)
63  else if (strcmp(str, "vxlan") == 0)
65  else {
66  DOCA_LOG_ERR("Unknown vxlan_type '%s' was specified", str);
68  }
69 
70  return DOCA_SUCCESS;
71 }
72 
73 /*
74  * Register for vxlan_encap params
75  *
76  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
77  */
79 {
81  struct doca_argp_param *vxlan_type_param;
82 
83  /* Create and register vxlan-type para */
84  result = doca_argp_param_create(&vxlan_type_param);
85  if (result != DOCA_SUCCESS) {
86  DOCA_LOG_ERR("Failed to create vxlan-type ARGP param: %s", doca_error_get_descr(result));
87  return result;
88  }
89 
90  doca_argp_param_set_short_name(vxlan_type_param, "type");
91  doca_argp_param_set_long_name(vxlan_type_param, "vxlan-type");
92  doca_argp_param_set_arguments(vxlan_type_param, "<vxlan-type>");
93  doca_argp_param_set_description(vxlan_type_param,
94  "Set vxlan-type (\"gpe\", \"gbp\", \"vxlan\") to create encap flows");
97  result = doca_argp_register_param(vxlan_type_param);
98  if (result != DOCA_SUCCESS) {
99  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
100  return result;
101  }
102 
103  return 0;
104 }
105 /*
106  * Sample main function
107  *
108  * @argc [in]: command line arguments size
109  * @argv [in]: array of command line arguments
110  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
111  */
112 int main(int argc, char **argv)
113 {
115  struct doca_log_backend *sdk_log;
116  int exit_status = EXIT_FAILURE;
117  struct application_dpdk_config dpdk_config = {
118  .port_config.nb_ports = 2,
119  .port_config.nb_queues = 4,
120  .port_config.nb_hairpin_q = 1,
121  .reserve_main_thread = true,
122  };
123  struct vxlan_encap_config app_cfg = {
124  .vxlan_type = DOCA_FLOW_TUN_EXT_VXLAN_STANDARD,
125  };
126 
127  /* Register a logger backend */
129  if (result != DOCA_SUCCESS)
130  goto sample_exit;
131 
132  /* Register a logger backend for internal SDK errors and warnings */
133  result = doca_log_backend_create_with_file_sdk(stderr, &sdk_log);
134  if (result != DOCA_SUCCESS)
135  goto sample_exit;
137  if (result != DOCA_SUCCESS)
138  goto sample_exit;
139 
140  DOCA_LOG_INFO("Starting the sample");
141 
143  if (result != DOCA_SUCCESS) {
144  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
145  goto sample_exit;
146  }
148  if (result != DOCA_SUCCESS) {
149  DOCA_LOG_ERR("Failed to register Flow parameters: %s", doca_error_get_descr(result));
150  goto argp_cleanup;
151  }
153  result = doca_argp_start(argc, argv);
154  if (result != DOCA_SUCCESS) {
155  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
156  goto argp_cleanup;
157  }
158 
159  /* update queues and ports */
160  result = dpdk_queues_and_ports_init(&dpdk_config);
161  if (result != DOCA_SUCCESS) {
162  DOCA_LOG_ERR("Failed to update ports and queues");
163  goto dpdk_cleanup;
164  }
165 
166  /* run sample */
167  result = flow_vxlan_encap(dpdk_config.port_config.nb_queues, app_cfg.vxlan_type);
168  if (result != DOCA_SUCCESS) {
169  DOCA_LOG_ERR("flow_vxlan_encap() encountered an error: %s", doca_error_get_descr(result));
170  goto dpdk_ports_queues_cleanup;
171  }
172 
173  exit_status = EXIT_SUCCESS;
174 
175 dpdk_ports_queues_cleanup:
176  dpdk_queues_and_ports_fini(&dpdk_config);
177 dpdk_cleanup:
178  dpdk_fini();
179 argp_cleanup:
181 sample_exit:
182  if (exit_status == EXIT_SUCCESS)
183  DOCA_LOG_INFO("Sample finished successfully");
184  else
185  DOCA_LOG_INFO("Sample finished with errors");
186  return exit_status;
187 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
if(bitoffset % 64+bitlength > 64) result|
doca_error_t dpdk_init(int argc, char **argv)
Definition: dpdk_utils.c:907
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 flow_vxlan_encap(int nb_queues, enum doca_flow_tun_ext_vxlan_type vxlan_type)
int main(int argc, char **argv)
DOCA_LOG_REGISTER(FLOW_VXLAN_ENCAP::MAIN)
static doca_error_t vxlan_type_callback(void *param, void *config)
static int register_vxlan_type_params(void)
static struct app_gpu_cfg app_cfg
DOCA_EXPERIMENTAL void doca_argp_param_set_description(struct doca_argp_param *param, const char *description)
Set the description of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_long_name(struct doca_argp_param *param, const char *name)
Set the long name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_start(int argc, char **argv)
Parse incoming arguments (cmd line/json).
DOCA_EXPERIMENTAL void doca_argp_param_set_arguments(struct doca_argp_param *param, const char *arguments)
Set the description of the expected arguments of the program param, used during program usage.
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 void doca_argp_param_set_callback(struct doca_argp_param *param, doca_argp_param_cb_t callback)
Set the callback function of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_param_create(struct doca_argp_param **param)
Create new program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_type(struct doca_argp_param *param, enum doca_argp_type type)
Set the type of the param arguments.
DOCA_EXPERIMENTAL void doca_argp_param_set_short_name(struct doca_argp_param *param, const char *name)
Set the short name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_destroy(void)
ARG Parser destroy.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_param(struct doca_argp_param *input_param)
Register a program flag.
@ DOCA_ARGP_TYPE_STRING
Definition: doca_argp.h:56
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_NOT_SUPPORTED
Definition: doca_error.h:42
@ DOCA_SUCCESS
Definition: doca_error.h:38
doca_flow_tun_ext_vxlan_type
doca flow tunnel extension vxlan type
@ DOCA_FLOW_TUN_EXT_VXLAN_STANDARD
@ DOCA_FLOW_TUN_EXT_VXLAN_GBP
@ DOCA_FLOW_TUN_EXT_VXLAN_GPE
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
enum doca_flow_tun_ext_vxlan_type vxlan_type