summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Schipp <jonschipp@gmail.com>2013-10-14 12:59:25 -0700
committerTobias Klauser <tklauser@distanz.ch>2013-10-15 11:56:38 +0200
commit859f1fe60ae57d49c6a475117f3fbbfc46293448 (patch)
treed01546f6dae649e7169522e4b9795db4041202bd
parent2548dc39129485b6c78889a578d3a42f4a680bb6 (diff)
trafgen: set interpacket gap in time units (s/ms/us/ns)
Add ability to set IGP in time units in seconds, milliseconds, microseconds, and nanoseconds by appending a postfix to --gap e.g. --gap 100ms. Also, update the man page and trafgen.zsh to reflect the changes. [Fix whitespaces, coding style and minor wording changes -- tklauser] Signed-off-by: Jon Schipp <jonschipp@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--trafgen.820
-rw-r--r--trafgen.c50
-rw-r--r--trafgen.zsh2
3 files changed, 51 insertions, 21 deletions
diff --git a/trafgen.8 b/trafgen.8
index e4a4e84..d311084 100644
--- a/trafgen.8
+++ b/trafgen.8
@@ -122,14 +122,16 @@ Specify the number of processes trafgen shall fork(2) off. By default trafgen
will start as many processes as CPUs that are online and pin them to each,
respectively. Allowed value must be within interval [1,CPUs].
.PP
-.SS -t <uint>, --gap <uint>
-Specify a static inter-packet timegap in micro-seconds. If this option is given,
-then instead of packet(7)'s TX_RING interface, trafgen will use sendto(2) I/O
-for network packets, even if the <uint> argument is 0. This option is useful for
-a couple of reasons: i) comparison between sendto(2) and TX_RING performance,
-ii) low-traffic packet probing for a given interval, iii) ping-like debugging
-with specific payload patterns. Furthermore, the TX_RING interface does not cope
-with interpacket gaps.
+.SS -t <time>, --gap <time>
+Specify a static inter-packet timegap in seconds, milliseconds, microseconds,
+or nanoseconds: ''<num>s/ms/us/ns''. If no postfix is given default to
+microseconds. If this option is given, then instead of packet(7)'s TX_RING
+interface, trafgen will use sendto(2) I/O for network packets, even if the
+<time> argument is 0. This option is useful for a couple of reasons: i)
+comparison between sendto(2) and TX_RING performance, ii) low-traffic packet
+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 -S <size>, --ring-size <size>
Manually define the TX_RING resp. TX_RING size in ''<num>KiB/MiB/GiB''. On
@@ -358,7 +360,7 @@ are going to transmit raw 802.11 frames through the air. Use the
''beacon-test.txf'' configuration file, set trafgen into verbose mode and
use only 2 CPUs.
.PP
-.SS trafgen --dev em1 --conf frag_dos.cfg --rand --gap 1000
+.SS trafgen --dev em1 --conf frag_dos.cfg --rand --gap 1000us
Use trafgen in sendto(2) mode instead of TX_RING mode and sleep after each
sent packet a static timegap for 1000us. Generate packets from ''frag_dos.cfg''
and select next packets to send randomly instead of a round-robin fashion.
diff --git a/trafgen.c b/trafgen.c
index cb8cb52..ba0b96b 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -56,9 +56,11 @@
struct ctx {
bool rand, rfraw, jumbo_support, verbose, smoke_test, enforce;
- unsigned long kpull, num, gap, reserve_size;
+ unsigned long kpull, num, reserve_size;
unsigned int cpus;
- uid_t uid; gid_t gid; char *device, *device_trans, *rhost;
+ uid_t uid; gid_t gid;
+ char *device, *device_trans, *rhost;
+ struct timespec gap;
struct sockaddr_in dest;
};
@@ -181,7 +183,7 @@ static void __noreturn help(void)
" -n|--num <uint> Number of packets until exit (def: 0)\n"
" -r|--rand Randomize packet selection (def: round robin)\n"
" -P|--cpus <uint> Specify number of forks(<= CPUs) (def: #CPUs)\n"
- " -t|--gap <uint> Interpacket gap in us (approx)\n"
+ " -t|--gap <time> Set approx. interpacket gap (s/ms/us/ns, def: us)\n"
" -S|--ring-size <size> Manually set mmap size (KiB/MiB/GiB)\n"
" -k|--kernel-pull <uint> Kernel batch interval in us (def: 10us)\n"
" -E|--seed <uint> Manually set srand(3) seed\n"
@@ -198,7 +200,7 @@ static void __noreturn help(void)
" trafgen -e | trafgen -i - -o eth0 --cpp -n 1\n"
" trafgen --dev eth0 --conf fuzzing.cfg --smoke-test 10.0.0.1\n"
" trafgen --dev wlan0 --rfraw --conf beacon-test.txf -V --cpus 2\n"
- " trafgen --dev eth0 --conf frag_dos.cfg --rand --gap 1000\n"
+ " trafgen --dev eth0 --conf frag_dos.cfg --rand --gap 1000us\n"
" trafgen --dev eth0 --conf icmp.cfg --rand --num 1400000 -k1000\n"
" trafgen --dev eth0 --conf tcp_syn.cfg -u `id -u bob` -g `id -g bob`\n\n"
"Arbitrary packet config examples (e.g. trafgen -e > trafgen.cfg):\n"
@@ -592,8 +594,8 @@ retry:
if (ctx->num > 0)
num--;
- if (ctx->gap > 0)
- usleep(ctx->gap);
+ if ((ctx->gap.tv_sec | ctx->gap.tv_nsec) > 0)
+ nanosleep(&ctx->gap, NULL);
}
bug_on(gettimeofday(&end, NULL));
@@ -879,6 +881,7 @@ int main(int argc, char **argv)
{
bool slow = false, invoke_cpp = false, reseed = true, cpustats = true;
int c, opt_index, vals[4] = {0}, irq;
+ uint64_t gap = 0;
unsigned int i, j;
char *confname = NULL, *ptr;
unsigned long cpus_tmp, orig_num = 0;
@@ -962,11 +965,36 @@ int main(int argc, char **argv)
break;
case 't':
slow = true;
- ctx.gap = strtoul(optarg, NULL, 0);
- if (ctx.gap > 0)
- /* Fall back to single core to not
- * mess up correct timing. We are slow
- * anyway!
+ ptr = optarg;
+ gap = strtoul(optarg, NULL, 0);
+
+ for (j = i = strlen(optarg); i > 0; --i) {
+ if (!isdigit(optarg[j - i]))
+ break;
+ ptr++;
+ }
+
+ if (!strncmp(ptr, "ns", strlen("ns"))) {
+ ctx.gap.tv_sec = gap / 1000000000;
+ ctx.gap.tv_nsec = gap % 1000000000;
+ } else if (*ptr == '\0' || !strncmp(ptr, "us", strlen("us"))) {
+ /* Default to microseconds for backwards
+ * compatibility if no postfix is given.
+ */
+ ctx.gap.tv_sec = gap / 1000000;
+ ctx.gap.tv_nsec = (gap % 1000000) * 1000;
+ } else if (!strncmp(ptr, "ms", strlen("ms"))) {
+ ctx.gap.tv_sec = gap / 1000;
+ ctx.gap.tv_nsec = (gap % 1000) * 1000000;
+ } else if (!strncmp(ptr, "s", strlen("s"))) {
+ ctx.gap.tv_sec = gap;
+ ctx.gap.tv_nsec = 0;
+ } else
+ panic("Syntax error in time param!\n");
+
+ if (gap > 0)
+ /* Fall back to single core to not mess up
+ * correct timing. We are slow anyway!
*/
ctx.cpus = 1;
break;
diff --git a/trafgen.zsh b/trafgen.zsh
index 8fd1a37..8a90381 100644
--- a/trafgen.zsh
+++ b/trafgen.zsh
@@ -42,7 +42,7 @@ _arguments -s -S \
"(-n --num)"{-n,--num}"[Number of packets until exit (def: 0)]" \
"(-r --rand)"{-r,--rand}"[Randomize packet selection (def: round robin)]" \
"(-P --cpus)"{-P,--cpus}"[Specify number of forks(<= CPUs) (def: #CPUs)]:cpunum:_cpu" \
- "(-t --gap)"{-t,--gap}"[Interpacket gap in us (approx)]" \
+ "(-t --gap)"{-t,--gap}"[Set approx. interpacket gap (s/ms/us/ns, def: us)]:gap:"
"(-S --ring-size)"{-S,--ring-size}"[Manually set mmap size (KiB/MiB/GiB)]:ringsize:" \
"(-k --kernel-pull)"{-k,--kernel-pull}"[Kernel pull from user interval in us (def: 10us)]:kernelpull:_gnu_generic" \
"(-E --seed)"{-E,--seed}"[Manually set srand(3) seed]" \