[PACKET_IO]format code style
This commit is contained in:
13
src/app.toml
13
src/app.toml
@@ -5,12 +5,15 @@ thread_num = 1
|
||||
[PACKET_IO]
|
||||
"""
|
||||
example1:
|
||||
|
||||
run_mode = pcap_live
|
||||
interface = [eth0, eth1]
|
||||
|
||||
example2:
|
||||
run_mode = marsio
|
||||
work_thread_num = 10 # Prompt marsio how many threads to start to receive packets
|
||||
interface = [eth0]
|
||||
|
||||
|
||||
"""
|
||||
run_mode = pcap_live # three mode: pcap_file/pcap_live/marsio
|
||||
interface = [eth0, eth1]
|
||||
example3:
|
||||
run_mode = pcap_file
|
||||
pcap_file_path = /tmp/pcapfile/001.pcap # if single file, specify dir+filename; if pcapfile directory, specify dir
|
||||
"""
|
||||
@@ -55,7 +55,7 @@ void packet_io_loop(struct packet_io_loop_arg *arg)
|
||||
struct packet_io_device *
|
||||
packet_io_init(const char *instance_name, const enum packet_io_run_mode mode, const int wrk_thread_num)
|
||||
{
|
||||
struct packet_io_instance *ppio_inst = packet_io_instance_create(instance_name, mode, wrk_thread_num);
|
||||
struct packet_io_instance *ppio_inst = packet_io_instance_create(instance_name, mode);
|
||||
if (nullptr == ppio_inst) {
|
||||
log_error(ST_ERR_PIO_INSTANCE, "packet_io instance init failed.");
|
||||
return nullptr;
|
||||
|
||||
@@ -283,7 +283,7 @@ int pio_marsio_device_open(struct packet_io_device *pdev)
|
||||
}
|
||||
|
||||
pdev->entity.marsio_dev_ctx->pio_dev = pdev;
|
||||
|
||||
|
||||
struct mr_instance *mr_inst_handle = pdev->ppio_inst->entity.marsio_inst_ctx->mr_inst_handle;
|
||||
/* marsio_open_device() return marsio device handle*/
|
||||
pdev->entity.marsio_dev_ctx->mr_dev_handle = \
|
||||
@@ -353,7 +353,7 @@ void pio_marsio_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, str
|
||||
g_marsio_dll_func.marsio_buff_free(mr_inst, (marsio_buff_t **)pkts, nr_pkts, MARSIO_SOCKET_ID_ANY, qid);
|
||||
}
|
||||
|
||||
static int marsio_instance_init(struct packet_io_instance *pinst, int wrk_thread_num)
|
||||
static int marsio_instance_init(struct packet_io_instance *pinst)
|
||||
{
|
||||
int ret = -1;
|
||||
ret = pio_get_marsio_dll_function_entries();
|
||||
@@ -368,6 +368,7 @@ static int marsio_instance_init(struct packet_io_instance *pinst, int wrk_thread
|
||||
return -1;
|
||||
}
|
||||
|
||||
int wrk_thread_num = g_engine_instance.config.packet_io.thread_num;
|
||||
/* TODO: MARSIO_OPT_THREAD_NUM */
|
||||
ret = g_marsio_dll_func.marsio_option_set(pinst->entity.marsio_inst_ctx->mr_inst_handle,
|
||||
MARSIO_OPT_THREAD_NUM,
|
||||
@@ -394,7 +395,7 @@ static int marsio_instance_init(struct packet_io_instance *pinst, int wrk_thread
|
||||
*
|
||||
* @param: pinst(in/out)
|
||||
*/
|
||||
int pio_marsio_instance_create(struct packet_io_instance *pinst, int wrk_thread_num)
|
||||
int pio_marsio_instance_create(struct packet_io_instance *pinst)
|
||||
{
|
||||
if (nullptr == pinst) {
|
||||
log_error(ST_ERR_PIO_MARSIO_INSTANCE, "invalid marsio instance pointer.");
|
||||
@@ -408,7 +409,7 @@ int pio_marsio_instance_create(struct packet_io_instance *pinst, int wrk_thread_
|
||||
}
|
||||
|
||||
/* instance init */
|
||||
int ret = marsio_instance_init(pinst, wrk_thread_num);
|
||||
int ret = marsio_instance_init(pinst);
|
||||
if (ret < 0) {
|
||||
log_error(ST_ERR_PIO_MARSIO_INSTANCE, "marsio instance init failed.");
|
||||
return -1;
|
||||
|
||||
@@ -83,7 +83,7 @@ struct pio_marsio_instance_context {
|
||||
};
|
||||
|
||||
/**
|
||||
* struct pio_marsio_device_context - marsio device context
|
||||
* @brief struct pio_marsio_device_context - marsio device context
|
||||
* @mr_dev_handle: marsio device handle
|
||||
* if marsio device receive packets, use mr_dev_handle
|
||||
* @mr_sendpath_handle: marsio sendpath handle
|
||||
@@ -96,6 +96,21 @@ struct pio_marsio_device_context {
|
||||
struct packet_io_device *pio_dev;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pinst
|
||||
* @return int
|
||||
*/
|
||||
int pio_marsio_instance_create(struct packet_io_instance *pinst);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pinst
|
||||
*/
|
||||
void pio_marsio_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
/**
|
||||
* @brief open marsio device
|
||||
*
|
||||
@@ -145,10 +160,6 @@ int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struc
|
||||
*/
|
||||
void pio_marsio_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
|
||||
|
||||
int pio_marsio_instance_create(struct packet_io_instance *pinst, int wrk_thread_num);
|
||||
|
||||
void pio_marsio_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
void *pio_marsio_device_buff_ctrlzone(struct packet *p);
|
||||
|
||||
char *pio_marsio_device_buff_mtod(struct packet *p);
|
||||
|
||||
@@ -72,17 +72,9 @@ struct pio_instance_operations pio_instance_ops_array[PACKET_IO_RUN_MODE_MAX] =
|
||||
};
|
||||
|
||||
struct packet_io_instance *
|
||||
packet_io_instance_create(const char *inst_name, const enum packet_io_run_mode mode, const int wrk_thread_num)
|
||||
packet_io_instance_create(const char *inst_name, const enum packet_io_run_mode mode)
|
||||
{
|
||||
if (nullptr == inst_name) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (mode < PACKET_IO_RUN_MODE_PCAP_FILE || mode >= PACKET_IO_RUN_MODE_MAX) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (wrk_thread_num < 0) {
|
||||
if (nullptr == inst_name || mode < PACKET_IO_RUN_MODE_PCAP_FILE || mode >= PACKET_IO_RUN_MODE_MAX) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -96,7 +88,7 @@ packet_io_instance_create(const char *inst_name, const enum packet_io_run_mode m
|
||||
pio_instance->mode = mode;
|
||||
pio_instance->inst_ops = &pio_instance_ops_array[mode];
|
||||
|
||||
int ret = pio_instance->inst_ops->create(pio_instance, wrk_thread_num);
|
||||
int ret = pio_instance->inst_ops->create(pio_instance);
|
||||
if (ret < 0) {
|
||||
log_error(ST_ERR_PIO_INSTANCE, "packet_io instance create failed.");
|
||||
return nullptr;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
**/
|
||||
|
||||
struct pio_instance_operations {
|
||||
int (*create)(struct packet_io_instance *pinst, int wrk_thread_num);
|
||||
int (*create)(struct packet_io_instance *pinst);
|
||||
|
||||
void (*destroy)(struct packet_io_instance *pinst);
|
||||
};
|
||||
@@ -104,11 +104,9 @@ struct packet_io_device {
|
||||
*
|
||||
* @param instance_name: packet_io instance name
|
||||
* @param mode: packet_io run mode
|
||||
* @param wrk_thread_num: expected number of packet receiving threads, which will be created by packet_io,
|
||||
* this param is useful only in marsio mode
|
||||
**/
|
||||
struct packet_io_instance *
|
||||
packet_io_instance_create(const char *instance_name, const enum packet_io_run_mode mode, const int wrk_thread_num);
|
||||
packet_io_instance_create(const char *instance_name, const enum packet_io_run_mode mode);
|
||||
|
||||
/* destroy packet_io instance */
|
||||
void packet_io_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
@@ -612,7 +612,7 @@ void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unu
|
||||
}
|
||||
}
|
||||
|
||||
int pio_pcap_file_instance_create(struct packet_io_instance *pinst, __unused int wrk_thread_num)
|
||||
int pio_pcap_file_instance_create(struct packet_io_instance *pinst)
|
||||
{
|
||||
if (nullptr == pinst) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_INSTANCE, "invalid pcap file instance pointer.");
|
||||
|
||||
@@ -97,6 +97,21 @@ struct pio_pcap_file_device_context {
|
||||
struct packet_io_device *pio_dev;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pinst
|
||||
* @return int
|
||||
*/
|
||||
int pio_pcap_file_instance_create(struct packet_io_instance *pinst);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pinst
|
||||
*/
|
||||
void pio_pcap_file_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
/**
|
||||
* @brief open pcap_file device
|
||||
*
|
||||
@@ -116,10 +131,6 @@ int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
|
||||
|
||||
void pio_pcap_file_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
|
||||
|
||||
int pio_pcap_file_instance_create(struct packet_io_instance *pinst, int wrk_thread_num);
|
||||
|
||||
void pio_pcap_file_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
void *pio_pcap_file_device_buff_ctrlzone(struct packet *p);
|
||||
|
||||
char *pio_pcap_file_device_buff_mtod(struct packet *p);
|
||||
|
||||
@@ -243,7 +243,7 @@ void pio_pcap_live_device_pkt_free(__unused struct packet_io_device *pdev, __unu
|
||||
}
|
||||
}
|
||||
|
||||
int pio_pcap_live_instance_create(struct packet_io_instance *pinst, __unused int wrk_thread_num)
|
||||
int pio_pcap_live_instance_create(struct packet_io_instance *pinst)
|
||||
{
|
||||
if (nullptr == pinst) {
|
||||
log_error(ST_ERR_PIO_PCAP_LIVE_INSTANCE, "invalid pcap live instance pointer.");
|
||||
|
||||
@@ -56,6 +56,22 @@ struct pio_pcap_live_device_context {
|
||||
struct packet_io_device *pio_dev;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pinst
|
||||
* @param wrk_thread_num
|
||||
* @return int
|
||||
*/
|
||||
int pio_pcap_live_instance_create(struct packet_io_instance *pinst);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param pinst
|
||||
*/
|
||||
void pio_pcap_live_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
/**
|
||||
* @brief open pcap_live device
|
||||
*
|
||||
@@ -77,10 +93,6 @@ int pio_pcap_live_device_send(struct packet_io_device *pdev, uint32_t txq_id, st
|
||||
|
||||
void pio_pcap_live_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
|
||||
|
||||
int pio_pcap_live_instance_create(struct packet_io_instance *pinst, int wrk_thread_num);
|
||||
|
||||
void pio_pcap_live_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
void *pio_pcap_live_device_buff_ctrlzone(struct packet *p);
|
||||
|
||||
char *pio_pcap_live_device_buff_mtod(struct packet *p);
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
TEST(PACKET_IO_Test, packet_io_instance_create) {
|
||||
struct packet_io_config ppio_config;
|
||||
struct packet_io_instance *ppio_inst = packet_io_instance_create("stellar", PACKET_IO_RUN_MODE_PCAP_FILE, 2);
|
||||
struct packet_io_instance *ppio_inst = packet_io_instance_create("stellar", PACKET_IO_RUN_MODE_PCAP_FILE);
|
||||
EXPECT_NE(ppio_inst, nullptr);
|
||||
}
|
||||
|
||||
TEST(PACKET_IO_Test, packet_io_open_device) {
|
||||
struct packet_io_config ppio_config;
|
||||
struct packet_io_instance *ppio_inst = packet_io_instance_create("stellar", PACKET_IO_RUN_MODE_PCAP_FILE, 2);
|
||||
struct packet_io_instance *ppio_inst = packet_io_instance_create("stellar", PACKET_IO_RUN_MODE_PCAP_FILE);
|
||||
EXPECT_EQ(packet_io_device_open(ppio_inst, nullptr, 1, 1), nullptr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user