From 7ee6bef87927c6c6349f4a792cdb7c85237fb82b Mon Sep 17 00:00:00 2001 From: yunwei37 Date: Mon, 29 Apr 2024 10:20:28 +0000 Subject: [PATCH] update file --- src/xdp-pktgen.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/xdp-pktgen.c b/src/xdp-pktgen.c index 5d80460..103b9f3 100644 --- a/src/xdp-pktgen.c +++ b/src/xdp-pktgen.c @@ -62,9 +62,25 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va static int run_prog(int run_prog_fd, int count) { // struct test_udp_packet pkt_udp = create_test_udp_packet_v6(); - struct test_udp_packet_v4 pkt_udp = create_test_udp_packet_v4(); + char* pkt_file = NULL; + unsigned char pkt_file_buffer[1024]; + int size = 0; + if ((pkt_file = getenv("PKTGEN_FILE")) != NULL) { + FILE* file = fopen(pkt_file, "r"); + if (file == NULL) { + printf("Error opening file\n"); + return -1; + } + // read the the file length of data into the buffer + size = fread(pkt_file_buffer, 1, 1024, file); + fclose(file); + } else { + struct test_udp_packet_v4 pkt_udp = create_test_udp_packet_v4(); + size = sizeof(pkt_udp); + memcpy(pkt_file_buffer, &pkt_udp, size); + } struct xdp_md ctx_in = { - .data_end = sizeof(pkt_udp), + .data_end = size, .ingress_ifindex = cfg.ifindex }; // struct xdp_md ctx_in_array[64]; @@ -73,10 +89,10 @@ static int run_prog(int run_prog_fd, int count) // ctx_in_array[i].ingress_ifindex = cfg.ifindex; // } - printf("pkt size: %ld\n", sizeof(pkt_udp)); + printf("pkt size: %ld\n", size); DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, - .data_in = &pkt_udp, - .data_size_in = sizeof(pkt_udp), + .data_in = pkt_file_buffer, + .data_size_in = size, .ctx_in = &ctx_in, .ctx_size_in = sizeof(ctx_in), .repeat = cfg.repeat,