/** Measure round-trip time. * * @author Steffen Vogel * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC * @license GNU General Public License (version 3) * * VILLASnode * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . *********************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct super_node sn; /** > measurement_results.m */ static int fd = STDOUT_FILENO; #define CLOCK_ID CLOCK_MONOTONIC /* Prototypes */ void test_rtt(); void quit(int signal, siginfo_t *sinfo, void *ctx) { running = 0; } void usage() { std::cout << "Usage: villas-test-rtt [OPTIONS] CONFIG NODE" << std::endl; std::cout << " CONFIG path to a configuration file" << std::endl; std::cout << " NODE name of the node which shoud be used" << std::endl; std::cout << " OPTIONS is one or more of the following options:" << std::endl; std::cout << " -c CNT send CNT messages" << std::endl; std::cout << " -f FD use file descriptor FD for result output instead of stdout" << std::endl; std::cout << " -b BKTS number of buckets for histogram" << std::endl; std::cout << " -w WMUP duration of histogram warmup phase" << std::endl; std::cout << " -h show this usage information" << std::endl; std::cout << " -V show the version of the tool" << std::endl << std::endl; print_copyright(); } int main(int argc, char *argv[]) { /* Parse Arguments */ char c, *endptr; while ((c = getopt (argc, argv, "w:h:r:f:c:b:V")) != -1) { switch (c) { case 'c': count = strtoul(optarg, &endptr, 10); goto check; case 'f': fd = strtoul(optarg, &endptr, 10); goto check; case 'w': hist_warmup = strtoul(optarg, &endptr, 10); goto check; case 'b': hist_buckets = strtoul(optarg, &endptr, 10); goto check; case 'V': print_version(); exit(EXIT_SUCCESS); case 'h': case '?': usage(); exit(c == '?' ? EXIT_FAILURE : EXIT_SUCCESS); } continue; check: if (optarg == endptr) error("Failed to parse parse option argument '-%c %s'", c, optarg); } if (argc != optind + 2) { usage(); exit(EXIT_FAILURE); } char *configfile = argv[optind]; char *nodestr = argv[optind + 1]; log_init(&sn.log, V, LOG_ALL); super_node_init(&sn); super_node_parse_uri(&sn, configfile); log_open(&sn.log); signals_init(quit); rt_init(sn.priority, sn.affinity); memory_init(sn.hugepages); node = (struct node *) list_lookup(&sn.nodes, nodestr); if (!node) error("There's no node with the name '%s'", nodestr); node_type_start(node->_vt, &sn); node_start(node); test_rtt(); node_stop(node); node_type_stop(node->_vt); super_node_destroy(&sn); return 0; } void test_rtt() { struct hist hist; struct timespec send, recv; struct sample *smp_send = (struct sample *) alloc(SAMPLE_LEN(2)); struct sample *smp_recv = (struct sample *) alloc(SAMPLE_LEN(2)); hist_init(&hist, 20, 100); /* 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, &send); unsigned release; release = 1; // release = allocated node_write(node, &smp_send, 1, &release); /* Ping */ release = 1; // release = allocated node_read(node, &smp_recv, 1, &release); /* Pong */ clock_gettime(CLOCK_ID, &recv); double rtt = time_delta(&recv, &send); if (rtt < 0) warn("Negative RTT: %f", rtt); hist_put(&hist, rtt); smp_send->sequence++; fprintf(stdout, "%10lu.%06lu%5u%10.3f%10.3f%10.3f%10.3f%10.3f\n", recv.tv_sec, recv.tv_nsec / 1000, smp_send->sequence, 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"); hist_dump_matlab(&hist, f); } else error("Invalid file descriptor: %u", fd); hist_print(&hist, 1); hist_destroy(&hist); }