diff --git a/server/src/random.c b/server/src/random.c index 97f02e7b0..735b55282 100644 --- a/server/src/random.c +++ b/server/src/random.c @@ -54,12 +54,17 @@ int main(int argc, char *argv[]) serror("Failed to start timer"); /* Print header */ - fprintf(stderr, "# %-6s%-12s\n", "seq", "data"); + fprintf(stderr, "# %-20s\t%s\t%s\n", "timestamp", "seqno", "data[]"); /* Block until 1/p->rate seconds elapsed */ - m.sequence += (uint16_t) timerfd_wait(tfd); - for (;;) { + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + + m.sequence += timerfd_wait(tfd); + m.ts.sec = ts.tv_sec; + m.ts.nsec = ts.tv_nsec; + msg_random(&m); msg_fprint(stdout, &m); diff --git a/server/src/receive.c b/server/src/receive.c index f2d17deb7..2f9f74e56 100644 --- a/server/src/receive.c +++ b/server/src/receive.c @@ -86,7 +86,6 @@ int main(int argc, char *argv[]) usage(argv[0]); /* Setup signals */ - struct timespec ts; struct sigaction sa_quit = { .sa_flags = SA_SIGINFO, .sa_sigaction = quit @@ -117,14 +116,14 @@ int main(int argc, char *argv[]) pool = alloc(sizeof(struct msg) * node->combine); /* Print header */ - fprintf(stderr, "# %-6s %-8s %-12s\n", "dev_id", "seq_no", "data"); + fprintf(stderr, "# %-20s\t%s\t%s\n", "timestamp", "seqno", "data[]"); for (;;) { int recv = node_read(node, pool, node->combine, 0, node->combine); - for (int i = 0; i < recv; i++) { - if (msg_verify(&pool[i])) - warn("Failed to verify message"); + int ret = msg_verify(&pool[i]); + if (ret) + warn("Failed to verify message: %d", ret); msg_fprint(stdout, &pool[i]); } diff --git a/server/src/socket.c b/server/src/socket.c index 11b0e1542..693af3c3d 100644 --- a/server/src/socket.c +++ b/server/src/socket.c @@ -208,7 +208,7 @@ int socket_read(struct node *n, struct msg *pool, int poolsize, int first, int c struct msg *n = &pool[(first+poolsize+i) % poolsize]; /* Check integrity of packet */ - bytes -= MSG_LEN(n->length); + bytes -= MSG_LEN(n); /* Convert headers to host byte order */ n->sequence = ntohs(n->sequence); @@ -243,7 +243,7 @@ int socket_write(struct node *n, struct msg *pool, int poolsize, int first, int n->sequence = htons(n->sequence); iov[i].iov_base = n; - iov[i].iov_len = MSG_LEN(n->length); + iov[i].iov_len = MSG_LEN(n); } /* Specify destination address for connection-less procotols */ diff --git a/server/src/test.c b/server/src/test.c index a86381250..a2e2763cb 100644 --- a/server/src/test.c +++ b/server/src/test.c @@ -157,21 +157,17 @@ check: void test_rtt() { struct msg m = MSG_INIT(sizeof(struct timespec) / sizeof(float)); + + struct timespec ts; struct timespec *ts1 = (struct timespec *) &m.data; struct timespec *ts2 = alloc(sizeof(struct timespec)); double rtt; - double rtt_max = LLONG_MIN; - double rtt_min = LLONG_MAX; - double avg = 0; + struct hist hist; + hist_create(&hist, low, high, res); - struct hist histogram; - hist_create(&histogram, low, high, res); - -#if 1 /* Print header */ - fprintf(stdout, "%17s", "timestamp"); -#endif - fprintf(stdout, "%5s%10s%10s%10s%10s\n", "seq", "rtt", "min", "max", "avg"); + /* Print header */ + fprintf(stdout, "%17s%5s%10s%10s%10s%10s%10s\n", "timestamp", "seq", "rtt", "min", "max", "mean", "stddev"); while (running && (count < 0 || count--)) { clock_gettime(CLOCK_ID, ts1); @@ -181,36 +177,32 @@ void test_rtt() { rtt = time_delta(ts1, ts2); - if (rtt < 0) continue; - if (rtt > rtt_max) rtt_max = rtt; - if (rtt < rtt_min) rtt_min = rtt; - - avg += rtt; + if (rtt < 0) + warn("Negative RTT: %f", rtt); - hist_put(&histogram, rtt); + hist_put(&hist, rtt); -#if 1 - struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - fprintf(stdout, "%17.6f", ts.tv_sec + ts.tv_nsec / 1e9); -#endif + time_fprint(stdout, &ts); + m.sequence++; - fprintf(stdout, "%5u%10.3f%10.3f%10.3f%10.3f\n", m.sequence, - 1e3 * rtt, 1e3 * rtt_min, 1e3 * rtt_max, 1e3 * avg / m.sequence); + fprintf(stdout, "%5u%10.3f%10.3f%10.3f%10.3f%10.3f\n", m.sequence, + 1e3 * rtt, 1e3 * hist.lowest, 1e3 * hist.highest, + 1e3 * hist_mean(&hist), 1e3 * hist_stddev(&hist)); } free(ts2); - hist_print(&histogram); + hist_print(&hist); struct stat st; if (!fstat(fd, &st)) { FILE *f = fdopen(fd, "w"); - hist_matlab(&histogram, f); + hist_matlab(&hist, f); } else error("Invalid file descriptor: %u", fd); - hist_destroy(&histogram); + hist_destroy(&hist); }