NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_ecmp_main.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 <stdint.h>
27 #include <stdlib.h>
28 
29 #include <rte_ethdev.h>
30 
31 #include <doca_argp.h>
32 #include <doca_flow.h>
33 #include <doca_log.h>
34 
35 #include <dpdk_utils.h>
36 
37 #include "flow_switch_common.h"
38 
39 DOCA_LOG_REGISTER(FLOW_ECMP::MAIN);
40 
41 /* Sample's Logic */
42 doca_error_t flow_ecmp(int nb_queues, int nb_ports, struct flow_switch_ctx *ctx);
43 
44 /*
45  * Sample main function
46  *
47  * @argc [in]: command line arguments size
48  * @argv [in]: array of command line arguments
49  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
50  */
51 int main(int argc, char **argv)
52 {
54  struct doca_log_backend *sdk_log;
55  int exit_status = EXIT_FAILURE;
56  struct application_dpdk_config dpdk_config = {
58  .port_config.isolated_mode = 1,
59  .port_config.switch_mode = 1,
60  };
61  struct flow_switch_ctx ctx = {0};
62  uint8_t nb_ports;
63 
64  /* Register a logger backend */
66  if (result != DOCA_SUCCESS)
67  goto sample_exit;
68 
69  /* Register a logger backend for internal SDK errors and warnings */
71  if (result != DOCA_SUCCESS)
72  goto sample_exit;
74  if (result != DOCA_SUCCESS)
75  goto sample_exit;
76 
77  DOCA_LOG_INFO("Starting the sample");
78 
80  if (result != DOCA_SUCCESS) {
81  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
82  goto sample_exit;
83  }
85  if (result != DOCA_SUCCESS) {
86  DOCA_LOG_ERR("Failed to register flow param: %s", doca_error_get_descr(result));
87  goto argp_cleanup;
88  }
90  result = doca_argp_start(argc, argv);
91  if (result != DOCA_SUCCESS) {
92  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
93  goto argp_cleanup;
94  }
95 
97  if (result != DOCA_SUCCESS) {
98  DOCA_LOG_ERR("Failed to init flow switch common: %s", doca_error_get_descr(result));
99  goto dpdk_cleanup;
100  }
101 
103  DOCA_LOG_INFO("Number of DPDK ports is %u, E-switch manager and %u SF representors", nb_ports, nb_ports - 1);
104  dpdk_config.port_config.nb_ports = nb_ports;
105 
106  /* update queues and ports */
107  result = dpdk_queues_and_ports_init(&dpdk_config);
108  if (result != DOCA_SUCCESS) {
109  DOCA_LOG_ERR("Failed to update ports and queues: %s", doca_error_get_descr(result));
110  goto dpdk_cleanup;
111  }
112 
113  /* run sample */
114  result = flow_ecmp(dpdk_config.port_config.nb_queues, dpdk_config.port_config.nb_ports, &ctx);
115  if (result != DOCA_SUCCESS) {
116  DOCA_LOG_ERR("flow_ecmp() encountered an error: %s", doca_error_get_descr(result));
117  goto dpdk_ports_queues_cleanup;
118  }
119 
120  exit_status = EXIT_SUCCESS;
121 
122 dpdk_ports_queues_cleanup:
123  dpdk_queues_and_ports_fini(&dpdk_config);
124 dpdk_cleanup:
125  dpdk_fini();
126 argp_cleanup:
128 sample_exit:
130  if (exit_status == EXIT_SUCCESS)
131  DOCA_LOG_INFO("Sample finished successfully");
132  else
133  DOCA_LOG_INFO("Sample finished with errors");
134  return exit_status;
135 }
#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
int main(int argc, char **argv)
DOCA_LOG_REGISTER(FLOW_ECMP::MAIN)
doca_error_t flow_ecmp(int nb_queues, int nb_ports, struct flow_switch_ctx *ctx)
doca_error_t init_doca_flow_switch_common(struct flow_switch_ctx *ctx)
uint8_t get_dpdk_nb_ports(void)
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)
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