packet IO support inject packet and add inject packet stat

This commit is contained in:
luwenpeng
2024-04-25 15:34:46 +08:00
parent 476c5bac56
commit 54a78389cf
6 changed files with 85 additions and 0 deletions

View File

@@ -274,6 +274,32 @@ void dumpfile_io_drop(struct dumpfile_io *handle, uint16_t thr_idx, struct packe
}
}
int dumpfile_io_inject(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
{
int len;
struct packet *pkt = NULL;
struct io_stat *stat = &handle->stat[thr_idx];
for (int i = 0; i < nr_pkts; i++)
{
pkt = &pkts[i];
len = packet_get_len(pkt);
stat->inject_pkts++;
stat->inject_bytes += len;
stat->raw_tx_pkts++;
stat->raw_tx_bytes += len;
stat->dev_tx_pkts++;
stat->dev_tx_bytes += len;
packet_free(pkt);
}
return nr_pkts;
}
void dumpfile_io_yield(struct dumpfile_io *handle, uint16_t thr_idx, uint64_t timeout_ms)
{
return;

View File

@@ -16,6 +16,7 @@ int dumpfile_io_init(struct dumpfile_io *handle, uint16_t thr_idx);
int dumpfile_io_ingress(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void dumpfile_io_egress(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void dumpfile_io_drop(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
int dumpfile_io_inject(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void dumpfile_io_yield(struct dumpfile_io *handle, uint16_t thr_idx, uint64_t timeout_ms);
struct io_stat *dumpfile_io_stat(struct dumpfile_io *handle, uint16_t thr_idx);

View File

@@ -241,6 +241,46 @@ void marsio_io_drop(struct marsio_io *handle, uint16_t thr_idx, struct packet *p
}
}
int marsio_io_inject(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
{
int len;
int nr_inject = 0;
char *ptr;
struct packet *pkt;
marsio_buff_t *mbuff;
struct io_stat *stat = &handle->stat[thr_idx];
for (int i = 0; i < nr_pkts; i++)
{
pkt = &pkts[i];
len = packet_get_len(pkt);
if (marsio_buff_malloc_global(handle->mr_ins, &mbuff, 1, MARSIO_SOCKET_ID_ANY, MARSIO_LCORE_ID_ANY) < 0)
{
PACKET_IO_LOG_ERROR("unable to allocate marsio buffer for inject packet");
continue;
}
stat->inject_pkts++;
stat->inject_bytes += len;
stat->raw_tx_pkts++;
stat->raw_tx_bytes += len;
stat->dev_tx_pkts++;
stat->dev_tx_bytes += len;
nr_inject++;
ptr = marsio_buff_append(mbuff, len);
memcpy(ptr, packet_get_data(pkt), len);
marsio_send_burst(handle->mr_path, thr_idx, &mbuff, 1);
packet_free(pkt);
}
return nr_inject;
}
void marsio_io_yield(struct marsio_io *handle, uint16_t thr_idx, uint64_t timeout_ms)
{
struct mr_vdev *vdevs[1] = {

View File

@@ -16,6 +16,7 @@ int marsio_io_init(struct marsio_io *handle, uint16_t thr_idx);
int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void marsio_io_egress(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void marsio_io_drop(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
int marsio_io_inject(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void marsio_io_yield(struct marsio_io *handle, uint16_t thr_idx, uint64_t timeout_ms);
struct io_stat *marsio_io_stat(struct marsio_io *handle, uint16_t thr_idx);

View File

@@ -106,6 +106,18 @@ void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet
}
}
int packet_io_inject(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
{
if (likely(packet_io->mode == PACKET_IO_MARSIO))
{
return marsio_io_inject(packet_io->marsio, thr_idx, pkts, nr_pkts);
}
else
{
return dumpfile_io_inject(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
}
}
void packet_io_yield(struct packet_io *packet_io, uint16_t thr_idx, uint64_t timeout_ms)
{
if (likely(packet_io->mode == PACKET_IO_MARSIO))

View File

@@ -34,6 +34,10 @@ struct io_stat
uint64_t raw_tx_pkts;
uint64_t raw_tx_bytes;
// inject packet
uint64_t inject_pkts;
uint64_t inject_bytes;
// ctrl packet
uint64_t ctrl_rx_pkts;
uint64_t ctrl_rx_bytes;
@@ -71,6 +75,7 @@ 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);
int packet_io_inject(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
void packet_io_yield(struct packet_io *packet_io, uint16_t thr_idx, uint64_t timeout_ms);
struct io_stat *packet_io_stat(struct packet_io *packet_io, uint16_t thr_idx);