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

@@ -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] = {