[PACKET_IO]add ip hash func
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "time_helper.h"
|
||||
#include "pio_pcap_file.h"
|
||||
#include "packet_io.h"
|
||||
#include "packet_io_util.h"
|
||||
|
||||
/**
|
||||
* @brief validate path is a valid plain file or directory
|
||||
@@ -183,7 +184,7 @@ static int pcap_directory_file_init(struct pio_pcap_file_device_context *pfile_d
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pcap_file_shared_init(struct pio_pcap_file_device_context *pfile_dev_ctx, uint32_t nr_rxq)
|
||||
static int pcap_file_shared_init(struct pio_pcap_file_device_context *pfile_dev_ctx)
|
||||
{
|
||||
if (nullptr == pfile_dev_ctx) {
|
||||
return -1;
|
||||
@@ -257,7 +258,7 @@ int pio_pcap_file_device_open(struct packet_io_device *pdev)
|
||||
|
||||
pdev->entity.pcap_file_dev_ctx->pio_dev = pdev;
|
||||
|
||||
status = pcap_file_shared_init(pdev->entity.pcap_file_dev_ctx, pdev->rxq_num);
|
||||
status = pcap_file_shared_init(pdev->entity.pcap_file_dev_ctx);
|
||||
if (status < 0) {
|
||||
log_error(ST_ERR_PIO_PCAP_FILE_DEVICE, "pcap file shared init failed.");
|
||||
return -1;
|
||||
@@ -321,28 +322,26 @@ void pcap_file_pkt_callback_oneshot(char *user, struct pcap_pkthdr *pkt_hdr, u_c
|
||||
return;
|
||||
}
|
||||
memset(p, 0, SIZE_OF_PIO_PACKET);
|
||||
|
||||
p->pkt_hdr = p;
|
||||
p->pkt_payload = (uint8_t *)p + CUSTOM_ZONE_LEN;
|
||||
p->pkt_len = pkt_hdr->caplen;
|
||||
p->data_link = pfile_dev_ctx->entity.file->data_link;
|
||||
if (packet_copy_data((uint8_t *)p->pkt_payload, (uint8_t *)pkt, pkt_hdr->caplen)) {
|
||||
FREE(p);
|
||||
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;
|
||||
packet_enqueue(&pfile_dev_ctx->pkt_queues[hash_id], p);
|
||||
*/
|
||||
int rxq_id = 0;
|
||||
/* nr_rxq <= PKT_QUEUE_MAX_NUM */
|
||||
uint16_t nr_rxq = pfile_dev_ctx->pio_dev->rxq_num;
|
||||
uint16_t rxq_id = pio_packet_hash(p) % nr_rxq;
|
||||
|
||||
/* hash to specific queue id and enqueue */
|
||||
pthread_mutex_lock(&pfile_dev_ctx->pkt_queues[rxq_id].mutex_q);
|
||||
pio_packet_enqueue(&pfile_dev_ctx->pkt_queues[rxq_id], p);
|
||||
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 rxq_id,
|
||||
static int pcap_file_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint16_t rxq_id,
|
||||
struct stellar_packet **pkts, int nr_pkts)
|
||||
{
|
||||
if (pfile_dev_ctx->entity.file->first_pkt_hdr != nullptr) {
|
||||
@@ -518,7 +517,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 rxq_id,
|
||||
static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_dev_ctx, uint16_t rxq_id,
|
||||
struct stellar_packet **pkts, int nr_pkts)
|
||||
{
|
||||
int res = -1;
|
||||
@@ -603,7 +602,7 @@ static int pcap_directory_dispatch(struct pio_pcap_file_device_context *pfile_de
|
||||
return res;
|
||||
}
|
||||
|
||||
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, int nr_pkts)
|
||||
int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint16_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) {
|
||||
@@ -623,7 +622,7 @@ int pio_pcap_file_device_receive(struct packet_io_device *pdev, uint32_t rxq_id,
|
||||
return res;
|
||||
}
|
||||
|
||||
void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint32_t qid, struct stellar_packet **pkts, int nr_pkts)
|
||||
void pio_pcap_file_device_pkt_free(__unused struct packet_io_device *pdev, __unused uint16_t qid, struct stellar_packet **pkts, int nr_pkts)
|
||||
{
|
||||
for (int i = 0; i < nr_pkts; i++) {
|
||||
struct pio_packet *p = (struct pio_packet *)pkts[i];
|
||||
|
||||
Reference in New Issue
Block a user