This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/src/packet_io/marsio_mode/pio_marsio.cpp
2022-07-28 15:12:46 +08:00

299 lines
14 KiB
C++

/*
**********************************************************************************************
* File: marsio.h
* Description: marsio runmode api
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-07-15
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
#include <dlfcn.h>
#include "pio_marsio.h"
#include "../packet_io.h"
#include "../../common/global_var.h"
#include "../../common/common.h"
#include "../../sdk/include/logger.h"
#include "../../sdk/include/util_errors.h"
static struct marsio_dll_function_entries shared_marsio_dll_func_entries;
static void fake_marsio_buff_set_rehash_index(marsio_buff_t *m, uint32_t hash)
{
return;
}
static int pio_get_marsio_dll_function_entries(void)
{
void *marsio_so_handle = dlopen(g_engine_instance.config.lib.libmarsio_path, RTLD_NOW | RTLD_LOCAL | RTLD_NODELETE);
if (nullptr == marsio_so_handle) {
printf("\033[1;31;40m[Error]dlopen '%s' failed, %s\033[0m\n", g_engine_instance.config.lib.libmarsio_path, dlerror());
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_create =
(struct mr_instance *(*)(void))dlsym(marsio_so_handle, "marsio_create");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_create) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_create", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_init =
(int (*)(struct mr_instance *, const char *))dlsym(marsio_so_handle, "marsio_init");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_init) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_init", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_destroy =
(int (*)(struct mr_instance *))dlsym(marsio_so_handle, "marsio_destory");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_destroy) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_destory", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_open_device =
(struct mr_vdev *(*)(struct mr_instance *, const char *, unsigned int, unsigned int))dlsym(marsio_so_handle, "marsio_open_device");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_open_device) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_open_device", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_close_device =
(void (*)(struct mr_vdev *))dlsym(marsio_so_handle, "marsio_close_device");
if (nullptr ==shared_marsio_dll_func_entries.ptr_marsio_close_device) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_close_device", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_option_set =
(int (*)(struct mr_instance *, marsio_opt_type_t, void *, size_t))dlsym(marsio_so_handle, "marsio_option_set");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_option_set) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_option_set", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_sendpath_create_by_vdev =
(struct mr_sendpath *(*)(struct mr_vdev *))dlsym(marsio_so_handle, "marsio_sendpath_create_by_vdev");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_sendpath_create_by_vdev) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_sendpath_create_by_vdev", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_sendpath_destroy =
(void (*)(struct mr_sendpath *))dlsym(marsio_so_handle, "marsio_sendpath_destory");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_sendpath_destroy) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_sendpath_destory", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_thread_init =
(int (*)(struct mr_instance *))dlsym(marsio_so_handle, "marsio_thread_init");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_thread_init) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_thread_init", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_recv_burst =
(int (*)(struct mr_vdev *, queue_id_t, marsio_buff_t **, int))dlsym(marsio_so_handle, "marsio_recv_burst");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_recv_burst) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_recv_burst", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_send_burst =
(int (*)(struct mr_sendpath *, queue_id_t, marsio_buff_t **, int))dlsym(marsio_so_handle, "marsio_send_burst");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_send_burst) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_send_burst", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_send_burst_with_options =
(int (*)(struct mr_sendpath *, queue_id_t, marsio_buff_t **, int, uint16_t))dlsym(marsio_so_handle, "marsio_send_burst_with_options");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_send_burst_with_options) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_send_burst_with_options", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_malloc_global =
(int (*)(struct mr_instance *, marsio_buff_t **, unsigned int, int, int))dlsym(marsio_so_handle, "marsio_buff_malloc_global");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_malloc_global) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_malloc_global", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_free =
(void (*)(struct mr_instance *, marsio_buff_t **,unsigned int, int, int))dlsym(marsio_so_handle, "marsio_buff_free");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_free) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_free", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_append =
(char * (*)(marsio_buff_t *, uint16_t))dlsym(marsio_so_handle, "marsio_buff_append");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_append) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_append", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_ctrlzone =
(void * (*)(marsio_buff_t *, uint8_t))dlsym(marsio_so_handle, "marsio_buff_ctrlzone");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_ctrlzone) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_ctrlzone", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_ctrlzone_set =
(void (*)(marsio_buff_t *, uint8_t, void *, uint8_t))dlsym(marsio_so_handle, "marsio_buff_ctrlzone_set");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_ctrlzone_set) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_ctrlzone_set", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_set_rehash_index =
(void (*)(marsio_buff_t *, uint32_t))dlsym(marsio_so_handle, "marsio_buff_set_rehash_index");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_set_rehash_index) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_set_rehash_index", g_engine_instance.config.lib.libmarsio_path);
shared_marsio_dll_func_entries.ptr_marsio_buff_set_rehash_index = fake_marsio_buff_set_rehash_index;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_mtod =
(char * (*)(marsio_buff_t *))dlsym(marsio_so_handle, "marsio_buff_mtod");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_mtod) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_mtod", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_datalen =
(uint32_t (*)(marsio_buff_t *))dlsym(marsio_so_handle, "marsio_buff_datalen");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_datalen) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_datalen", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_buflen =
(uint32_t (*)(marsio_buff_t *))dlsym(marsio_so_handle, "marsio_buff_buflen");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_buflen) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_buflen", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
shared_marsio_dll_func_entries.ptr_marsio_buff_clone_with_options =
(marsio_buff_t * (*)(struct mr_instance *, marsio_buff_t *, int, int, uint16_t))dlsym(marsio_so_handle, "marsio_buff_clone_with_options");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_clone_with_options) {
printf("\033[1;31;40m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_clone_with_options", g_engine_instance.config.lib.libmarsio_path);
return -1;
}
/* note: if not include marsio_send_burst_flush(), no errors. include just for backward compatibility */
shared_marsio_dll_func_entries.ptr_marsio_send_burst_flush =
(void (*)(struct mr_sendpath *, queue_id_t))dlsym(marsio_so_handle, "marsio_send_burst_flush");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_send_burst_flush) {
printf("\033[33m[Warning]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_send_burst_flush", g_engine_instance.config.lib.libmarsio_path);
}
/* for vlan flipping */
shared_marsio_dll_func_entries.ptr_marsio_buff_get_metadata =
(int (*)(marsio_buff_t *, enum mr_buff_metadata_type, void *, unsigned int))dlsym(marsio_so_handle, "marsio_buff_get_metadata");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_get_metadata) {
printf("\033[33m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_get_metadata", g_engine_instance.config.lib.libmarsio_path);
/* in order to be forward compatible with the previous version of mrzcpd, no error is returned here. vlan_flipping will become invalid */
}
shared_marsio_dll_func_entries.ptr_marsio_buff_set_metadata =
(int (*)(marsio_buff_t *, enum mr_buff_metadata_type, void *, unsigned int))dlsym(marsio_so_handle, "marsio_buff_set_metadata");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_get_metadata) {
printf("\033[33m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_set_metadata", g_engine_instance.config.lib.libmarsio_path);
/* in order to be forward compatible with the previous version of mrzcpd, no error is returned here. vlan_flipping will become invalid */
}
shared_marsio_dll_func_entries.ptr_marsio_buff_unset_metadata =
(int (*)(marsio_buff_t *, enum mr_buff_metadata_type))dlsym(marsio_so_handle, "marsio_buff_unset_metadata");
if (nullptr == shared_marsio_dll_func_entries.ptr_marsio_buff_unset_metadata) {
printf("\033[33m[Error]dlsym function '%s' from '%s' failed!\033[0m\n", "marsio_buff_unset_metadata", g_engine_instance.config.lib.libmarsio_path);
/* in order to be forward compatible with the previous version of mrzcpd, no error is returned here. vlan_flipping will become invalid */
}
return 0;
}
int pio_marsio_device_open(const void *init_data)
{
return 0;
}
int pio_marsio_device_close(const void *init_data)
{
return 0;
}
int pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet *p[], int nr_p)
{
return 0;
}
int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct packet *p[], int nr_p)
{
return 0;
}
static int marsio_instance_init(struct packet_io_instance *pinst, int worker_thread_num)
{
int ret = -1;
ret = pio_get_marsio_dll_function_entries();
if (ret < 0) {
printf("\033[1;31;40m[Error]dlopen marsio.so symbol failed!\033[0m\n");
return -1;
}
pinst->entity.ppio_marsio_inst->ptr_mr_inst = shared_marsio_dll_func_entries.ptr_marsio_create();
if (nullptr == pinst->entity.ppio_marsio_inst->ptr_mr_inst) {
fprintf(stderr,"%s\n","marsio_create error!\n");
return -1;
}
/* TODO: MARSIO_OPT_THREAD_NUM */
shared_marsio_dll_func_entries.ptr_marsio_option_set(pinst->entity.ppio_marsio_inst->ptr_mr_inst,
MARSIO_OPT_THREAD_NUM,
&worker_thread_num, sizeof(int));
/* TODO: MARSIO_OPT_THREAD_MASK_IN_CPUSET */
/* marsio_init */
ret = shared_marsio_dll_func_entries.ptr_marsio_init(pinst->entity.ppio_marsio_inst->ptr_mr_inst, pinst->inst_name);
if (ret < 0) {
fprintf(stderr,"%s\n","marsio_init error!\n");
return -1;
}
return 0;
}
/*
* @brief create packet_io marsio instance
*
* @param: pinst(in/out)
*/
int pio_marsio_instance_create(struct packet_io_instance *pinst, int worker_thread_num)
{
/* instance init */
int ret = marsio_instance_init(pinst, worker_thread_num);
if (ret < 0) {
log_error(ST_ERR_PIO_INSTANCE, "marsio instance init failed.");
return -1;
}
return 0;
}
void pio_marsio_instance_destroy(void)
{
}