Merge branch develop-0.0

This commit is contained in:
liuwentan
2022-08-11 09:38:38 +08:00
87 changed files with 9132 additions and 522 deletions

View File

@@ -319,7 +319,7 @@ int pio_marsio_device_close(struct packet_io_device *pdev)
return 0;
}
int pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts)
int pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts)
{
struct mr_vdev *mr_dev_handle = pdev->entity.marsio_dev_ctx->mr_dev_handle;
marsio_buff_t *rx_buff[MARSIO_BURST_PKT_MAX];
@@ -328,14 +328,14 @@ int pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, st
/* receive some pkts, copy mbuf pointer to packet structure */
if (recv_res > 0) {
for (int i = 0; i < recv_res; i++) {
pkts[i]= (struct packet *)rx_buff[i];
pkts[i]= (struct stellar_packet *)rx_buff[i];
}
}
return recv_res;
}
int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts)
int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, int nr_pkts)
{
struct mr_sendpath *sendpath_handle = pdev->entity.marsio_dev_ctx->mr_sendpath_handle;
int ret = g_marsio_dll_func.marsio_send_burst(sendpath_handle, txq_id, (marsio_buff_t **)pkts, nr_pkts);
@@ -347,7 +347,7 @@ int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struc
return ret;
}
void pio_marsio_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts)
void pio_marsio_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, int nr_pkts)
{
struct mr_instance *mr_inst = pdev->ppio_inst->entity.marsio_inst_ctx->mr_inst_handle;
g_marsio_dll_func.marsio_buff_free(mr_inst, (marsio_buff_t **)pkts, nr_pkts, MARSIO_SOCKET_ID_ANY, qid);
@@ -424,24 +424,24 @@ void pio_marsio_instance_destroy(struct packet_io_instance *pinst)
}
}
void *pio_marsio_device_buff_ctrlzone(struct packet *p)
void *pio_marsio_device_buff_ctrlzone(struct stellar_packet *p)
{
int zone_id = 0;
return g_marsio_dll_func.marsio_buff_ctrlzone((marsio_buff_t *)p, zone_id);
}
char *pio_marsio_device_buff_mtod(struct packet *p)
char *pio_marsio_device_buff_mtod(struct stellar_packet *p)
{
return g_marsio_dll_func.marsio_buff_mtod((marsio_buff_t *)p);
}
uint32_t pio_marsio_device_buff_buflen(struct packet *p)
uint32_t pio_marsio_device_buff_buflen(struct stellar_packet *p)
{
return g_marsio_dll_func.marsio_buff_buflen((marsio_buff_t *)p);
}
uint32_t pio_marsio_device_buff_datalen(struct packet *p)
uint32_t pio_marsio_device_buff_datalen(struct stellar_packet *p)
{
return g_marsio_dll_func.marsio_buff_datalen((marsio_buff_t *)p);
}
}

View File

@@ -136,7 +136,7 @@ int pio_marsio_device_close(struct packet_io_device *pdev);
*
* @retval number of packets actually received
*/
int pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts);
int pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts);
/**
* @brief send packets by device's single tx queue which specified by txq_id
@@ -148,7 +148,7 @@ int pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, st
*
* @retval if ret<0, means the sending fails; if ret==0 means the sending succeeds
*/
int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts);
int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, int nr_pkts);
/**
* @brief manually free packet's memory
@@ -158,12 +158,12 @@ int pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struc
* @param pkts:
* @param nr_pkts:
*/
void pio_marsio_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
void pio_marsio_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, int nr_pkts);
void *pio_marsio_device_buff_ctrlzone(struct packet *p);
void *pio_marsio_device_buff_ctrlzone(struct stellar_packet *p);
char *pio_marsio_device_buff_mtod(struct packet *p);
char *pio_marsio_device_buff_mtod(struct stellar_packet *p);
uint32_t pio_marsio_device_buff_buflen(struct packet *p);
uint32_t pio_marsio_device_buff_buflen(struct stellar_packet *p);
uint32_t pio_marsio_device_buff_datalen(struct packet *p);
uint32_t pio_marsio_device_buff_datalen(struct stellar_packet *p);

View File

