2024-02-28 16:30:03 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
#include "marsio_io.h"
|
|
|
|
|
#include "dumpfile_io.h"
|
2024-02-28 16:30:03 +08:00
|
|
|
|
|
|
|
|
struct packet_io
|
|
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
enum packet_io_mode mode;
|
|
|
|
|
struct marsio_io *marsio;
|
|
|
|
|
struct dumpfile_io *dumpfile;
|
2024-02-28 16:30:03 +08:00
|
|
|
};
|
|
|
|
|
|
2024-03-08 14:51:21 +08:00
|
|
|
struct packet_io *packet_io_new(struct packet_io_options *opts)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
struct packet_io *packet_io = (struct packet_io *)calloc(1, sizeof(struct packet_io));
|
|
|
|
|
if (packet_io == NULL)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
|
|
|
|
PACKET_IO_LOG_ERROR("unable to alloc packet io");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
packet_io->mode = opts->mode;
|
2024-03-08 14:51:21 +08:00
|
|
|
if (opts->mode == PACKET_IO_MARSIO)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
packet_io->marsio = marsio_io_new(opts->app_symbol, opts->dev_symbol, opts->cpu_mask, opts->nr_threads);
|
2024-02-28 16:30:03 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
packet_io->dumpfile = dumpfile_io_new(opts->dumpfile_dir, opts->nr_threads);
|
2024-02-28 16:30:03 +08:00
|
|
|
}
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io->marsio == NULL && packet_io->dumpfile == NULL)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
|
|
|
|
goto error_out;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
return packet_io;
|
2024-02-28 16:30:03 +08:00
|
|
|
|
|
|
|
|
error_out:
|
2024-04-10 17:50:51 +08:00
|
|
|
packet_io_free(packet_io);
|
2024-02-28 16:30:03 +08:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
void packet_io_free(struct packet_io *packet_io)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io->mode == PACKET_IO_MARSIO)
|
|
|
|
|
{
|
|
|
|
|
marsio_io_free(packet_io->marsio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dumpfile_io_free(packet_io->dumpfile);
|
|
|
|
|
}
|
|
|
|
|
free(packet_io);
|
|
|
|
|
packet_io = NULL;
|
2024-02-28 16:30:03 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 14:12:41 +08:00
|
|
|
struct io_stat *packet_io_get_stat(struct packet_io *packet_io)
|
2024-03-08 14:25:01 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io->mode == PACKET_IO_MARSIO)
|
|
|
|
|
{
|
2024-04-16 14:12:41 +08:00
|
|
|
return marsio_io_get_stat(packet_io->marsio);
|
2024-04-10 17:50:51 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-04-16 14:12:41 +08:00
|
|
|
return dumpfile_io_get_stat(packet_io->dumpfile);
|
2024-04-10 17:50:51 +08:00
|
|
|
}
|
2024-03-08 14:25:01 +08:00
|
|
|
}
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
int packet_io_init(struct packet_io *packet_io, uint16_t thr_idx)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io->mode == PACKET_IO_MARSIO)
|
|
|
|
|
{
|
|
|
|
|
return marsio_io_init(packet_io->marsio, thr_idx);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return dumpfile_io_init(packet_io->dumpfile, thr_idx);
|
|
|
|
|
}
|
2024-02-28 16:30:03 +08:00
|
|
|
}
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
int packet_io_ingress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io->mode == PACKET_IO_MARSIO)
|
|
|
|
|
{
|
|
|
|
|
return marsio_io_ingress(packet_io->marsio, thr_idx, pkts, nr_pkts);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return dumpfile_io_ingress(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
|
|
|
|
|
}
|
2024-02-28 16:30:03 +08:00
|
|
|
}
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
void packet_io_egress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
|
2024-02-28 16:30:03 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io->mode == PACKET_IO_MARSIO)
|
|
|
|
|
{
|
|
|
|
|
marsio_io_egress(packet_io->marsio, thr_idx, pkts, nr_pkts);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dumpfile_io_egress(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
|
|
|
|
|
}
|
2024-03-09 19:28:14 +08:00
|
|
|
}
|
|
|
|
|
|
2024-04-10 17:50:51 +08:00
|
|
|
void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
|
2024-03-09 19:28:14 +08:00
|
|
|
{
|
2024-04-10 17:50:51 +08:00
|
|
|
if (packet_io->mode == PACKET_IO_MARSIO)
|
|
|
|
|
{
|
|
|
|
|
marsio_io_drop(packet_io->marsio, thr_idx, pkts, nr_pkts);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dumpfile_io_drop(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
|
|
|
|
|
}
|
2024-02-28 16:30:03 +08:00
|
|
|
}
|