From 9ece0fe0209673d2f3f7f4f3e3738dfa7ec1873b Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Wed, 23 Dec 2015 22:31:23 +0200 Subject: trafgen: Add option to specify packets sending rate Added -b,--rate option in units of: pps/B/kB/MB/kBit/Mbit/Gbit/KiB/MiB/GiB to specify rate at which packets will be sent. Similarly to -t,--gap option the packets will be sent in slow mode with 1 CPU. Tested with ifpps. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- trafgen.8 | 4 ++ trafgen.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 135 insertions(+), 9 deletions(-) diff --git a/trafgen.8 b/trafgen.8 index 6f5d318..57ce8fa 100644 --- a/trafgen.8 +++ b/trafgen.8 @@ -136,6 +136,10 @@ probing for a given interval, iii) ping-like debugging with specific payload patterns. Furthermore, the TX_RING interface does not cope with interpacket gaps. .PP +.SS -b , --rate +Specify the packet send rate pps/B/kB/MB/GB/kBit/Mbit/Gbit/KiB/MiB/GiB units. +Like with the -t,--gap option, the packets are sent in slow mode. +.PP .SS -S , --ring-size Manually define the TX_RING resp. TX_RING size in ''KiB/MiB/GiB''. On default the size is being determined based on the network connectivity rate. diff --git a/trafgen.c b/trafgen.c index df2ecf4..a1d5463 100644 --- a/trafgen.c +++ b/trafgen.c @@ -55,6 +55,27 @@ #include "ring_tx.h" #include "csum.h" +#ifndef timeval_to_timespec +#define timeval_to_timespec(tv, ts) { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} +#endif + +enum shaper_type { + SHAPER_NONE, + SHAPER_PKTS, + SHAPER_BYTES, +}; + +struct shaper { + enum shaper_type type; + unsigned long long sent; + unsigned long long rate; + struct timeval start; + struct timeval end; +}; + struct ctx { bool rand, rfraw, jumbo_support, verbose, smoke_test, enforce, qdisc_path; size_t reserve_size; @@ -64,6 +85,7 @@ struct ctx { char *device, *device_trans, *rhost; struct timespec gap; struct sockaddr_in dest; + struct shaper sh; char *packet_str; }; @@ -83,7 +105,7 @@ size_t plen = 0; struct packet_dyn *packet_dyn = NULL; size_t dlen = 0; -static const char *short_options = "d:c:n:t:vJhS:rk:i:o:VRs:P:eE:pu:g:CHQqD:"; +static const char *short_options = "d:c:n:t:vJhS:rk:i:o:VRs:P:eE:pu:g:CHQqD:b:"; static const struct option long_options[] = { {"dev", required_argument, NULL, 'd'}, {"out", required_argument, NULL, 'o'}, @@ -91,6 +113,7 @@ static const struct option long_options[] = { {"conf", required_argument, NULL, 'c'}, {"num", required_argument, NULL, 'n'}, {"gap", required_argument, NULL, 't'}, + {"rate", required_argument, NULL, 'b'}, {"cpus", required_argument, NULL, 'P'}, {"ring-size", required_argument, NULL, 'S'}, {"kernel-pull", required_argument, NULL, 'k'}, @@ -172,6 +195,7 @@ static void __noreturn help(void) " -r|--rand Randomize packet selection (def: round robin)\n" " -P|--cpus Specify number of forks(<= CPUs) (def: #CPUs)\n" " -t|--gap