@@ -84,11 +84,16 @@ packet_io_instance_create(const char *inst_name, const enum packet_io_run_mode m
return nullptr;
}
strncpy(pio_instance->inst_name, inst_name, strlen(inst_name));
int ret = strncpy_safe(pio_instance->inst_name, inst_name, sizeof(pio_instance->inst_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "packet_io instance name copy failed.");
return nullptr;
}
pio_instance->mode = mode;
pio_instance->inst_ops = &pio_instance_ops_array[mode];
int ret = pio_instance->inst_ops->create(pio_instance);
ret = pio_instance->inst_ops->create(pio_instance);
if (ret < 0) {
log_error(ST_ERR_PIO_INSTANCE, "packet_io instance create failed.");
return nullptr;
@@ -115,7 +120,12 @@ packet_io_device_open(struct packet_io_instance *pinst, const char *dev_name, ui
return nullptr;
}
strncpy(ppio_dev->dev_name, dev_name, strlen(dev_name));
int ret = strncpy_safe(ppio_dev->dev_name, dev_name, sizeof(ppio_dev->dev_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "packet_io device name copy failed.");
return nullptr;
}
ppio_dev->rxq_num = nr_rxq;
ppio_dev->txq_num = nr_txq;
ppio_dev->ppio_inst = pinst;
@@ -127,7 +137,7 @@ packet_io_device_open(struct packet_io_instance *pinst, const char *dev_name, ui
**/
pinst->devices[pinst->dev_cnt++] = ppio_dev;
int ret = ppio_dev->dev_ops->open(ppio_dev);
ret = ppio_dev->dev_ops->open(ppio_dev);
if (ret < 0) {
log_error(ST_ERR_PIO_DEVICE, "packet_io device open failed.");
FREE(ppio_dev);
@@ -156,37 +166,37 @@ void packet_io_device_close(struct packet_io_device *pdev)
FREE(pdev);
}
int packet_io_device_rx(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts)
int packet_io_device_rx(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts)
{
return pdev->dev_ops->recv(pdev, rxq_id, pkts, nr_pkts);
}
int packet_io_device_tx(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts)
int packet_io_device_tx(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, int nr_pkts)
{
return pdev->dev_ops->send(pdev, txq_id, pkts, nr_pkts);
}
void packet_io_pkts_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts)
void packet_io_pkts_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, int nr_pkts)
{
return pdev->dev_ops->pkt_free(pdev, qid, pkts, nr_pkts);
}
void *packet_io_buff_ctrlzone(struct packet_io_device *pdev, struct packet *p)
void *packet_io_buff_ctrlzone(struct packet_io_device *pdev, struct stellar_packet *p)
{
return pdev->dev_ops->buff_ctrlzone(p);
}
char *packet_io_buff_mtod(struct packet_io_device *pdev, struct packet *p)
char *packet_io_buff_mtod(struct packet_io_device *pdev, struct stellar_packet *p)
{
return pdev->dev_ops->buff_mtod(p);
}
uint32_t packet_io_buff_buflen(struct packet_io_device *pdev, struct packet *p)
uint32_t packet_io_buff_buflen(struct packet_io_device *pdev, struct stellar_packet *p)
{
return pdev->dev_ops->buff_buflen(p);
}
uint32_t packet_io_buff_datalen(struct packet_io_device *pdev, struct packet *p)
uint32_t packet_io_buff_datalen(struct packet_io_device *pdev, struct stellar_packet *p)
{
return pdev->dev_ops->buff_datalen(p);
}
}

View File

