]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
fwp-timing: Added -c flag to specify the number of messages to be sent
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 10 Nov 2009 10:50:28 +0000 (11:50 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 10 Nov 2009 10:50:28 +0000 (11:50 +0100)
fwp/tests/timing/fwp-timing.c

index 1a6c8ad8972a0e70d7c438cfba533b5226faa23b..2db8026a45bef4832624e583fc98b5337aedc2a1 100644 (file)
@@ -59,6 +59,7 @@ struct stream_params {
        struct in_addr src, dst;
        int number;
        int id;
+       int count;
 };
 
 
@@ -147,6 +148,7 @@ static struct option long_opts[] = {
     { "dest",  1, 0, 'd' },
     { "async",         0, 0, 'a' },
     { "number",        0, 0, 'n' },
+    { "count", 0, 0, 'c' },
     { 0, 0, 0, 0}
 };
 
@@ -160,6 +162,7 @@ usage(void)
        printf("  -d, --dest <ip:port> destination IP address and port\n");
        printf("  -a, --async  Send packets asynchronously\n");
        printf("  -n, --number Number of streams with the same parameters\n");
+       printf("  -c, --count Number of messages to send [infinity]\n");
        printf("  -/, --stream  New stream separator\n");
 }
 
@@ -169,7 +172,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:p:s:d:n:", long_opts, NULL)) != -1) {
+       while ((opt = getopt_long(*argc, *argv, "/ab:c:p:s:d:n:", long_opts, NULL)) != -1) {
                options_found = true;
                switch (opt) {
                case 'a':
@@ -178,6 +181,9 @@ int parse_opts(int *argc, char **argv[], struct stream_params *p)
                case 'b':
                        p->budget = atoi(optarg);
                        break;
+               case 'c':
+                       p->count = atoi(optarg);
+                       break;
                case 'p':
                        p->period_ms = atoi(optarg);
                        break;
@@ -332,7 +338,7 @@ void *sender(void *arg)
        struct timespec next_period;
        struct timespec tss;
        clock_gettime(CLOCK_MONOTONIC, &next_period);
-       while (!exit_flag) {
+       while (!exit_flag && (p->count == -1 || p->count--)) {
                clock_gettime(CLOCK_MONOTONIC, &tss);
                msg->cnt = cnt++;
                msg->ts = tss;
@@ -369,6 +375,7 @@ int main(int argc, char *argv[])
                .src.s_addr = htonl(INADDR_LOOPBACK),
                .dst.s_addr = htonl(INADDR_LOOPBACK),
                .number = 1,
+               .count = -1,
        };
        struct stream_params *p = NULL;