Refactor Packet I/O

This commit is contained in:
luwenpeng
2024-04-10 17:50:51 +08:00
parent 24e109e34f
commit 621a4cf292
13 changed files with 441 additions and 528 deletions

View File

@@ -6,29 +6,40 @@ extern "C"
{
#endif
#include "packet_private.h"
#include "log.h"
#include "packet.h"
#include "stellar.h"
#define PACKET_IO_LOG_STATE(format, ...) LOG_STATE("packet_io", format, ##__VA_ARGS__)
#define PACKET_IO_LOG_ERROR(format, ...) LOG_ERROR("packet_io", format, ##__VA_ARGS__)
#define PACKET_IO_LOG_DEBUG(format, ...) LOG_DEBUG("packet_io", format, ##__VA_ARGS__)
struct packet_io_stat
struct packet_stat
{
uint64_t rx_pkts;
uint64_t tx_pkts;
// device packet
uint64_t dev_rx_pkts;
uint64_t dev_rx_bytes;
uint64_t rx_bytes;
uint64_t tx_bytes;
uint64_t dev_tx_pkts;
uint64_t dev_tx_bytes;
uint64_t keepalive_pkts;
uint64_t keepalive_bytes;
// keep-alive packet
uint64_t keep_alive_pkts;
uint64_t keep_alive_bytes;
uint64_t drop_pkts;
uint64_t drop_bytes;
// raw packet
uint64_t raw_rx_pkts;
uint64_t raw_rx_bytes;
uint64_t inject_pkts;
uint64_t inject_bytes;
uint64_t raw_tx_pkts;
uint64_t raw_tx_bytes;
// ctrl packet
uint64_t ctrl_rx_pkts;
uint64_t ctrl_rx_bytes;
uint64_t ctrl_tx_pkts;
uint64_t ctrl_tx_bytes;
};
enum packet_io_mode
@@ -54,19 +65,13 @@ struct packet_io_options
struct packet_io;
struct packet_io *packet_io_new(struct packet_io_options *opts);
void packet_io_free(struct packet_io *handle);
struct packet_io_stat *packet_io_get_stat(struct packet_io *handle);
void packet_io_free(struct packet_io *packet_io);
struct packet_stat *packet_io_stat(struct packet_io *packet_io);
// TODO performance optimization egress for multi-packet
// return 0: success
// return -1: failed
int packet_io_init(struct packet_io *handle, uint16_t thread_id);
// return number of packets received
int packet_io_ingress(struct packet_io *handle, uint16_t thread_id, struct packet *pkts, int nr_pkts);
void packet_io_egress(struct packet_io *handle, uint16_t thread_id, struct packet *pkts, int nr_pkts);
void packet_io_drop(struct packet_io *handle, uint16_t thread_id, struct packet *pkts, int nr_pkts);
void packet_io_inject(struct packet_io *handle, uint16_t thread_id, struct packet *pkts, int nr_pkts);
int packet_io_init(struct packet_io *packet_io, uint16_t thr_idx);
int packet_io_ingress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void packet_io_egress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
#ifdef __cpluscplus
}