[PACKET_IO] add function for operating packets
This commit is contained in:
@@ -240,6 +240,8 @@ int pio_pcap_file_device_open(struct packet_io_device *pdev)
|
||||
return -1;
|
||||
}
|
||||
|
||||
pdev->entity.pcap_file_dev_ctx->pio_dev = pdev;
|
||||
|
||||
status = pcap_file_shared_init(pdev->entity.pcap_file_dev_ctx, pdev->rxq_num);
|
||||
if (status < 0) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "pcap file shared init failed.");
|
||||
@@ -313,6 +315,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;
|
||||
/*
|
||||
hash to specific queue id and enqueue
|
||||
hash_id = decode_packet(p) % nr_rxq;
|
||||
@@ -324,7 +327,7 @@ void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_c
|
||||
pthread_mutex_unlock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
|
||||
}
|
||||
|
||||
static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t nr_rxq, uint32_t rxq_id,
|
||||
static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t rxq_id,
|
||||
struct packet **pkts, int nr_pkts)
|
||||
{
|
||||
if (pfile_dev_ctx->entity.file->first_pkt_hdr != nullptr) {
|
||||
@@ -495,7 +498,7 @@ static int pcap_directory_collect_pending_files(struct pio_pcap_file_device_cont
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t nr_rxq, uint32_t rxq_id,
|
||||
static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t rxq_id,
|
||||
struct packet **pkts, int nr_pkts)
|
||||
{
|
||||
int res = -1;
|
||||
@@ -542,7 +545,7 @@ static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_de
|
||||
return -1;
|
||||
} else {
|
||||
pfile_dev_ctx->entity.dir->current_file = pfile_info;
|
||||
res = pcap_file_dispatch(pfile_dev_ctx, nr_rxq, rxq_id, pkts, nr_pkts);
|
||||
res = pcap_file_dispatch(pfile_dev_ctx, rxq_id, pkts, nr_pkts);
|
||||
if (res < 0) {
|
||||
FREE(current_file);
|
||||
return -1;
|
||||
@@ -559,7 +562,7 @@ static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_de
|
||||
}
|
||||
} else {
|
||||
/* file has been opened */
|
||||
res = pcap_file_dispatch(pfile_dev_ctx, nr_rxq, rxq_id, pkts, nr_pkts);
|
||||
res = pcap_file_dispatch(pfile_dev_ctx, rxq_id, pkts, nr_pkts);
|
||||
if (res < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -590,10 +593,10 @@ int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
|
||||
int res = -1;
|
||||
if (pfile_dev_ctx->is_dir == 0) {
|
||||
log_info("Start reading file:%s", pfile_dev_ctx->entity.file->file_name);
|
||||
res = pcap_file_dispatch(pfile_dev_ctx, pdev->rxq_num, rxq_id, pkts, nr_pkts);
|
||||
res = pcap_file_dispatch(pfile_dev_ctx, rxq_id, pkts, nr_pkts);
|
||||
} else {
|
||||
log_info("Start reading directory:%s", pfile_dev_ctx->entity.dir->dir_name);
|
||||
res = pcap_directory_dispatch(pfile_dev_ctx, pdev->rxq_num, rxq_id, pkts, nr_pkts);
|
||||
res = pcap_directory_dispatch(pfile_dev_ctx, rxq_id, pkts, nr_pkts);
|
||||
}
|
||||
|
||||
//pcap_file_exit(status, &pfile_dev_ctx->shared.last_processed_ts);
|
||||
@@ -601,12 +604,6 @@ int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
|
||||
return res;
|
||||
}
|
||||
|
||||
int pio_pcap_file_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct packet **pkts, int nr_pkts)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct packet **pkts, int nr_pkts)
|
||||
{
|
||||
for (uint32_t i = 0; i < nr_pkts; i++) {
|
||||
@@ -643,4 +640,28 @@ void pio_pcap_file_instance_destroy(struct packet_io_instance *pinst)
|
||||
pio_pcap_file_device_close(pinst->devices[i]);
|
||||
FREE(pinst->devices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void *pio_pcap_file_device_buff_ctrlzone(struct packet *p)
|
||||
{
|
||||
struct pio_packet *pkt = (struct pio_packet *)p;
|
||||
return pkt->pkt_hdr;
|
||||
}
|
||||
|
||||
char *pio_pcap_file_device_buff_mtod(struct 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
struct pio_packet *pkt = (struct pio_packet *)p;
|
||||
return (pkt->pkt_len);
|
||||
}
|
||||
Reference in New Issue
Block a user