diff options
Diffstat (limited to 'src/tools/oping')
| -rw-r--r-- | src/tools/oping/oping.c | 14 | ||||
| -rw-r--r-- | src/tools/oping/oping_client.c | 47 | 
2 files changed, 23 insertions, 38 deletions
| diff --git a/src/tools/oping/oping.c b/src/tools/oping/oping.c index 6addbc58..18cc86ee 100644 --- a/src/tools/oping/oping.c +++ b/src/tools/oping/oping.c @@ -39,6 +39,7 @@  #define _POSIX_C_SOURCE 199506L  #define __XSI_VISIBLE   500 +#include <ouroboros/endian.h>  #include <ouroboros/fqueue.h>  #include <ouroboros/dev.h> @@ -70,10 +71,6 @@ struct c {          double rtt_avg;          double rtt_m2; -        /* needs locking */ -        struct timespec * times; -        pthread_mutex_t lock; -          pthread_t reader_pt;          pthread_t writer_pt;  } client; @@ -92,7 +89,9 @@ struct s {  struct oping_msg {          uint32_t type;          uint32_t id; -}; +        uint64_t tv_sec; +        uint64_t tv_nsec; +} __attribute__((packed));  #include "oping_client.c" @@ -177,11 +176,6 @@ int main(int argc, char ** argv)                          client.size = 64;                  } -                if (client.count > 1000000) { -                        printf("Count truncated to 1 million SDUs.\n"); -                        client.count = 1000000; -                } -                  ret = client_main();          } diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index 0117b793..d1d31242 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -68,13 +68,14 @@ void * reader(void * o)  {          struct timespec timeout = {2, 0};          struct timespec now = {0, 0}; +        struct timespec sent; -        char buf[OPING_BUF_SIZE]; +        char               buf[OPING_BUF_SIZE];          struct oping_msg * msg = (struct oping_msg *) buf; -        int fd = *((int *) o); -        int msg_len = 0; -        double ms = 0; -        double d = 0; +        int                fd      = *((int *) o); +        int                msg_len = 0; +        double             ms      = 0; +        double             d       = 0;          fccntl(fd, FLOWSRCVTIMEO, &timeout); @@ -86,12 +87,12 @@ void * reader(void * o)                  if (msg_len < 0)                          continue; -                if (ntohl(msg->type) != ECHO_REPLY) { +                if (ntoh32(msg->type) != ECHO_REPLY) {                          printf("Invalid message on fd %d.\n", fd);                          continue;                  } -                if (ntohl(msg->id) >= client.count) { +                if (ntoh32(msg->id) >= client.count) {                          printf("Invalid id.\n");                          continue;                  } @@ -100,10 +101,10 @@ void * reader(void * o)                  clock_gettime(CLOCK_MONOTONIC, &now); -                pthread_mutex_lock(&client.lock); -                ms = ts_diff_us(&client.times[ntohl(msg->id)], &now) -                        / 1000.0; -                pthread_mutex_unlock(&client.lock); +                sent.tv_sec = ntoh64(msg->tv_sec); +                sent.tv_nsec = ntoh64(msg->tv_nsec); + +                ms = ts_diff_us(&sent, &now) / 1000.0;                  printf("%d bytes from %s: seq=%d time=%.3f ms\n",                         msg_len, @@ -150,14 +151,13 @@ void * writer(void * o)          while (client.sent < client.count) {                  nanosleep(&wait, NULL); -                msg->type = htonl(ECHO_REQUEST); -                msg->id = htonl(client.sent);                  clock_gettime(CLOCK_MONOTONIC, &now); -                pthread_mutex_lock(&client.lock); -                client.times[client.sent++] = now; -                pthread_mutex_unlock(&client.lock); +                msg->type = hton32(ECHO_REQUEST); +                msg->id = hton32(client.sent++); +                msg->tv_sec = hton64(now.tv_sec); +                msg->tv_nsec = hton64(now.tv_nsec);                  if (flow_write(*fdp, buf, client.size) == -1) {                          printf("Failed to send SDU.\n"); @@ -174,12 +174,6 @@ void * writer(void * o)  static int client_init(void)  { -        client.times = malloc(sizeof(struct timespec) * client.count); -        if (client.times == NULL) { -                pthread_mutex_unlock(&client.lock); -                return -ENOMEM; -        } -          client.sent = 0;          client.rcvd = 0;          client.rtt_min = FLT_MAX; @@ -187,18 +181,15 @@ static int client_init(void)          client.rtt_avg = 0;          client.rtt_m2 = 0; -        pthread_mutex_init(&client.lock, NULL); -          return 0;  } -void client_fini(void) +static void client_fini(void)  { -        if (client.times != NULL) -                free(client.times); +        return;  } -int client_main(void) +static int client_main(void)  {          struct sigaction sig_act; | 