@@ -60,19 +60,19 @@ struct pio_device_operations {
int (*close)(struct packet_io_device *pdev);
int (*recv)(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts);
int (*recv)(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts);
int (*send)(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts);
int (*send)(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, int nr_pkts);
void (*pkt_free)(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
void (*pkt_free)(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, int nr_pkts);
void *(*buff_ctrlzone)(struct packet *p);
void *(*buff_ctrlzone)(struct stellar_packet *p);
char *(*buff_mtod)(struct packet *p);
char *(*buff_mtod)(struct stellar_packet *p);
uint32_t (*buff_buflen)(struct packet *p);
uint32_t (*buff_buflen)(struct stellar_packet *p);
uint32_t (*buff_datalen)(struct packet *p);
uint32_t (*buff_datalen)(struct stellar_packet *p);
};
struct packet_io_device {
@@ -133,7 +133,7 @@ void packet_io_device_close(struct packet_io_device *dev);
* @param p: received packet's pointer array
* @param nr_p: number of received packets
*/
int packet_io_device_rx(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts);
int packet_io_device_rx(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts);
/**
* @brief packet_io device send function
@@ -143,30 +143,30 @@ int packet_io_device_rx(struct packet_io_device *pdev, uint32_t rxq_id, struct p
* @param p: prepare to send packet's pointer array
* @param nr_p: number of packets which prepare to send
*/
int packet_io_device_tx(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts);
int packet_io_device_tx(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, int nr_pkts);
/*
* @brief packet_io free packet buff
*/
void packet_io_pkts_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
void packet_io_pkts_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, int nr_pkts);
/**
* @brief get packet_io packet's ctrlzone
* @note ctrlzone's memory is 64 bytes, do not exceed it
*/
void *packet_io_buff_ctrlzone(struct packet_io_device *pdev, struct packet *p);
void *packet_io_buff_ctrlzone(struct packet_io_device *pdev, struct stellar_packet *p);
/**
* @brief get packet_io packet's data pointer
*/
char *packet_io_buff_mtod(struct packet_io_device *pdev, struct packet *p);
char *packet_io_buff_mtod(struct packet_io_device *pdev, struct stellar_packet *p);
/**
* @brief get packet_io packet's buffer length
*/
uint32_t packet_io_buff_buflen(struct packet_io_device *pdev, struct packet *p);
uint32_t packet_io_buff_buflen(struct packet_io_device *pdev, struct stellar_packet *p);
/**
* @brief get packet_io packet's data length
*/
uint32_t packet_io_buff_datalen(struct packet_io_device *pdev, struct packet *p);
uint32_t packet_io_buff_datalen(struct packet_io_device *pdev, struct stellar_packet *p);

View File

@@ -93,7 +93,7 @@ static int init_pcap_file(struct pcap_plain_file_info *pfile_info)
return -1;
}
pthread_mutex_init(&pfile_info->handle_mutex, NULL);
pthread_mutex_init(&pfile_info->handle_mutex, nullptr);
if (pfile_info->shared != nullptr && pfile_info->shared->bpf_string != nullptr) {
if (pcap_compile(pfile_info->pcap_handle, &pfile_info->filter,
@@ -133,9 +133,14 @@ static int pcap_plain_file_init(struct pio_pcap_file_device_context *pfile_dev_c
}
/* TODO: get conf and assign pfile_info */
strncpy(pfile_info->file_name, file_name, strlen(file_name));
int ret = strncpy_safe(pfile_info->file_name, file_name, sizeof(pfile_info->file_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "pcap plain file name copy failed.");
return -1;
}
pfile_info->shared = &pfile_dev_ctx->shared;
int ret = init_pcap_file(pfile_info);
ret = init_pcap_file(pfile_info);
if (ret < 0) {
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "init_pcap_file failed.");
FREE(pfile_info);
@@ -161,7 +166,12 @@ static int pcap_directory_file_init(struct pio_pcap_file_device_context *pfile_d
}
/* TODO: get conf and assign pdir_info */
strncpy(pdir_info->dir_name, dir_name, strlen(dir_name));
int ret = strncpy_safe(pdir_info->dir_name, dir_name, sizeof(pdir_info->dir_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "pcap directory name copy failed.");
return -1;
}
//pdir_info->delay = 30;
pdir_info->shared = &pfile_dev_ctx->shared;
pdir_info->directory = directory;
@@ -182,8 +192,13 @@ static int pcap_file_shared_init(struct pio_pcap_file_device_context *pfile_dev_
/* TODO: get conf and assign pfile_dev_ctx->shared */
if ((g_engine_instance.config.packet_io.mode == PACKET_IO_RUN_MODE_PCAP_FILE) &&
g_engine_instance.config.packet_io.bpf_string != nullptr) {
strncpy(pfile_dev_ctx->shared.bpf_string, g_engine_instance.config.packet_io.bpf_string,
strlen(g_engine_instance.config.packet_io.bpf_string));
memset(pfile_dev_ctx->shared.bpf_string, 0, sizeof(pfile_dev_ctx->shared.bpf_string));
int ret = strncpy_safe(pfile_dev_ctx->shared.bpf_string, g_engine_instance.config.packet_io.bpf_string,
sizeof(pfile_dev_ctx->shared.bpf_string));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "pcap file bpf string copy failed.");
return -1;
}
}
pfile_dev_ctx->shared.should_delete = g_engine_instance.config.packet_io.should_delete;
@@ -315,7 +330,7 @@ void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_c
return;
}
uint32_t nr_rxq = pfile_dev_ctx->pio_dev->rxq_num;
//uint32_t nr_rxq = pfile_dev_ctx->pio_dev->rxq_num;
/*
hash to specific queue id and enqueue
hash_id = decode_packet(p) % nr_rxq;
@@ -328,7 +343,7 @@ void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_c
}
static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t rxq_id,
struct packet **pkts, int nr_pkts)
struct stellar_packet **pkts, int nr_pkts)
{
if (pfile_dev_ctx->entity.file->first_pkt_hdr != nullptr) {
pthread_mutex_lock(&pfile_dev_ctx->entity.file->handle_mutex);
@@ -361,7 +376,7 @@ static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx
pthread_mutex_lock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
do {
p = pio_packet_dequeue(&pfile_dev_ctx->pkt_queues[rxq_id]);
pkts[i] = (struct packet *)p;
pkts[i] = (struct stellar_packet *)p;
i++;
} while (p != nullptr && (i < nr_pkts));
pthread_mutex_unlock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
@@ -401,7 +416,7 @@ find_pending_file_to_add(struct pio_pcap_file_device_context *pfile_dev_ctx, str
{
char abs_path[PATH_MAX] = {0};
snprintf(abs_path, PATH_MAX, "%s/%s", pfile_dev_ctx->entity.dir->dir_name, dir->d_name);
snprintf(abs_path, sizeof(abs_path), "%s/%s", pfile_dev_ctx->entity.dir->dir_name, dir->d_name);
struct timespec temp_time;
memset(&temp_time, 0, sizeof(struct timespec));
@@ -420,7 +435,12 @@ find_pending_file_to_add(struct pio_pcap_file_device_context *pfile_dev_ctx, str
}
struct pending_file *file_to_add = CALLOC(struct pending_file, 1);
strncpy(file_to_add->file_name, abs_path, strlen(abs_path));
int ret = strncpy_safe(file_to_add->file_name, abs_path, sizeof(file_to_add->file_name));
if (ret < 0) {
log_error(ST_ERR_STR_COPY, "file_to_add file name copy failed.");
return nullptr;
}
copy_timespec(&temp_time, &file_to_add->modified_time);
log_info("found \"%s\" at %" PRIuMAX, file_to_add->file_name,
(uintmax_t)timespec_to_millisecond(&file_to_add->modified_time));
@@ -499,7 +519,7 @@ static int pcap_directory_collect_pending_files(struct pio_pcap_file_device_cont
}
static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t rxq_id,
struct packet **pkts, int nr_pkts)
struct stellar_packet **pkts, int nr_pkts)
{
int res = -1;
struct timespec deadline;
@@ -535,7 +555,14 @@ static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_de
return -1;
}
strncpy(pfile_info->file_name, current_file->file_name, strlen(current_file->file_name));
res = strncpy_safe(pfile_info->file_name, current_file->file_name, sizeof(pfile_info->file_name));
if (res < 0) {
log_error(ST_ERR_STR_COPY, "pfile_info file name copy failed.");
FREE(current_file);
FREE(pfile_info);
return -1;
}
pfile_info->shared = &pfile_dev_ctx->shared;
if (init_pcap_file(pfile_info) < 0) {
@@ -576,13 +603,7 @@ static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_de
return res;
}
static int pcap_file_exit(int status, struct timespec *last_processed)
{
return 0;
}
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts)
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts)
{
struct pio_pcap_file_device_context *pfile_dev_ctx = pdev->entity.pcap_file_dev_ctx;
if (nullptr == pfile_dev_ctx) {
@@ -599,14 +620,12 @@ int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
res = pcap_directory_dispatch(pfile_dev_ctx, rxq_id, pkts, nr_pkts);
}
//pcap_file_exit(status, &pfile_dev_ctx->shared.last_processed_ts);
return res;
}
void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct packet **pkts, int nr_pkts)
void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct stellar_packet **pkts, int nr_pkts)
{
for (uint32_t i = 0; i < nr_pkts; i++) {
for (int i = 0; i < nr_pkts; i++) {
struct pio_packet *p = (struct pio_packet *)pkts[i];
FREE(p);
}
@@ -642,26 +661,26 @@ void pio_pcap_file_instance_destroy(struct packet_io_instance *pinst)
}
}
void *pio_pcap_file_device_buff_ctrlzone(struct packet *p)
void *pio_pcap_file_device_buff_ctrlzone(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return pkt->pkt_hdr;
}
char *pio_pcap_file_device_buff_mtod(struct packet *p)
char *pio_pcap_file_device_buff_mtod(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (char *)pkt->pkt_payload;
}
uint32_t pio_pcap_file_device_buff_buflen(struct packet *p)
uint32_t pio_pcap_file_device_buff_buflen(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (pkt->pkt_len + CUSTOM_ZONE_LEN);
}
uint32_t pio_pcap_file_device_buff_datalen(struct packet *p)
uint32_t pio_pcap_file_device_buff_datalen(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (pkt->pkt_len);
}
}

View File

@@ -127,14 +127,14 @@ int pio_pcap_file_device_open(struct packet_io_device *pdev);
*/
int pio_pcap_file_device_close(struct packet_io_device *pdev);
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts);
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts);
void pio_pcap_file_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
void pio_pcap_file_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, int nr_pkts);
void *pio_pcap_file_device_buff_ctrlzone(struct packet *p);
void *pio_pcap_file_device_buff_ctrlzone(struct stellar_packet *p);
char *pio_pcap_file_device_buff_mtod(struct packet *p);
char *pio_pcap_file_device_buff_mtod(struct stellar_packet *p);
uint32_t pio_pcap_file_device_buff_buflen(struct packet *p);
uint32_t pio_pcap_file_device_buff_buflen(struct stellar_packet *p);
uint32_t pio_pcap_file_device_buff_datalen(struct packet *p);
uint32_t pio_pcap_file_device_buff_datalen(struct stellar_packet *p);

