diff options
| author | luwenpeng <[email protected]> | 2024-04-25 15:34:46 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-04-25 15:34:46 +0800 |
| commit | 54a78389cf0dfd731a56749ecbdfe7767618e828 (patch) | |
| tree | 1e853e19e6ec26b4c1d043e9b8d6f7e65f167c22 | |
| parent | 476c5bac56a8d6a87d1af05dce3f25c7262dc13a (diff) | |
packet IO support inject packet and add inject packet stat
| -rw-r--r-- | src/packet_io/dumpfile_io.cpp | 26 | ||||
| -rw-r--r-- | src/packet_io/dumpfile_io.h | 1 | ||||
| -rw-r--r-- | src/packet_io/marsio_io.cpp | 40 | ||||
| -rw-r--r-- | src/packet_io/marsio_io.h | 1 | ||||
| -rw-r--r-- | src/packet_io/packet_io.cpp | 12 | ||||
| -rw-r--r-- | src/packet_io/packet_io.h | 5 |
6 files changed, 85 insertions, 0 deletions
diff --git a/src/packet_io/dumpfile_io.cpp b/src/packet_io/dumpfile_io.cpp index b9e4aa2..1cd996b 100644 --- a/src/packet_io/dumpfile_io.cpp +++ b/src/packet_io/dumpfile_io.cpp @@ -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; diff --git a/src/packet_io/dumpfile_io.h b/src/packet_io/dumpfile_io.h index cebc744..8c69b04 100644 --- a/src/packet_io/dumpfile_io.h +++ b/src/packet_io/dumpfile_io.h @@ -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); diff --git a/src/packet_io/marsio_io.cpp b/src/packet_io/marsio_io.cpp index 0d4355d..e33f52c 100644 --- a/src/packet_io/marsio_io.cpp +++ b/src/packet_io/marsio_io.cpp @@ -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] = { diff --git a/src/packet_io/marsio_io.h b/src/packet_io/marsio_io.h index 328fa88..56103a2 100644 --- a/src/packet_io/marsio_io.h +++ b/src/packet_io/marsio_io.h @@ -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); diff --git a/src/packet_io/packet_io.cpp b/src/packet_io/packet_io.cpp index 633ce7f..3b545d2 100644 --- a/src/packet_io/packet_io.cpp +++ b/src/packet_io/packet_io.cpp @@ -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)) diff --git a/src/packet_io/packet_io.h b/src/packet_io/packet_io.h index 2faec8c..c8a2cf3 100644 --- a/src/packet_io/packet_io.h +++ b/src/packet_io/packet_io.h @@ -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); |
