NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
comch_ctrl_path_server_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 #include <stdlib.h>
27 
28 #include <doca_argp.h>
29 #include <doca_dev.h>
30 #include <doca_log.h>
31 
32 #include "comch_ctrl_path_common.h"
33 
34 #define DEFAULT_PCI_ADDR "03:00.0"
35 #define DEFAULT_REP_PCI_ADDR "b1:00.0"
36 #define DEFAULT_MESSAGE "Message from the client"
37 
38 DOCA_LOG_REGISTER(COMCH_CTRL_PATH_SERVER::MAIN);
39 
40 /* Sample's Logic */
42  const char *dev_pci_addr,
43  const char *rep_pci_addr,
44  const char *text,
45  const uint32_t text_size);
46 
47 /*
48  * Sample main function
49  *
50  * @argc [in]: Command line arguments size
51  * @argv [in]: Array of command line arguments
52  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
53  */
54 int main(int argc, char **argv)
55 {
56  struct comch_config cfg;
57  const char *server_name = "comch_ctrl_path_sample_server";
59  struct doca_log_backend *sdk_log;
60  int exit_status = EXIT_FAILURE;
61 
62  /* Set the default configuration values */
63  strcpy(cfg.comch_dev_pci_addr, DEFAULT_PCI_ADDR);
64  strcpy(cfg.comch_dev_rep_pci_addr, DEFAULT_REP_PCI_ADDR);
65  strcpy(cfg.text, DEFAULT_MESSAGE);
66  cfg.text_size = strlen(DEFAULT_MESSAGE);
67 
68  /* Register a logger backend */
70  if (result != DOCA_SUCCESS)
71  goto sample_exit;
72 
73  /* Register a logger backend for internal SDK errors and warnings */
75  if (result != DOCA_SUCCESS)
76  goto sample_exit;
78  if (result != DOCA_SUCCESS)
79  goto sample_exit;
80 
81  DOCA_LOG_INFO("Starting the sample");
82 
83  /* Parse cmdline/json arguments */
85  if (result != DOCA_SUCCESS) {
86  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
87  goto sample_exit;
88  }
89 
91  if (result != DOCA_SUCCESS) {
92  DOCA_LOG_ERR("Failed to register Comm Channel server sample parameters: %s",
94  goto argp_cleanup;
95  }
96 
97  result = doca_argp_start(argc, argv);
98  if (result != DOCA_SUCCESS) {
99  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
100  goto argp_cleanup;
101  }
102 
103  /* Start the server */
105  cfg.comch_dev_pci_addr,
106  cfg.comch_dev_rep_pci_addr,
107  cfg.text,
108  cfg.text_size);
109  if (result != DOCA_SUCCESS) {
110  DOCA_LOG_ERR("Failed to run the sample: %s", doca_error_get_descr(result));
111  goto argp_cleanup;
112  }
113 
114  exit_status = EXIT_SUCCESS;
115 
116 argp_cleanup:
118 sample_exit:
119  if (exit_status == EXIT_SUCCESS)
120  DOCA_LOG_INFO("Sample finished successfully");
121  else
122  DOCA_LOG_INFO("Sample finished with errors");
123  return exit_status;
124 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
doca_error_t register_comch_params(void)
#define DEFAULT_PCI_ADDR
int main(int argc, char **argv)
doca_error_t start_comch_ctrl_path_server_sample(const char *server_name, const char *dev_pci_addr, const char *rep_pci_addr, const char *text, const uint32_t text_size)
#define DEFAULT_REP_PCI_ADDR
#define DEFAULT_MESSAGE
DOCA_LOG_REGISTER(COMCH_CTRL_PATH_SERVER::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 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
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0