View File

@@ -76,8 +76,13 @@ static int pcap_live_init(struct pio_pcap_live_device_context *pcap_live_dev_ctx
/* set bpf filter */
if (strlen(g_engine_instance.config.packet_io.bpf_string) != 0) {
strncpy(pcap_live_dev_ctx->bpf_string, g_engine_instance.config.packet_io.bpf_string,
strlen(g_engine_instance.config.packet_io.bpf_string));
res = strncpy_safe(pcap_live_dev_ctx->bpf_string, g_engine_instance.config.packet_io.bpf_string,
sizeof(pcap_live_dev_ctx->bpf_string));
if (res < 0) {
log_error(ST_ERR_STR_COPY, "pcap_live_dev_ctx bpf string copy failed.");
return -1;
}
if (pcap_compile(pcap_live_dev_ctx->pcap_handle, &pcap_live_dev_ctx->filter,
pcap_live_dev_ctx->bpf_string, 1, 0) < 0) {
log_error(ST_ERR_BPF, "bpf compliation error %s",
@@ -160,7 +165,7 @@ static void pcap_live_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_h
return;
}
uint32_t nr_rxq = plive_dev_ctx->pio_dev->rxq_num;
//uint32_t nr_rxq = plive_dev_ctx->pio_dev->rxq_num;
/*
hash to specific queue id and enqueue
hash_id = decode_packet(p) % nr_rxq;
@@ -172,7 +177,7 @@ static void pcap_live_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_h
pthread_mutex_unlock(&plive_dev_ctx->pkt_queues[rxq_id].mutex_q);
}
int pio_pcap_live_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts)
int pio_pcap_live_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts)
{
int res = -1;
@@ -198,7 +203,7 @@ int pio_pcap_live_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
pthread_mutex_lock(&plive_dev_ctx->pkt_queues[rxq_id].mutex_q);
do {
p = pio_packet_dequeue(&plive_dev_ctx->pkt_queues[rxq_id]);
pkts[i] = (struct packet *)p;
pkts[i] = (struct stellar_packet *)p;
i++;
} while (p != nullptr && (i < nr_pkts));
pthread_mutex_unlock(&plive_dev_ctx->pkt_queues[rxq_id].mutex_q);
@@ -213,7 +218,7 @@ int pio_pcap_live_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
return res;
}
int pio_pcap_live_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts)
int pio_pcap_live_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, int nr_pkts)
{
int res = -1;
@@ -223,9 +228,8 @@ int pio_pcap_live_device_send(struct packet_io_device *pdev, uint32_t txq_id, st
return res;
}
int packet_q_len = nr_pkts;
pthread_mutex_lock(&plive_dev_ctx->handle_mutex);
for (uint32_t i = 0; i < nr_pkts; i++) {
for (int i = 0; i < nr_pkts; i++) {
struct pio_packet *p = (struct pio_packet *)pkts[i];
res = pcap_sendpacket(plive_dev_ctx->pcap_handle, (u_char *)p->pkt_payload, p->pkt_len);
}
@@ -235,9 +239,9 @@ int pio_pcap_live_device_send(struct packet_io_device *pdev, uint32_t txq_id, st
return 0;
}
void pio_pcap_live_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct packet **pkts, int nr_pkts)
void pio_pcap_live_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct stellar_packet **pkts, int nr_pkts)
{
for (uint32_t i = 0; i < nr_pkts; i++) {
for (int i = 0; i < nr_pkts; i++) {
struct pio_packet *p = (struct pio_packet *)pkts[i];
FREE(p);
}
@@ -273,26 +277,26 @@ void pio_pcap_live_instance_destroy(struct packet_io_instance *pinst)
}
}
void *pio_pcap_live_device_buff_ctrlzone(struct packet *p)
void *pio_pcap_live_device_buff_ctrlzone(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return pkt->pkt_hdr;
}
char *pio_pcap_live_device_buff_mtod(struct packet *p)
char *pio_pcap_live_device_buff_mtod(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (char *)pkt->pkt_payload;
}
uint32_t pio_pcap_live_device_buff_buflen(struct packet *p)
uint32_t pio_pcap_live_device_buff_buflen(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (pkt->pkt_len + CUSTOM_ZONE_LEN);
}
uint32_t pio_pcap_live_device_buff_datalen(struct packet *p)
uint32_t pio_pcap_live_device_buff_datalen(struct stellar_packet *p)
{
struct pio_packet *pkt = (struct pio_packet *)p;
return (pkt->pkt_len);
}
}

View File

@@ -87,16 +87,16 @@ int pio_pcap_live_device_open(struct packet_io_device *pdev);
*/
int pio_pcap_live_device_close(struct packet_io_device *pdev);
int pio_pcap_live_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct packet **pkts, int nr_pkts);
int pio_pcap_live_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts);
int pio_pcap_live_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts);
int pio_pcap_live_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, int nr_pkts);
void pio_pcap_live_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct packet **pkts, int nr_pkts);
void pio_pcap_live_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, int nr_pkts);
void *pio_pcap_live_device_buff_ctrlzone(struct packet *p);
void *pio_pcap_live_device_buff_ctrlzone(struct stellar_packet *p);
char *pio_pcap_live_device_buff_mtod(struct packet *p);
char *pio_pcap_live_device_buff_mtod(struct stellar_packet *p);
uint32_t pio_pcap_live_device_buff_buflen(struct packet *p);
uint32_t pio_pcap_live_device_buff_buflen(struct stellar_packet *p);
uint32_t pio_pcap_live_device_buff_datalen(struct packet *p);
uint32_t pio_pcap_live_device_buff_datalen(struct stellar_packet *p);

View File

@@ -4,7 +4,7 @@ add_executable(gtest_packet_io
target_link_libraries(
gtest_packet_io
gtest_main
gtest
packet_io
dl
pcap

View File

@@ -1,17 +1,15 @@
#include <gtest/gtest.h>
#include "../packet_io.h"
#include "packet_io.h"
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);
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);
EXPECT_EQ(packet_io_device_open(ppio_inst, nullptr, 1, 1), nullptr);
EXPECT_EQ(packet_io_device_open(ppio_inst, NULL, 1, 1), nullptr);
}
int main(int argc, char ** argv)