From 8082e88ad0ea0451782d283587db705db268a8f1 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 12 Nov 2009 14:57:29 +0100 Subject: [PATCH] fwp-timing learned -j (sending packets with jitter) --- fwp/tests/timing/fwp-timing.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fwp/tests/timing/fwp-timing.c b/fwp/tests/timing/fwp-timing.c index d2518a4..5d7726d 100644 --- a/fwp/tests/timing/fwp-timing.c +++ b/fwp/tests/timing/fwp-timing.c @@ -118,6 +118,7 @@ struct stream_params { int count; frsh_vres_id_t vres; pthread_t thread; + int jitter; }; @@ -208,6 +209,7 @@ static struct option long_opts[] = { { "count", required_argument, 0, 'c' }, { "verbose",no_argument, 0, 'v' }, { "quiet", no_argument, 0, 'q' }, + { "jitter", required_argument, 0, 'j' }, { 0, 0, 0, 0} }; @@ -226,6 +228,7 @@ usage(void) printf(" -q, --quiet Print only final statistics\n"); printf(" -/, --stream New stream separator\n"); printf(" -v, --verbose Be more verbose\n"); + printf(" -j, --jitter Sent jitter given as percentage of period\n"); } int parse_opts(int *argc, char **argv[], struct stream_params *p) @@ -234,7 +237,7 @@ int parse_opts(int *argc, char **argv[], struct stream_params *p) int ret; bool options_found = false; - while ((opt = getopt_long(*argc, *argv, "/ab:c:d:l:n:p:qs:v", long_opts, NULL)) != -1) { + while ((opt = getopt_long(*argc, *argv, "/ab:c:d:j:l:n:p:qs:v", long_opts, NULL)) != -1) { options_found = true; switch (opt) { case 'a': @@ -255,6 +258,9 @@ int parse_opts(int *argc, char **argv[], struct stream_params *p) exit(1); } break; + case 'j': + p->jitter = atoi(optarg); + break; case 'l': ul_log_domain_arg2levels(optarg); break; @@ -427,8 +433,16 @@ void *sender(void *arg) clock_gettime(CLOCK_MONOTONIC, &next_period); } __sync_fetch_and_add(&stats.sent, 1); - next_period.tv_sec += (p->period_ms/1000); - next_period.tv_nsec += (p->period_ms%1000) * 1000000; + + int delay_ms; + if (p->jitter) + delay_ms = p->period_ms*(100-p->jitter)/100 + + rand() % (2*p->period_ms*p->jitter/100); + else + delay_ms = p->period_ms; + + next_period.tv_sec += (delay_ms/1000); + next_period.tv_nsec += (delay_ms%1000) * 1000000; if (next_period.tv_nsec >= 1000000000) { next_period.tv_nsec -= 1000000000; next_period.tv_sec++; -- 2.39.2