NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
file_compression_core.h
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 #ifndef FILE_COMPRESSION_CORE_H_
27 #define FILE_COMPRESSION_CORE_H_
28 
29 #include <doca_buf.h>
30 #include <doca_buf_inventory.h>
31 #include <doca_ctx.h>
32 #include <doca_compress.h>
33 
34 #include "comch_utils.h"
35 
36 #include <samples/common.h>
38 
39 /* File compression running mode */
41  NO_VALID_INPUT = 0, /* CLI argument is not valid */
42  CLIENT, /* Run app as client */
43  SERVER /* Run app as server */
44 };
45 
46 /* File compression compress method */
48  COMPRESS_DEFLATE_HW, /* Compress file using DOCA Compress library */
49  COMPRESS_DEFLATE_SW /* Compress file using zlib */
50 };
51 
52 /* State of the file transfer on the doca comch control path */
54  TRANSFER_IDLE, /* No transfer has started */
55  TRANSFER_IN_PROGRESS, /* File transfer is under way */
56  TRANSFER_COMPLETE, /* File transfer is complete */
57  TRANSFER_ERROR /* An error was detected in file transfer */,
58 };
59 
61  uint64_t expected_checksum; /* Expected checksum of transferred file */
62  uint32_t expected_file_chunks; /* Number of chunks file should be sent in */
63  uint32_t received_file_chunks; /* Current number of chunks received */
64  uint32_t received_file_length; /* Current length of file data received */
65  char *compressed_file; /* File received on server */
66 };
67 
68 /* File compression configuration struct */
70  enum file_compression_mode mode; /* Application mode */
71  char file_path[MAX_FILE_NAME]; /* Input file path */
72  char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* Comm Channel DOCA device PCI address */
73  char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]; /* Comm Channel DOCA device representor PCI address */
74  int timeout; /* Application timeout in seconds */
75  enum file_compression_compress_method compress_method; /* Whether to run compress with HW or SW */
76  uint64_t max_compress_file_len; /* Max supported length of compress file */
77  struct server_runtime_data server_data; /* Data populated on server side during file transmission */
78  enum transfer_state state; /* Indicator of completion of a file transfer */
79 };
80 
81 /*
82  * Initialize application resources
83  *
84  * @compress_cfg [in]: application config struct
85  * @resources [out]: DOCA compress resources pointer
86  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
87  */
89 
90 /*
91  * Clean all application resources
92  *
93  * @compress_cfg [in]: application config struct
94  * @resources [in]: DOCA compress resources pointer
95  */
97 
98 /*
99  * Run client logic
100  *
101  * @comch_cfg [in]: comch object to use for control messages
102  * @compress_cfg [in]: application config struct
103  * @resources [in]: DOCA compress resources pointer
104  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
105  */
108  struct compress_resources *resources);
109 
110 /*
111  * Run server logic
112  *
113  * @comch_cfg [in]: comch object to use for control messages
114  * @compress_cfg [in]: application config struct
115  * @resources [in]: DOCA compress resources pointer
116  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
117  */
120  struct compress_resources *resources);
121 
122 /*
123  * Register the command line parameters for the application
124  *
125  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
126  */
128 
129 /*
130  * Callback event for client messages
131  *
132  * @event [in]: message receive event
133  * @recv_buffer [in]: array of bytes containing the message data
134  * @msg_len [in]: number of bytes in the recv_buffer
135  * @comch_connection [in]: comm channel connection over which the event occurred
136  */
137 void client_recv_event_cb(struct doca_comch_event_msg_recv *event,
138  uint8_t *recv_buffer,
139  uint32_t msg_len,
140  struct doca_comch_connection *comch_connection);
141 
142 /*
143  * Callback event for server messages
144  *
145  * @event [in]: message receive event
146  * @recv_buffer [in]: array of bytes containing the message data
147  * @msg_len [in]: number of bytes in the recv_buffer
148  * @comch_connection [in]: comm channel connection over which the event occurred
149  */
150 void server_recv_event_cb(struct doca_comch_event_msg_recv *event,
151  uint8_t *recv_buffer,
152  uint32_t msg_len,
153  struct doca_comch_connection *comch_connection);
154 #endif /* FILE_COMPRESSION_CORE_H_ */
doca_error_t register_file_compression_params(void)
doca_error_t file_compression_client(struct comch_cfg *comch_cfg, struct file_compression_config *compress_cfg, struct compress_resources *resources)
doca_error_t file_compression_init(struct file_compression_config *compress_cfg, struct compress_resources *resources)
void server_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
void client_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
@ TRANSFER_ERROR
@ TRANSFER_COMPLETE
@ TRANSFER_IN_PROGRESS
@ TRANSFER_IDLE
void file_compression_cleanup(struct file_compression_config *compress_cfg, struct compress_resources *resources)
doca_error_t file_compression_server(struct comch_cfg *comch_cfg, struct file_compression_config *compress_cfg, struct compress_resources *resources)
file_compression_mode
@ NO_VALID_INPUT
file_compression_compress_method
@ COMPRESS_DEFLATE_SW
@ COMPRESS_DEFLATE_HW
#define MAX_FILE_NAME
struct rdma_resources resources
#define DOCA_DEVINFO_REP_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:665
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
enum doca_error doca_error_t
DOCA API return codes.
char cc_dev_pci_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
char cc_dev_rep_pci_addr[DOCA_DEVINFO_REP_PCI_ADDR_SIZE]
char file_path[MAX_FILE_NAME]
struct server_runtime_data server_data
enum file_compression_mode mode
enum file_compression_compress_method compress_method