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

133 lines
4.0 KiB
C
Raw Normal View History

2022-07-26 15:05:14 +08:00
/*
**********************************************************************************************
* 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.
***********************************************************************************************
*/
#pragma once
#include <stdint.h>
#include <limits.h>
2022-07-26 15:05:14 +08:00
#include <sys/queue.h>
#include "../common/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"
2022-07-26 15:05:14 +08:00
2022-07-28 21:22:44 +08:00
/*
2022-07-29 13:31:09 +08:00
* 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
**/
2022-07-26 15:05:14 +08:00
struct pio_instance_operations {
2022-07-29 13:31:09 +08:00
int (*create)(struct packet_io_instance *pinst, int wrk_thread_num);
2022-07-26 15:05:14 +08:00
2022-07-29 13:31:09 +08:00
void (*destroy)(struct packet_io_instance *pinst);
2022-07-26 15:05:14 +08:00
};
struct packet_io_instance {
/* packet_io instance name */
char inst_name[NAME_MAX];
/* packet_io run mode of the instance */
2022-07-26 15:05:14 +08:00
enum packet_io_run_mode mode;
/* device handle set in this instance */
2022-07-28 21:22:44 +08:00
struct packet_io_device *devices[DEV_MAX_CNT];
/* device's exactly count */
2022-07-26 15:05:14 +08:00
uint32_t dev_cnt;
/* instance operations */
struct pio_instance_operations *inst_ops;
union
{
struct pio_pcap_file_instance *pcap_file_inst;
struct pio_pcap_live_instance *pcap_live_inst;
struct pio_marsio_instance *marsio_inst;
2022-07-26 15:05:14 +08:00
} entity;
};
struct pio_device_operations {
int (*open)(struct packet_io_device *pinst, const char *dev_name, uint32_t nr_rxq, uint32_t nr_txq);
2022-07-26 15:05:14 +08:00
2022-07-28 21:22:44 +08:00
int (*close)(const struct packet_io_device *pdev);
2022-07-26 15:05:14 +08:00
int (*recv)(struct packet_io_device *pdev, uint32_t rxq_id, struct packet *p[], int pkt_cnt);
2022-07-26 15:05:14 +08:00
int (*send)(struct packet_io_device *pdev, uint32_t txq_id, struct packet *p[], int pkt_cnt);
2022-07-26 15:05:14 +08:00
};
struct packet_io_device {
/* device name */
char dev_name[NAME_MAX];
2022-07-26 15:05:14 +08:00
/* device operations */
struct pio_device_operations *dev_ops;
union {
struct pio_pcap_file_device *pcap_file_dev;
struct pio_pcap_live_device *pcap_live_dev;
struct pio_marsio_device *marsio_dev;
} entity;
2022-07-26 15:05:14 +08:00
/* packet io device context */
void *dev_ctx;
/* packet_io instance which the device belongs to */
2022-07-26 15:05:14 +08:00
struct packet_io_instance *ppio_inst;
};
2022-07-28 21:22:44 +08:00
/*
2022-07-29 13:31:09 +08:00
* @brief create packet_io instance which will manage packet_io device
*
* @param instance_name: packet_io instance name
* @param mode: packet_io run mode
* @param wrk_thread_num: expected number of packet receiving threads, which will be created by packet_io
**/
struct packet_io_instance *
2022-07-28 21:22:44 +08:00
packet_io_instance_create(const char *instance_name, const enum packet_io_run_mode mode, const int wrk_thread_num);
2022-07-29 13:31:09 +08:00
/* destroy packet_io instance */
void packet_io_instance_destroy(struct packet_io_instance *pinst);
2022-07-29 13:31:09 +08:00
/*
* @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 *
2022-07-29 13:31:09 +08:00
packet_io_device_open(struct packet_io_instance *pinst, const char *dev_name, uint32_t nr_rxq, uint32_t nr_txq);
2022-07-29 13:31:09 +08:00
/* close packet_io device */
void packet_io_device_close(struct packet_io_device *dev);
2022-07-29 13:31:09 +08:00
/*
* @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, uint32_t rxq_id, struct packet *p[], int nr_p);
2022-07-28 21:22:44 +08:00
2022-07-29 13:31:09 +08:00
/*
* @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, uint32_t txq_id, struct packet *p[], int nr_p);