This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/src/packet_io/packet_io.h
2022-08-31 22:01:12 +08:00

184 lines
5.1 KiB
C

/*
**********************************************************************************************
* File: packet_io.h
* Description: packet io module entry
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-07-15
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
#ifndef _PACKET_IO_H_
#define _PACKET_IO_H_
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
#include <limits.h>
#include <sys/queue.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"
/**
* 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
*/
struct packet_io_instance *
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);
/**
* @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
*/
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);
/** close packet_io device */
void packet_io_device_close(struct packet_io_device *dev);
/**
* @brief packet_io device receive function
*
* @param pdev: packet_io device pointer
* @param rxq_id: which queue will receive from
* @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);
/**
* @brief packet_io device send function
*
* @param pdev: packet_io device pointer
* @param rxq_id: which queue will send to
* @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);
/*
* @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);
#ifdef __cpluscplus
}
#endif
#endif /* _PIO_PCAP_LIVE_H_ */