Repository navigation
xdp-trafficgen: add total runtime option to specify number of seconds to run - #590
Conversation
f7ebb41 to
8a39779
Compare
| .ctx_in = &ctx_in, | ||
| .ctx_size_in = sizeof(ctx_in), | ||
| .repeat = cfg->num_pkts ?: 1 << 20, | ||
| .repeat = cfg->num_pkts && cfg->num_pkts < TEST_RUN_BATCH_SIZE ? cfg->num_pkts : TEST_RUN_BATCH_SIZE, |
There was a problem hiding this comment.
This is too long - split it out to a separate expression before the DECLARE
There was a problem hiding this comment.
Got it, separated into expression.
| int err; | ||
| bool duration_expired = false; | ||
| struct timespec deadline = {}; | ||
| struct timespec now; |
There was a problem hiding this comment.
Please keep the declarations sorted by line length; also those two timespecs can be on one line.
There was a problem hiding this comment.
Moved them into one line and sorted declarations by line length.
| if (remaining < (__u64)opts.repeat) | ||
| opts.repeat = (int)remaining; | ||
| } | ||
|
|
There was a problem hiding this comment.
This seems like a separate fix, let's split it out to its own commit. And there's something wrong with the indentation (spaces instead of tabs)
There was a problem hiding this comment.
Separated into another commit.
| duration_expired = | ||
| now.tv_sec > deadline.tv_sec || | ||
| (now.tv_sec == deadline.tv_sec && | ||
| now.tv_nsec >= deadline.tv_nsec); |
There was a problem hiding this comment.
Might as well just break; here instead of carrying this into the while() check.
Add a duration option to the UDP and TCP traffic generators. Use a monotonic clock deadline to stop transmission once the requested number of seconds has elapsed, while preserving the existing packet-count stopping condition. Signed-off-by: Eray Cepni <cepnieray.tr@gmail.com>
Limit each BPF test run invocation to a fixed-size batch and reduce the final batch to the exact number of packets remaining. This avoids overflowing the signed repeat field for large packet counts while ensuring that only the requested number of packets is sent. Signed-off-by: Eray Cepni <cepnieray.tr@gmail.com>
8a39779 to
048f281
Compare
tohojo
left a comment
There was a problem hiding this comment.
Code looks good, but please add the new options to the README file and man page as well.
Document the duration option for the UDP and TCP traffic generators in both the README and generated man page, including its interaction with the packet-count limit. Signed-off-by: Eray Cepni <cepnieray.tr@gmail.com>
Add a --duration option to the UDP and TCP traffic-generator modes. Traffic generation stops when either the duration or packet limit is reached.
Batching was implemented because when num_pkts was given a high number like 4 billion and duration was given as 2 seconds, program wouldn't exit after 2 seconds. Doing it with batches allows both options to be checked constantly. BPF program runs are processed in smaller batches to keep duration checks responsive.
Fixes #355.