[PACKET_IO]format api style
This commit is contained in:
@@ -17,119 +17,50 @@ extern "C"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <sys/queue.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "global_var.h"
|
||||
#include "./pcap_live_mode/pio_pcap_live.h"
|
||||
#include "./pcap_file_mode/pio_pcap_file.h"
|
||||
#include "./marsio_mode/pio_marsio.h"
|
||||
enum packet_io_run_mode {
|
||||
PACKET_IO_RUN_MODE_PCAP_FILE,
|
||||
PACKET_IO_RUN_MODE_PCAP_LIVE,
|
||||
PACKET_IO_RUN_MODE_MARSIO,
|
||||
PACKET_IO_RUN_MODE_MAX,
|
||||
};
|
||||
|
||||
struct packet_io_instance;
|
||||
struct packet_io_device;
|
||||
|
||||
/**
|
||||
* note:
|
||||
* 1. packet_io_XXX function is supported by packet_io.h
|
||||
* 2. pio_XXX function is supported by pio_pcap_live.h/pio_pcap_file.h/pio_marsio.h
|
||||
*/
|
||||
|
||||
struct pio_instance_operations {
|
||||
int (*create)(struct packet_io_instance *pinst);
|
||||
|
||||
void (*destroy)(struct packet_io_instance *pinst);
|
||||
};
|
||||
|
||||
struct packet_io_instance {
|
||||
/* packet_io instance name */
|
||||
char inst_name[NAME_MAX];
|
||||
|
||||
/* packet_io run mode of the instance */
|
||||
enum packet_io_run_mode mode;
|
||||
|
||||
/* device handle set in this instance */
|
||||
struct packet_io_device *devices[DEV_MAX_CNT];
|
||||
|
||||
/* device's exactly count */
|
||||
uint32_t dev_cnt;
|
||||
|
||||
/* instance operations */
|
||||
struct pio_instance_operations *inst_ops;
|
||||
|
||||
union
|
||||
{
|
||||
struct pio_pcap_file_instance_context *pcap_file_inst_ctx;
|
||||
struct pio_pcap_live_instance_context *pcap_live_inst_ctx;
|
||||
struct pio_marsio_instance_context *marsio_inst_ctx;
|
||||
} entity;
|
||||
};
|
||||
|
||||
struct pio_device_operations {
|
||||
int (*open)(struct packet_io_device *pdev);
|
||||
|
||||
int (*close)(struct packet_io_device *pdev);
|
||||
|
||||
int (*recv)(struct packet_io_device *pdev, uint16_t rxq_id, struct stellar_packet **pkts, int nr_pkts);
|
||||
|
||||
int (*send)(struct packet_io_device *pdev, uint16_t txq_id, struct stellar_packet **pkts, int nr_pkts);
|
||||
|
||||
void (*pkt_free)(struct packet_io_device *pdev, uint16_t qid, struct stellar_packet **pkts, int nr_pkts);
|
||||
|
||||
void *(*buff_ctrlzone)(struct stellar_packet *p);
|
||||
|
||||
char *(*buff_mtod)(struct stellar_packet *p);
|
||||
|
||||
uint32_t (*buff_buflen)(struct stellar_packet *p);
|
||||
|
||||
uint32_t (*buff_datalen)(struct stellar_packet *p);
|
||||
};
|
||||
|
||||
struct packet_io_device {
|
||||
/* device name */
|
||||
char dev_name[NAME_MAX];
|
||||
|
||||
/* device operations */
|
||||
struct pio_device_operations *dev_ops;
|
||||
|
||||
/* number of receive queue */
|
||||
uint16_t rxq_num;
|
||||
|
||||
/* number of send queue */
|
||||
uint16_t txq_num;
|
||||
|
||||
/* packet io device context */
|
||||
union {
|
||||
struct pio_pcap_file_device_context *pcap_file_dev_ctx;
|
||||
struct pio_pcap_live_device_context *pcap_live_dev_ctx;
|
||||
struct pio_marsio_device_context *marsio_dev_ctx;
|
||||
} entity;
|
||||
|
||||
/* packet_io instance which the device belongs to */
|
||||
struct packet_io_instance *ppio_inst;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief create packet_io instance which will manage packet_io device
|
||||
*
|
||||
* @param instance_name: packet_io instance name
|
||||
* @param mode: packet_io run mode
|
||||
* @brief
|
||||
*
|
||||
* @param instance_name: packet_io instance's name
|
||||
* @param filename: packet_io config file's name
|
||||
* @param devices(in/out): return packet_io_device pointer array, each pointer stands for an opened packet_io device
|
||||
* @param dev_num: the num of opened packet_io_device's pointer
|
||||
* @return struct packet_io_instance*
|
||||
*/
|
||||
struct packet_io_instance *
|
||||
packet_io_instance_create(const char *instance_name, const enum packet_io_run_mode mode);
|
||||
packet_io_init(const char *instance_name, const char *filename, struct packet_io_device *devices[], size_t *dev_num);
|
||||
|
||||
/* destroy packet_io instance */
|
||||
void packet_io_instance_destroy(struct packet_io_instance *pinst);
|
||||
void packet_io_fini(struct packet_io_instance *pinst);
|
||||
|
||||
/**
|
||||
* @brief open packet_io device for send/receive packets
|
||||
*
|
||||
* @param pinst: packet_io instance pointer
|
||||
* @param dev_name: packet_io device name
|
||||
* @param nr_rxq: number of receive queue for the device
|
||||
* @param nr_txq: number of send queue for the device
|
||||
* @brief
|
||||
*
|
||||
* @param inst_name
|
||||
* @param mode
|
||||
* @return struct packet_io_instance*
|
||||
*/
|
||||
struct packet_io_device *
|
||||
packet_io_device_open(struct packet_io_instance *pinst, const char *dev_name, uint16_t nr_rxq, uint16_t nr_txq);
|
||||
struct packet_io_instance *
|
||||
packet_io_instance_create(const char *inst_name, const enum packet_io_run_mode mode);
|
||||
|
||||
/** close packet_io device */
|
||||
void packet_io_device_close(struct packet_io_device *dev);
|
||||
void packet_io_instance_destroy(struct packet_io_instance *pinst);
|
||||
|
||||
struct packet_io_device *
|
||||
packet_io_device_open(struct packet_io_instance *pinst, const char *dev_name, size_t nr_rxq, size_t nr_txq);
|
||||
|
||||
void packet_io_device_close(struct packet_io_device *pdev);
|
||||
|
||||
/**
|
||||
* @brief packet_io device receive function
|
||||
@@ -139,7 +70,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, uint16_t rxq_id, struct stellar_packet **pkts, int nr_pkts);
|
||||
ssize_t packet_io_device_rx(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, size_t nr_pkts);
|
||||
|
||||
/**
|
||||
* @brief packet_io device send function
|
||||
@@ -149,33 +80,12 @@ int packet_io_device_rx(struct packet_io_device *pdev, uint16_t rxq_id, struct s
|
||||
* @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, uint16_t txq_id, struct stellar_packet **pkts, int nr_pkts);
|
||||
ssize_t packet_io_device_tx(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, size_t nr_pkts);
|
||||
|
||||
/*
|
||||
* @brief packet_io free packet buff
|
||||
*/
|
||||
void packet_io_pkts_free(struct packet_io_device *pdev, uint16_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 stellar_packet *p);
|
||||
|
||||
/**
|
||||
* @brief get packet_io packet's data pointer
|
||||
*/
|
||||
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 stellar_packet *p);
|
||||
|
||||
/**
|
||||
* @brief get packet_io packet's data length
|
||||
*/
|
||||
uint32_t packet_io_buff_datalen(struct packet_io_device *pdev, struct stellar_packet *p);
|
||||
void packet_io_pkts_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, size_t nr_pkts);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user