diff options
Diffstat (limited to 'src/tools/oping/oping_client.c')
| -rw-r--r-- | src/tools/oping/oping_client.c | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index 6f874dd9..7b03c83d 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros ping application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -65,10 +65,13 @@ void * reader(void * o) int msg_len = 0; double ms = 0; double d = 0; + uint32_t exp_id = 0; fccntl(fd, FLOWSRCVTIMEO, &timeout); while (!stop && client.rcvd != client.count) { + uint32_t id; + msg_len = flow_read(fd, buf, OPING_BUF_SIZE); if (msg_len == -ETIMEDOUT) { printf("Server timed out.\n"); @@ -84,7 +87,8 @@ void * reader(void * o) continue; } - if ((uint32_t) ntohl(msg->id) >= client.count) { + id = (uint32_t) ntohl(msg->id); + if (id >= client.count) { printf("Invalid id.\n"); continue; } @@ -98,11 +102,25 @@ void * reader(void * o) ms = ts_diff_us(&sent, &now) / 1000.0; - printf("%d bytes from %s: seq=%d time=%.3f ms\n", - msg_len, - client.s_apn, - ntohl(msg->id), - ms); + if (id < exp_id) + ++client.ooo; + + if (!client.quiet) { + if (client.timestamp) { + struct timespec rtc; + clock_gettime(CLOCK_REALTIME, &rtc); + printf("[%zd.%06zu] ", + (ssize_t) rtc.tv_sec, + (size_t) rtc.tv_nsec / 1000); + } + + printf("%d bytes from %s: seq=%d time=%.3f ms%s\n", + msg_len, + client.s_apn, + ntohl(msg->id), + ms, + id < exp_id ? " [out-of-order]" : ""); + } if (ms < client.rtt_min) client.rtt_min = ms; @@ -112,6 +130,9 @@ void * reader(void * o) d = (ms - client.rtt_avg); client.rtt_avg += d / client.rcvd; client.rtt_m2 += d * (ms - client.rtt_avg); + + if (id >= exp_id) + exp_id = id + 1; } return (void *) 0; @@ -129,17 +150,20 @@ void * writer(void * o) if (buf == NULL) return (void *) -ENOMEM; - if (fdp == NULL) + if (fdp == NULL) { + free(buf); return (void *) -EINVAL; + } memset(buf, 0, client.size); msg = (struct oping_msg *) buf; - printf("Pinging %s with %d bytes of data:\n\n", - client.s_apn, client.size); + if (!client.quiet) + printf("Pinging %s with %d bytes of data (%u packets):\n\n", + client.s_apn, client.size, client.count); - pthread_cleanup_push((void (*) (void *)) free, buf); + pthread_cleanup_push(free, buf); while (!stop && client.sent < client.count) { nanosleep(&wait, NULL); @@ -151,11 +175,9 @@ void * writer(void * o) msg->tv_sec = now.tv_sec; msg->tv_nsec = now.tv_nsec; - if (flow_write(*fdp, buf, client.size) == -1) { - printf("Failed to send SDU.\n"); - flow_dealloc(*fdp); - free(buf); - return (void *) -1; + if (flow_write(*fdp, buf, client.size) < 0) { + printf("Failed to send packet.\n"); + stop = true; } } @@ -208,13 +230,15 @@ static int client_main(void) return -1; } - fd = flow_alloc(client.s_apn, NULL, NULL); + fd = flow_alloc(client.s_apn, &client.qs, NULL); if (fd < 0) { - printf("Failed to allocate flow.\n"); + printf("Failed to allocate flow: %d.\n", fd); client_fini(); return -1; } + fccntl(fd, FLOWSFLAGS, FLOWFRDWR | FLOWFRNOPART); + clock_gettime(CLOCK_REALTIME, &tic); pthread_create(&client.reader_pt, NULL, reader, &fd); @@ -227,8 +251,9 @@ static int client_main(void) printf("\n"); printf("--- %s ping statistics ---\n", client.s_apn); - printf("%d SDUs transmitted, ", client.sent); + printf("%d packets transmitted, ", client.sent); printf("%d received, ", client.rcvd); + printf("%zd out-of-order, ", client.ooo); printf("%.0lf%% packet loss, ", client.sent == 0 ? 0 : ceil(100 - (100 * (client.rcvd / (float) client.sent)))); printf("time: %.3f ms\n", ts_diff_us(&tic, &toc) / 1000.0); |
