1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/src/test-rtt.c

181 lines
4.2 KiB
C
Raw Normal View History

/** Measure round-trip time.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2015-06-02 21:53:04 +02:00
*********************************************************************************/
#include <stdlib.h>
2015-06-03 10:13:35 +02:00
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/stat.h>
#include <villas/super_node.h>
2016-11-20 02:45:39 -05:00
#include <villas/node.h>
#include <villas/utils.h>
#include <villas/hist.h>
#include <villas/timing.h>
#include <villas/pool.h>
#include <villas/kernel/rt.h>
struct super_node sn; /** <The global configuration */
static struct node *node;
/* Test options */
2016-02-04 17:13:01 +01:00
static int running = 1; /**< Initiate shutdown if zero */
static int count = -1; /**< Amount of messages which should be sent (default: -1 for unlimited) */
/** File descriptor for Matlab results.
* This allows you to write Matlab results in a seperate log file:
*
* ./test etc/example.conf rtt -f 3 3>> measurement_results.m
*/
2015-06-02 22:04:03 +02:00
static int fd = STDOUT_FILENO;
2015-12-13 00:46:22 +01:00
/* Histogram */
static double low = 0; /**< Lowest value in histogram. */
static double high = 2e-4; /**< Highest value in histogram. */
static double res = 1e-5; /**< Histogram resolution. */
#define CLOCK_ID CLOCK_MONOTONIC
/* Prototypes */
void test_rtt();
2017-03-06 19:09:44 -04:00
void quit(int signal, siginfo_t *sinfo, void *ctx)
{
running = 0;
}
2016-10-22 20:37:02 -04:00
void usage()
{
printf("Usage: villas-test-rtt CONFIG NODE [ARGS]\n");
printf(" CONFIG path to a configuration file\n");
printf(" NODE name of the node which shoud be used\n");
printf(" ARGS the following optional options:\n");
printf(" -c CNT send CNT messages\n");
printf(" -f FD use file descriptor FD for result output instead of stdout\n");
printf(" -l LOW smallest value for histogram\n");
printf(" -H HIGH largest value for histogram\n");
printf(" -r RES bucket resolution for histogram\n");
printf(" -h show this usage information\n");
printf("\n");
print_copyright();
}
int main(int argc, char *argv[])
{
if (argc < 4) {
2016-10-22 20:37:02 -04:00
usage();
exit(EXIT_FAILURE);
}
log_init(&sn.log, V, LOG_ALL);
super_node_init(&sn);
super_node_parse_uri(&sn, argv[1]);
2017-03-06 19:08:45 -04:00
signals_init(quit);
rt_init(sn.priority, sn.affinity);
memory_init(sn.hugepages);
node = list_lookup(&sn.nodes, argv[3]);
if (!node)
error("There's no node with the name '%s'", argv[3]);
node_type_start(node->_vt, &sn);
node_start(node);
2015-08-07 01:11:43 +02:00
/* Parse Arguments */
char c, *endptr;
while ((c = getopt (argc-3, argv+3, "l:hH:r:f:c:")) != -1) {
switch (c) {
case 'c':
count = strtoul(optarg, &endptr, 10);
goto check;
case 'f':
fd = strtoul(optarg, &endptr, 10);
goto check;
case 'l':
low = strtod(optarg, &endptr);
goto check;
case 'H':
high = strtod(optarg, &endptr);
goto check;
case 'r':
res = strtod(optarg, &endptr);
goto check;
case 'h':
case '?':
usage();
exit(c == '?' ? EXIT_FAILURE : EXIT_SUCCESS);
}
2015-08-07 01:11:43 +02:00
continue;
check: if (optarg == endptr)
error("Failed to parse parse option argument '-%c %s'", c, optarg);
}
test_rtt();
node_stop(node);
node_type_stop(node->_vt);
super_node_destroy(&sn);
return 0;
}
void test_rtt() {
2015-06-02 22:43:57 +02:00
struct hist hist;
2016-06-08 22:38:21 +02:00
struct timespec send, recv;
2016-06-08 22:38:21 +02:00
struct sample *smp_send = alloc(SAMPLE_LEN(2));
struct sample *smp_recv = alloc(SAMPLE_LEN(2));
hist_init(&hist, low, high, res);
2015-06-02 22:43:57 +02:00
/* Print header */
fprintf(stdout, "%17s%5s%10s%10s%10s%10s%10s\n", "timestamp", "seq", "rtt", "min", "max", "mean", "stddev");
while (running && (count < 0 || count--)) {
2016-06-08 22:38:21 +02:00
clock_gettime(CLOCK_ID, &send);
2016-06-08 22:38:21 +02:00
node_write(node, &smp_send, 1); /* Ping */
node_read(node, &smp_recv, 1); /* Pong */
clock_gettime(CLOCK_ID, &recv);
2016-06-08 22:38:21 +02:00
double rtt = time_delta(&recv, &send);
2015-06-02 22:43:57 +02:00
if (rtt < 0)
warn("Negative RTT: %f", rtt);
2015-08-07 01:11:43 +02:00
2015-06-02 22:43:57 +02:00
hist_put(&hist, rtt);
2016-06-08 22:38:21 +02:00
smp_send->sequence++;
fprintf(stdout, "%10lu.%06lu%5u%10.3f%10.3f%10.3f%10.3f%10.3f\n",
2016-06-08 22:38:21 +02:00
recv.tv_sec, recv.tv_nsec / 1000, smp_send->sequence,
2015-06-02 22:43:57 +02:00
1e3 * rtt, 1e3 * hist.lowest, 1e3 * hist.highest,
1e3 * hist_mean(&hist), 1e3 * hist_stddev(&hist));
}
struct stat st;
if (!fstat(fd, &st)) {
FILE *f = fdopen(fd, "w");
2016-10-22 20:37:02 -04:00
hist_dump_matlab(&hist, f);
}
else
error("Invalid file descriptor: %u", fd);
2015-08-07 01:11:43 +02:00
hist_print(&hist, 1);
2015-06-02 22:43:57 +02:00
hist_destroy(&hist);
}