26 #include <arpa/inet.h>
44 #define SW_MAX_FILE_SIZE 128 * 1024 * 1024
45 #define SLEEP_IN_NANOS (10 * 1000)
46 #define DECOMPRESS_RATIO 1032
47 #define DEFAULT_TIMEOUT 10
74 DOCA_LOG_ERR(
"Failed to retrieve maximum buffer size allowed from DOCA compress device");
76 DOCA_LOG_DBG(
"DOCA compress device supports maximum buffer size of %" PRIu64
" bytes", *max_buf_size);
90 uint32_t max_bufs = 2;
117 uint64_t *max_buf_size)
128 DOCA_LOG_INFO(
"Failed to find device for compress task, running SW compress with zlib");
137 DOCA_LOG_ERR(
"Failed to retrieve DOCA compress device maximum buffer size: %s",
141 DOCA_LOG_ERR(
"Failed to destroy DOCA compress resources: %s",
176 struct doca_buf **dst_doca_buf)
198 DOCA_LOG_ERR(
"Unable to acquire DOCA buffer representing destination buffer: %s",
221 uint8_t *compressed_file,
222 size_t *compressed_file_len,
223 uint64_t *output_chksum)
225 struct doca_buf *dst_doca_buf;
226 struct doca_buf *src_doca_buf;
246 munmap(file_data, file_size);
258 DOCA_LOG_ERR(
"Unable to acquire DOCA buffer representing source buffer: %s",
314 Byte **compressed_file,
315 uLong *compressed_file_len)
320 memset(&c_stream, 0,
sizeof(c_stream));
322 c_stream.zalloc =
NULL;
323 c_stream.zfree =
NULL;
325 err = deflateInit2(&c_stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
327 DOCA_LOG_ERR(
"Failed to initialize compression system");
331 c_stream.next_in = (z_const
unsigned char *)file_data;
332 c_stream.next_out = *compressed_file;
334 c_stream.avail_in = file_size;
335 c_stream.avail_out = dst_buf_size;
336 err = deflate(&c_stream, Z_NO_FLUSH);
343 err = deflate(&c_stream, Z_FINISH);
344 if (err < 0 || err != Z_STREAM_END) {
349 err = deflateEnd(&c_stream);
354 *compressed_file_len = c_stream.total_out;
370 uint64_t result_checksum;
372 crc = crc32(0L, Z_NULL, 0);
373 crc = crc32(crc, (
const unsigned char *)file_data, file_size);
374 adler = adler32(0L, Z_NULL, 0);
375 adler = adler32(adler, (
const unsigned char *)file_data, file_size);
377 result_checksum = adler;
378 result_checksum <<= 32;
379 result_checksum += crc;
381 *output_chksum = result_checksum;
399 uint64_t max_buf_size,
402 uint8_t **compressed_file,
403 size_t *compressed_file_len,
404 uint64_t *output_chksum)
406 size_t dst_buf_size = 0;
411 dst_buf_size =
MAX(file_size + 16, file_size * 2);
412 if (dst_buf_size > max_buf_size)
413 dst_buf_size = max_buf_size;
417 *compressed_file = calloc(1, dst_buf_size);
418 if (*compressed_file ==
NULL) {
425 return compress_file_sw(file_data, file_size, dst_buf_size, compressed_file, compressed_file_len);
453 uint32_t max_comch_msg;
458 struct timespec ts = {
463 if (max_comch_msg == 0) {
469 total_msgs = (file_size + max_comch_msg - 1) / max_comch_msg;
470 file_meta.
num_segs = htonl(total_msgs);
480 for (i = 0; i < total_msgs; i++) {
485 msg_len =
MIN(file_size, max_comch_msg);
499 file_data += msg_len;
500 file_size -= msg_len;
506 uint8_t *recv_buffer,
508 struct doca_comch_connection *comch_connection)
516 recv_buffer[msg_len] =
'\0';
528 uint8_t *compressed_file;
529 size_t compressed_file_len;
532 struct timespec ts = {
542 if (fstat(fd, &statbuf) < 0) {
548 if (statbuf.st_size == 0 || (uint64_t)statbuf.st_size >
compress_cfg->max_compress_file_len) {
549 DOCA_LOG_ERR(
"Invalid file size. Should be greater then zero and smaller than %" PRIu64
" bytes",
555 file_data =
mmap(
NULL, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
556 if (file_data == MAP_FAILED) {
557 DOCA_LOG_ERR(
"Unable to map file content: %s", strerror(errno));
570 &compressed_file_len,
574 free(compressed_file);
578 DOCA_LOG_TRC(
"Compressed file size: %ld", compressed_file_len);
583 free(compressed_file);
586 free(compressed_file);
602 uint8_t *recv_buffer,
604 struct doca_comch_connection *comch_connection)
620 server_data = &
cfg->server_data;
627 DOCA_LOG_ERR(
"Unexpected file info message received. Size %u, expected size %lu",
641 DOCA_LOG_ERR(
"Received file exceeded maximum file size. Received length: %u, maximum size: %lu",
643 cfg->max_compress_file_len);
662 char finish_msg[] =
"Server was done receiving messages";
668 struct timespec ts = {
688 if (counter == num_of_iterations) {
689 DOCA_LOG_ERR(
"Message was not received at the given timeout");
715 DOCA_LOG_INFO(
"SUCCESS: file was received and decompressed successfully");
717 DOCA_LOG_ERR(
"ERROR: file checksum is different. received: 0x%lx, calculated: 0x%lx",
733 if ((
size_t)write(
fd, resp_head, data_len) != data_len) {
734 DOCA_LOG_ERR(
"Failed to write the decompressed into the input file");
824 char *pci_addr = (
char *)param;
827 DOCA_LOG_ERR(
"Entered device PCI address exceeding the maximum size of %d",
845 const char *rep_pci_addr = (
char *)param;
849 DOCA_LOG_ERR(
"Entered device representor PCI address exceeding the maximum size of %d",
873 DOCA_LOG_ERR(
"Timeout parameter must be positive value");
894 DOCA_LOG_ERR(
"Missing representor PCI address for server");
904 struct doca_argp_param *dev_pci_addr_param, *rep_pci_addr_param, *file_param, *timeout_param;
968 "Application timeout for receiving file content messages, default is 5 sec");
void * comch_utils_get_user_data(struct doca_comch_connection *connection)
doca_error_t comch_utils_progress_connection(struct doca_comch_connection *connection)
struct doca_comch_connection * comch_util_get_connection(struct comch_cfg *comch_cfg)
doca_error_t comch_utils_send(struct doca_comch_connection *connection, const void *msg, uint32_t len)
uint32_t comch_utils_get_max_buffer_size(struct comch_cfg *comch_cfg)
doca_error_t destroy_compress_resources(struct compress_resources *resources)
doca_error_t allocate_compress_resources(const char *pci_addr, uint32_t max_bufs, struct compress_resources *resources)
doca_error_t submit_decompress_deflate_task(struct compress_resources *resources, struct doca_buf *src_buf, struct doca_buf *dst_buf, uint64_t *output_checksum)
doca_error_t submit_compress_deflate_task(struct compress_resources *resources, struct doca_buf *src_buf, struct doca_buf *dst_buf, uint64_t *output_checksum)
@ COMPRESS_MODE_COMPRESS_DEFLATE
@ COMPRESS_MODE_DECOMPRESS_DEFLATE
static doca_error_t compress_file_hw(char *file_data, size_t file_size, size_t dst_buf_size, struct compress_resources *resources, uint8_t *compressed_file, size_t *compressed_file_len, uint64_t *output_chksum)
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)
static doca_error_t init_compress_resources(struct file_compression_config *compress_cfg, struct compress_resources *resources, enum file_compression_compress_method *method, uint64_t *max_buf_size)
static doca_error_t populate_dst_buf(struct program_core_objects *state, uint8_t *dst_buffer, size_t dst_buf_size, struct doca_buf **dst_doca_buf)
static doca_error_t rep_pci_addr_callback(void *param, void *config)
static doca_error_t get_compress_max_buf_size(struct compress_resources *resources, uint64_t *max_buf_size)
static void calculate_checksum_sw(char *file_data, size_t file_size, uint64_t *output_chksum)
doca_error_t file_compression_init(struct file_compression_config *compress_cfg, struct compress_resources *resources)
static doca_error_t timeout_callback(void *param, void *config)
DOCA_LOG_REGISTER(FILE_COMPRESSION::Core)
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)
static void unmap_cb(void *addr, size_t len, void *opaque)
static doca_error_t args_validation_callback(void *cfg)
static doca_error_t compress_file(char *file_data, size_t file_size, uint64_t max_buf_size, struct compress_resources *resources, enum file_compression_compress_method method, uint8_t **compressed_file, size_t *compressed_file_len, uint64_t *output_chksum)
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)
static doca_error_t dev_pci_addr_callback(void *param, void *config)
static doca_error_t compress_file_sw(char *file_data, size_t file_size, size_t dst_buf_size, Byte **compressed_file, uLong *compressed_file_len)
static doca_error_t file_callback(void *param, void *config)
static doca_error_t get_compress_resources(enum file_compression_mode mode, struct compress_resources *resources)
static doca_error_t send_file(struct file_compression_config *compress_cfg, struct comch_cfg *comch_cfg, char *file_data, size_t file_size, uint64_t checksum)
file_compression_compress_method
struct rdma_resources resources
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_validation_callback(doca_argp_validation_cb_t callback)
Register program validation callback function.
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 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 void doca_argp_param_set_mandatory(struct doca_argp_param *param)
Mark the program param as mandatory.
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 doca_error_t doca_argp_register_version_callback(doca_argp_param_cb_t callback)
Register an alternative version callback.
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_register_param(struct doca_argp_param *input_param)
Register a program flag.
static doca_error_t doca_buf_inventory_buf_get_by_addr(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *addr, size_t len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by addr & len argume...
DOCA_STABLE doca_error_t doca_buf_dec_refcount(struct doca_buf *buf, uint16_t *refcount)
Decrease the object reference count by 1, if 0 reached, return the element back to the inventory.
DOCA_STABLE doca_error_t doca_buf_get_data(const struct doca_buf *buf, void **data)
Get the buffer's data.
DOCA_STABLE doca_error_t doca_buf_get_data_len(const struct doca_buf *buf, size_t *data_len)
Get buffer's data length.
DOCA_STABLE doca_error_t doca_buf_set_data(struct doca_buf *buf, void *data, size_t data_len)
DOCA_EXPERIMENTAL doca_error_t doca_compress_cap_task_decompress_deflate_get_max_buf_size(const struct doca_devinfo *devinfo, uint64_t *max_buffer_size)
Get decompress deflate max size.
DOCA_EXPERIMENTAL doca_error_t doca_compress_cap_task_compress_deflate_get_max_buf_size(const struct doca_devinfo *devinfo, uint64_t *max_buffer_size)
Get compress deflate max size.
DOCA_STABLE doca_error_t doca_ctx_start(struct doca_ctx *ctx)
Finalizes all configurations, and starts the DOCA CTX.
#define DOCA_DEVINFO_REP_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
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_INVALID_VALUE
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
#define DOCA_LOG_TRC(format,...)
Generates a TRACE application log message.
#define DOCA_LOG_DBG(format,...)
Generates a DEBUG application log message.
DOCA_STABLE doca_error_t doca_mmap_set_memrange(struct doca_mmap *mmap, void *addr, size_t len)
Set the memory range of DOCA memory map.
DOCA_STABLE doca_error_t doca_mmap_start(struct doca_mmap *mmap)
Start DOCA Memory Map.
DOCA_STABLE doca_error_t doca_mmap_set_free_cb(struct doca_mmap *mmap, doca_mmap_memrange_free_cb_t *free_cb, void *opaque)
Set callback that will free the memory range when destroying DOCA memory map.
const struct ip_frag_config * cfg
uint64_t ntohq(uint64_t value)
char file_path[MAX_FILE_NAME]
char file_path[MAX_FILE_NAME]
struct doca_mmap * src_mmap
struct doca_buf_inventory * buf_inv
struct doca_mmap * dst_mmap
uint32_t received_file_length
uint64_t expected_checksum
uint32_t expected_file_chunks
uint32_t received_file_chunks
size_t strlcpy(char *dst, const char *src, size_t size)
noreturn doca_error_t sdk_version_callback(void *param, void *doca_config)