]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
fwp-timing learned -j (sending packets with jitter)
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 12 Nov 2009 13:57:29 +0000 (14:57 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 12 Nov 2009 13:57:39 +0000 (14:57 +0100)
fwp/tests/timing/fwp-timing.c

index d2518a44392b25c6f84f063b5f034899ff9f3af4..5d7726d3498d2994e2a80deaa1f19e0c6d9bdb75 100644 (file)
@@ -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 <percent> 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++;