2024-06-19 15:06:14 +08:00
|
|
|
#pragma once
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2024-02-28 16:30:03 +08:00
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-06-24 17:07:05 +08:00
|
|
|
#include <stdint.h>
|
2024-08-19 18:40:49 +08:00
|
|
|
#include <limits.h>
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-08-16 10:43:00 +08:00
|
|
|
#include "utils.h"
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-08-01 02:42:53 +08:00
|
|
|
struct __attribute__((aligned(64))) packet_io_stat
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
// device packet
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t pkts_rx;
|
|
|
|
|
uint64_t bytes_rx;
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t pkts_tx;
|
|
|
|
|
uint64_t bytes_tx;
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
// keep-alive packet
|
|
|
|
|
uint64_t keep_alive_pkts;
|
|
|
|
|
uint64_t keep_alive_bytes;
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
// raw packet
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t raw_pkts_rx;
|
|
|
|
|
uint64_t raw_bytes_rx;
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t raw_pkts_tx;
|
|
|
|
|
uint64_t raw_bytes_tx;
|
2024-04-10 17:50:51 +08:00
|
|
|
|
2024-04-30 15:25:34 +08:00
|
|
|
// drop packet
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t pkts_dropped;
|
|
|
|
|
uint64_t bytes_dropped;
|
2024-04-30 15:25:34 +08:00
|
|
|
|
2024-04-25 15:34:46 +08:00
|
|
|
// inject packet
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t pkts_injected;
|
|
|
|
|
uint64_t bytes_injected;
|
2024-04-25 15:34:46 +08:00
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
// ctrl packet
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t ctrl_pkts_rx;
|
|
|
|
|
uint64_t ctrl_bytes_rx;
|
2024-04-10 17:50:51 +08:00
|
|
|
|
2024-08-16 17:44:23 +08:00
|
|
|
uint64_t ctrl_pkts_tx;
|
|
|
|
|
uint64_t ctrl_bytes_tx;
|
2024-02-28 16:30:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum packet_io_mode
|
|
|
|
|
{
|
|
|
|
|
PACKET_IO_DUMPFILE = 0,
|
2024-08-19 18:40:49 +08:00
|
|
|
PACKET_IO_DUMPFILELIST = 1,
|
|
|
|
|
PACKET_IO_MARSIO = 2,
|
2024-02-28 16:30:03 +08:00
|
|
|
};
|
|
|
|
|
|
2024-03-08 14:51:21 +08:00
|
|
|
struct packet_io_options
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
|
|
|
|
enum packet_io_mode mode;
|
|
|
|
|
|
|
|
|
|
// for dumpfile
|
2024-08-19 18:40:49 +08:00
|
|
|
char dumpfile_path[PATH_MAX];
|
2024-02-28 16:30:03 +08:00
|
|
|
|
|
|
|
|
// for marsio
|
|
|
|
|
char app_symbol[64];
|
|
|
|
|
char dev_symbol[64];
|
|
|
|
|
|
2024-04-25 16:48:50 +08:00
|
|
|
uint16_t nr_threads;
|
2024-02-28 16:30:03 +08:00
|
|
|
uint16_t cpu_mask[MAX_THREAD_NUM];
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-28 19:00:32 +08:00
|
|
|
struct packet;
|
2024-02-28 16:30:03 +08:00
|
|
|
struct packet_io;
|
2024-03-08 14:51:21 +08:00
|
|
|
struct packet_io *packet_io_new(struct packet_io_options *opts);
|
2024-04-10 17:50:51 +08:00
|
|
|
void packet_io_free(struct packet_io *packet_io);
|
2024-08-21 14:33:03 +08:00
|
|
|
int packet_io_isbreak(struct packet_io *packet_io); // used for dumpfile mode
|
2024-04-10 17:50:51 +08:00
|
|
|
|
|
|
|
|
int packet_io_init(struct packet_io *packet_io, uint16_t thr_idx);
|
2024-08-28 09:58:39 +08:00
|
|
|
uint16_t packet_io_input(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, uint16_t nr_pkts);
|
|
|
|
|
void packet_io_output(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, uint16_t nr_pkts);
|
2024-08-21 14:33:03 +08:00
|
|
|
void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, uint16_t nr_pkts);
|
|
|
|
|
uint16_t packet_io_inject(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, uint16_t nr_pkts);
|
2024-04-18 14:20:28 +08:00
|
|
|
void packet_io_yield(struct packet_io *packet_io, uint16_t thr_idx, uint64_t timeout_ms);
|
2024-06-25 14:08:33 +08:00
|
|
|
struct packet_io_stat *packet_io_stat(struct packet_io *packet_io, uint16_t thr_idx);
|
2024-02-28 16:30:03 +08:00
|
|
|
|
2024-04-21 11:30:41 +08:00
|
|
|
#ifdef __cplusplus
|
2024-02-28 16:30:03 +08:00
|
|
|
}
|
|
|
|
|
#endif
|