// (c) 2023 Fraunhofer IIS, Maximilian Engelhardt #include #include "common.h" #include "rte_pause.h" #include "rte_ethdev.h" #include "rte_byteorder.h" #include "rte_byteorder_64.h" #include "rte_malloc.h" #include "rte_hexdump.h" const size_t BURST_SIZE = 128; struct ChannelStats { uint64_t stream_pos = 0; uint64_t last_packet_ts = -1; uint64_t max_ts_diff = 0; }; ChannelStats channel_stats_arr[2] = {}; uint64_t total_bytes_rx = 0; int worker(void* arg) { rte_mbuf* packets[BURST_SIZE]; while (run) { int num_packets = rte_eth_rx_burst(0, 0, packets, BURST_SIZE); for (int i = 0; istream_pos; auto rx_ts = *RTE_MBUF_DYNFIELD(packet, hwts_dynfield_offset, uint64_t *); auto& channel_stats = channel_stats_arr[header->stream_id]; ASSERT(channel_stats.stream_pos == header_stream_pos, "Stream error!"); if (channel_stats.last_packet_ts != -1) { auto diff = rx_ts - channel_stats.last_packet_ts; if (diff > channel_stats.max_ts_diff) channel_stats.max_ts_diff = diff; } channel_stats.last_packet_ts = rx_ts; total_bytes_rx += len; channel_stats.stream_pos = header_stream_pos + len; rte_pktmbuf_free(packet); } } } int main(int argc, char *argv[]) { init_dpdk(&argc, &argv); rte_eal_remote_launch(&worker, nullptr, rte_get_next_lcore(-1, true, false)); while (run) { rte_delay_ms(1000); printf("=== Total Rx: %lu bytes\r\n", total_bytes_rx); for (auto& channel_stats: channel_stats_arr) { printf("Stream pos %lu, Max timestamp difference: %lu\n", channel_stats.stream_pos, channel_stats.max_ts_diff); } } return 0; }