NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
rmax_create_stream_hds_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-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 <doca_log.h>
27 #include <doca_rmax.h>
28 
29 #include "rmax_common.h"
30 #include "common.h"
31 
32 DOCA_LOG_REGISTER(RMAX_CREATE_STREAM_HDS::MAIN);
33 
34 /* Sample's logic */
35 doca_error_t rmax_create_stream_hds(struct rmax_program_state *state, struct rmax_stream_config *stream_config);
36 
37 /*
38  * Initialize default configurations; stream and flow configurations that should be used when setting their attributes
39  *
40  * @config [out]: all needed configuration that should be set.
41  */
42 static void init_config(struct rmax_stream_config *config)
43 {
44  config->scatter_all = false;
45  config->src_ip.s_addr = 0;
46  config->dst_ip.s_addr = 0;
47  config->dst_port = 5200;
48  config->hdr_size = 8;
49  config->data_size = 150;
50  config->num_elements = 1024;
51 
52  strcpy(config->pci_address, "03:00.0");
53 }
54 
55 /*
56  * Sample main function
57  *
58  * @argc [in]: command line arguments size
59  * @argv [in]: array of command line arguments
60  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
61  */
62 int main(int argc, char **argv)
63 {
65  struct doca_log_backend *sdk_log;
66  int exit_status = EXIT_FAILURE;
67  struct rmax_program_state state;
68  struct rmax_stream_config stream_config;
69 
70  /* Register a logger backend */
72  if (result != DOCA_SUCCESS)
73  goto sample_exit;
74 
75  /* Register a logger backend for internal SDK errors and warnings */
77  if (result != DOCA_SUCCESS)
78  goto sample_exit;
80  if (result != DOCA_SUCCESS)
81  goto sample_exit;
82 
83  DOCA_LOG_INFO("Starting the sample");
84 
85  /* default configurations */
86  init_config(&stream_config);
87 
88  /* ARGP initialization */
89  result = doca_argp_init(NULL, &stream_config);
90  if (result != DOCA_SUCCESS) {
91  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
92  goto sample_exit;
93  }
94 
95  /* register ARGP parameters of the sample */
97  if (result != DOCA_SUCCESS) {
98  DOCA_LOG_ERR("Failed to register ARGP params: %s", doca_error_get_descr(result));
99  goto argp_cleanup;
100  }
101 
102  /* start parsing received arguments */
103  result = doca_argp_start(argc, argv);
104  if (result != DOCA_SUCCESS) {
105  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
106  goto argp_cleanup;
107  }
108 
109  /* Sample's main logic */
110  result = rmax_create_stream_hds(&state, &stream_config);
111  if (result != DOCA_SUCCESS) {
112  DOCA_LOG_ERR("rmax_create_stream_hds() encountered an error: %s", doca_error_get_descr(result));
113  goto argp_cleanup;
114  }
115 
116  exit_status = EXIT_SUCCESS;
117 
118 argp_cleanup:
120 sample_exit:
121  if (exit_status == EXIT_SUCCESS)
122  DOCA_LOG_INFO("Sample finished successfully");
123  else
124  DOCA_LOG_INFO("Sample finished with errors");
125  return exit_status;
126 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
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 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
doca_error_t register_create_stream_params(void)
Definition: rmax_common.c:116
doca_error_t rmax_create_stream_hds(struct rmax_program_state *state, struct rmax_stream_config *stream_config)
int main(int argc, char **argv)
static void init_config(struct rmax_stream_config *config)
DOCA_LOG_REGISTER(RMAX_CREATE_STREAM_HDS::MAIN)
struct in_addr dst_ip
Definition: rmax_common.h:61
uint16_t data_size
Definition: rmax_common.h:57
uint32_t num_elements
Definition: rmax_common.h:58
char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: rmax_common.h:52
struct in_addr src_ip
Definition: rmax_common.h:62