2017-07-06 23:48:19 +02:00
|
|
|
/* Node type: Node-type for testing Round-trip Time.
|
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-07-06 23:48:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2019-04-08 10:15:24 +02:00
|
|
|
#include <linux/limits.h>
|
2017-10-18 14:43:09 +02:00
|
|
|
#include <sys/stat.h>
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
#include <villas/exceptions.hpp>
|
2021-05-10 00:12:30 +02:00
|
|
|
#include <villas/format.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/node_compat.hpp>
|
2019-04-23 00:12:31 +02:00
|
|
|
#include <villas/nodes/test_rtt.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/sample.hpp>
|
|
|
|
#include <villas/timing.hpp>
|
2021-06-21 16:11:42 -04:00
|
|
|
#include <villas/utils.hpp>
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2020-07-04 16:22:10 +02:00
|
|
|
using namespace villas;
|
2021-05-10 00:12:30 +02:00
|
|
|
using namespace villas::node;
|
2019-06-04 16:55:38 +02:00
|
|
|
using namespace villas::utils;
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
static NodeCompatType p;
|
2019-04-08 08:59:51 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
static int test_rtt_case_start(NodeCompat *n, int id) {
|
|
|
|
auto *t = n->getData<struct test_rtt>();
|
|
|
|
struct test_rtt_case *c = (struct test_rtt_case *)list_at(&t->cases, id);
|
2017-08-27 18:02:24 +02:00
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
n->logger->info(
|
|
|
|
"Starting case #{}: filename={}, rate={}, values={}, limit={}",
|
|
|
|
t->current, c->filename_formatted, c->rate, c->values, c->limit);
|
2019-04-10 09:26:24 +02:00
|
|
|
|
2017-07-06 23:48:19 +02:00
|
|
|
// Open file
|
2021-05-10 00:12:30 +02:00
|
|
|
t->stream = fopen(c->filename_formatted, "a+");
|
|
|
|
if (!t->stream)
|
|
|
|
return -1;
|
2017-07-06 23:48:19 +02:00
|
|
|
|
|
|
|
// Start timer
|
2020-03-04 13:06:28 +01:00
|
|
|
t->task.setRate(c->rate);
|
2017-09-16 15:34:16 +02:00
|
|
|
|
|
|
|
t->counter = 0;
|
|
|
|
t->current = id;
|
2017-07-06 23:48:19 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
static int test_rtt_case_stop(NodeCompat *n, int id) {
|
2017-09-16 15:34:16 +02:00
|
|
|
int ret;
|
2021-08-10 10:12:48 -04:00
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
// Stop timer
|
2020-03-04 13:06:28 +01:00
|
|
|
t->task.stop();
|
2017-09-16 15:34:16 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
ret = fclose(t->stream);
|
2017-09-16 15:34:16 +02:00
|
|
|
if (ret)
|
2021-05-10 00:12:30 +02:00
|
|
|
throw SystemError("Failed to close file");
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
n->logger->info("Stopping case #{}", id);
|
2019-04-10 09:26:24 +02:00
|
|
|
|
2017-07-06 23:48:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
static int test_rtt_case_destroy(struct test_rtt_case *c) {
|
2019-04-08 10:15:24 +02:00
|
|
|
if (c->filename)
|
|
|
|
free(c->filename);
|
|
|
|
|
|
|
|
if (c->filename_formatted)
|
|
|
|
free(c->filename_formatted);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_prepare(NodeCompat *n) {
|
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2019-04-01 18:14:58 +02:00
|
|
|
|
2019-04-08 08:59:51 +02:00
|
|
|
unsigned max_values = 0;
|
2019-04-01 18:14:58 +02:00
|
|
|
|
2019-04-08 10:15:24 +02:00
|
|
|
// Take current for time for test case prefix
|
|
|
|
time_t ts = time(nullptr);
|
|
|
|
struct tm tm;
|
|
|
|
gmtime_r(&ts, &tm);
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
for (size_t i = 0; i < list_length(&t->cases); i++) {
|
|
|
|
struct test_rtt_case *c = (struct test_rtt_case *)list_at(&t->cases, i);
|
2019-04-01 18:14:58 +02:00
|
|
|
|
|
|
|
if (c->values > max_values)
|
|
|
|
max_values = c->values;
|
2019-04-08 10:15:24 +02:00
|
|
|
|
2020-01-21 16:26:51 +01:00
|
|
|
c->filename_formatted = new char[NAME_MAX];
|
2020-07-04 16:22:10 +02:00
|
|
|
if (!c->filename_formatted)
|
|
|
|
throw MemoryAllocationError();
|
2019-04-14 19:23:30 +02:00
|
|
|
|
2019-04-08 10:15:24 +02:00
|
|
|
strftime(c->filename_formatted, NAME_MAX, c->filename, &tm);
|
2019-04-01 18:14:58 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
n->in.signals = std::make_shared<SignalList>(max_values, SignalType::FLOAT);
|
2019-04-01 18:14:58 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_parse(NodeCompat *n, json_t *json) {
|
2017-09-16 15:34:16 +02:00
|
|
|
int ret;
|
2021-08-10 10:12:48 -04:00
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-08-27 18:02:24 +02:00
|
|
|
const char *output = ".";
|
2021-08-10 10:12:48 -04:00
|
|
|
const char *prefix = nullptr;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
std::vector<int> rates;
|
|
|
|
std::vector<int> values;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2018-08-07 18:40:32 +02:00
|
|
|
size_t i;
|
2021-05-10 00:12:30 +02:00
|
|
|
json_t *json_cases, *json_case, *json_val, *json_format = nullptr;
|
2019-04-08 08:59:51 +02:00
|
|
|
json_t *json_rates = nullptr, *json_values = nullptr;
|
2017-08-27 18:02:24 +02:00
|
|
|
json_error_t err;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-08 10:33:02 +02:00
|
|
|
t->cooldown = 0;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
// Generate list of test cases
|
2021-08-10 10:12:48 -04:00
|
|
|
ret = list_init(&t->cases);
|
2020-09-10 11:11:42 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
ret = json_unpack_ex(json, &err, 0, "{ s?: s, s?: s, s?: o, s?: F, s: o }",
|
2017-09-16 15:34:16 +02:00
|
|
|
"prefix", &prefix, "output", &output, "format",
|
2017-08-27 18:02:24 +02:00
|
|
|
&json_format, "cooldown", &t->cooldown, "cases",
|
2017-10-16 08:08:35 +02:00
|
|
|
&json_cases);
|
2017-08-27 18:02:24 +02:00
|
|
|
if (ret)
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(json, err, "node-config-node-test-rtt");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-08-27 18:02:24 +02:00
|
|
|
t->output = strdup(output);
|
2021-08-10 10:12:48 -04:00
|
|
|
t->prefix = strdup(prefix ? prefix : n->getNameShort().c_str());
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
// Initialize IO module
|
2021-05-10 00:12:30 +02:00
|
|
|
if (!json_format)
|
|
|
|
json_format = json_string("villas.binary");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
t->formatter = FormatFactory::make(json_format);
|
|
|
|
if (!t->formatter)
|
|
|
|
throw ConfigError(json, "node-config-node-test-rtt-format",
|
|
|
|
"Invalid value for setting 'format'");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
// Construct List of test cases
|
2017-10-16 08:08:35 +02:00
|
|
|
if (!json_is_array(json_cases))
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(json_cases, "node-config-node-test-rtt-format",
|
|
|
|
"The 'cases' setting must be an array.");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2018-08-07 18:40:32 +02:00
|
|
|
json_array_foreach(json_cases, i, json_case) {
|
2017-09-16 15:34:16 +02:00
|
|
|
int limit = -1;
|
|
|
|
double duration = -1; // in secs
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-10-16 08:08:35 +02:00
|
|
|
ret = json_unpack_ex(json_case, &err, 0, "{ s: o, s: o, s?: i, s?: F }",
|
|
|
|
"rates", &json_rates, "values", &json_values, "limit",
|
2017-09-16 15:34:16 +02:00
|
|
|
&limit, "duration", &duration);
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
if (limit > 0 && duration > 0)
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(
|
|
|
|
json_case, "node-config-node-test-rtt-duration",
|
|
|
|
"The settings 'duration' and 'limit' must be used exclusively");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
if (!json_is_array(json_rates) && !json_is_number(json_rates))
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(
|
|
|
|
json_case, "node-config-node-test-rtt-rates",
|
|
|
|
"The 'rates' setting must be a real or an array of real numbers");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
if (!json_is_array(json_values) && !json_is_integer(json_values))
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(
|
|
|
|
json_case, "node-config-node-test-rtt-values",
|
|
|
|
"The 'values' setting must be an integer or an array of integers");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
values.clear();
|
|
|
|
rates.clear();
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-10-16 08:08:35 +02:00
|
|
|
if (json_is_array(json_rates)) {
|
2018-08-07 18:40:32 +02:00
|
|
|
size_t j;
|
|
|
|
json_array_foreach(json_rates, j, json_val) {
|
2017-10-16 08:08:35 +02:00
|
|
|
if (!json_is_number(json_val))
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(
|
|
|
|
json_val, "node-config-node-test-rtt-rates",
|
|
|
|
"The 'rates' setting must be an array of real numbers");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
rates.push_back(json_integer_value(json_val));
|
2017-09-16 15:34:16 +02:00
|
|
|
}
|
|
|
|
} else
|
2021-01-04 21:08:04 +01:00
|
|
|
rates.push_back(json_number_value(json_rates));
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-10-16 08:08:35 +02:00
|
|
|
if (json_is_array(json_values)) {
|
2018-08-07 18:40:32 +02:00
|
|
|
size_t j;
|
|
|
|
json_array_foreach(json_values, j, json_val) {
|
2017-10-16 08:08:35 +02:00
|
|
|
if (!json_is_integer(json_val))
|
2021-02-16 14:15:14 +01:00
|
|
|
throw ConfigError(
|
|
|
|
json_val, "node-config-node-test-rtt-values",
|
|
|
|
"The 'values' setting must be an array of integers");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
values.push_back(json_integer_value(json_val));
|
2017-09-16 15:34:16 +02:00
|
|
|
}
|
2019-04-10 09:26:24 +02:00
|
|
|
} else
|
2021-01-04 21:08:04 +01:00
|
|
|
values.push_back(json_integer_value(json_values));
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
for (int rate : rates) {
|
|
|
|
for (int value : values) {
|
2020-01-21 16:26:51 +01:00
|
|
|
auto *c = new struct test_rtt_case;
|
2020-07-04 16:22:10 +02:00
|
|
|
if (!c)
|
|
|
|
throw MemoryAllocationError();
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2020-09-10 17:35:35 +02:00
|
|
|
c->filename = nullptr;
|
|
|
|
c->filename_formatted = nullptr;
|
2021-02-16 14:15:14 +01:00
|
|
|
c->node = n;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-01-04 21:08:04 +01:00
|
|
|
c->rate = rate;
|
|
|
|
c->values = value;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
if (limit > 0)
|
|
|
|
c->limit = limit;
|
|
|
|
else if (duration > 0)
|
|
|
|
c->limit = duration * c->rate;
|
|
|
|
else
|
|
|
|
c->limit = 1000; // default value
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-08 10:15:24 +02:00
|
|
|
c->filename = strf("%s/%s_values%d_rate%.0f.log", t->output, t->prefix,
|
|
|
|
c->values, c->rate);
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
list_push(&t->cases, c);
|
2017-09-16 15:34:16 +02:00
|
|
|
}
|
2017-07-06 23:48:19 +02:00
|
|
|
}
|
|
|
|
}
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_init(NodeCompat *n) {
|
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2020-03-04 13:06:28 +01:00
|
|
|
|
|
|
|
new (&t->task) Task(CLOCK_MONOTONIC);
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
t->formatter = nullptr;
|
|
|
|
|
2020-03-04 13:06:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_destroy(NodeCompat *n) {
|
2017-09-16 15:34:16 +02:00
|
|
|
int ret;
|
2021-08-10 10:12:48 -04:00
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2017-09-16 15:34:16 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
ret = list_destroy(&t->cases, (dtor_cb_t)test_rtt_case_destroy, true);
|
2017-07-06 23:48:19 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-03-04 13:06:28 +01:00
|
|
|
t->task.~Task();
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
if (t->output)
|
|
|
|
free(t->output);
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
if (t->prefix)
|
|
|
|
free(t->prefix);
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
if (t->formatter)
|
|
|
|
delete t->formatter;
|
|
|
|
|
2017-07-06 23:48:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
char *villas::node::test_rtt_print(NodeCompat *n) {
|
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
return strf("output=%s, prefix=%s, cooldown=%f, #cases=%zu", t->output,
|
|
|
|
t->prefix, t->cooldown, list_length(&t->cases));
|
2017-07-06 23:48:19 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_start(NodeCompat *n) {
|
2017-09-16 15:34:16 +02:00
|
|
|
int ret;
|
2017-10-18 14:43:09 +02:00
|
|
|
struct stat st;
|
2021-08-10 10:12:48 -04:00
|
|
|
auto *t = n->getData<struct test_rtt>();
|
|
|
|
struct test_rtt_case *c = (struct test_rtt_case *)list_first(&t->cases);
|
2017-09-16 15:34:16 +02:00
|
|
|
|
2017-10-18 14:43:09 +02:00
|
|
|
// Create folder for results if not present
|
|
|
|
ret = stat(t->output, &st);
|
|
|
|
if (ret || !S_ISDIR(st.st_mode)) {
|
|
|
|
ret = mkdir(t->output, 0777);
|
2021-02-16 14:15:14 +01:00
|
|
|
if (ret)
|
|
|
|
throw SystemError("Failed to create output directory: {}", t->output);
|
2017-10-18 14:43:09 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
t->formatter->start(n->getInputSignals(false), ~(int)SampleFlags::HAS_DATA);
|
2018-08-20 18:28:02 +02:00
|
|
|
|
2020-03-04 13:06:28 +01:00
|
|
|
t->task.setRate(c->rate);
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
t->current = -1;
|
|
|
|
t->counter = -1;
|
2017-07-06 23:48:19 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_stop(NodeCompat *n) {
|
2017-07-06 23:48:19 +02:00
|
|
|
int ret;
|
2021-08-10 10:12:48 -04:00
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2017-12-20 11:34:18 +01:00
|
|
|
if (t->counter >= 0) {
|
2021-02-16 14:15:14 +01:00
|
|
|
ret = test_rtt_case_stop(n, t->current);
|
2017-09-16 15:34:16 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
delete t->formatter;
|
2018-08-20 18:28:02 +02:00
|
|
|
|
2017-07-06 23:48:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_read(NodeCompat *n, struct Sample *const smps[],
|
|
|
|
unsigned cnt) {
|
2019-04-08 08:59:51 +02:00
|
|
|
int ret;
|
2019-04-08 10:15:49 +02:00
|
|
|
unsigned i;
|
2017-07-06 23:48:19 +02:00
|
|
|
uint64_t steps;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-08 10:15:49 +02:00
|
|
|
// Handle start/stop of new cases
|
2017-09-16 15:34:16 +02:00
|
|
|
if (t->counter == -1) {
|
2017-12-20 11:34:18 +01:00
|
|
|
if (t->current < 0) {
|
2017-09-16 15:34:16 +02:00
|
|
|
t->current = 0;
|
|
|
|
} else {
|
2021-02-16 14:15:14 +01:00
|
|
|
ret = test_rtt_case_stop(n, t->current);
|
2017-09-16 15:34:16 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
t->current++;
|
|
|
|
}
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
if ((unsigned)t->current >= list_length(&t->cases)) {
|
2021-02-16 14:15:14 +01:00
|
|
|
n->logger->info("This was the last case.");
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
n->setState(State::STOPPING);
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-02-11 16:37:59 +01:00
|
|
|
return -1;
|
2017-09-16 15:34:16 +02:00
|
|
|
} else {
|
2021-02-16 14:15:14 +01:00
|
|
|
ret = test_rtt_case_start(n, t->current);
|
2017-09-16 15:34:16 +02:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2023-09-07 11:46:39 +02:00
|
|
|
}
|
2017-09-16 15:34:16 +02:00
|
|
|
}
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
struct test_rtt_case *c =
|
|
|
|
(struct test_rtt_case *)list_at(&t->cases, t->current);
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2017-09-16 15:34:16 +02:00
|
|
|
// Wait
|
2020-03-04 13:06:28 +01:00
|
|
|
steps = t->task.wait();
|
2017-09-16 15:34:16 +02:00
|
|
|
if (steps > 1)
|
2021-02-16 14:15:14 +01:00
|
|
|
n->logger->warn("Skipped {} steps", steps - 1);
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-08 08:59:51 +02:00
|
|
|
if ((unsigned)t->counter >= c->limit) {
|
2021-02-16 14:15:14 +01:00
|
|
|
n->logger->info("Stopping case #{}", t->current);
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-08 10:33:02 +02:00
|
|
|
t->counter = -1;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-08 10:15:49 +02:00
|
|
|
if (t->cooldown) {
|
2021-02-16 14:15:14 +01:00
|
|
|
n->logger->info("Entering cooldown phase. Waiting {} seconds...",
|
|
|
|
t->cooldown);
|
2020-03-04 13:06:28 +01:00
|
|
|
t->task.setTimeout(t->cooldown);
|
2019-04-08 10:15:49 +02:00
|
|
|
}
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-10 09:26:24 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
struct timespec now = time_now();
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-10 09:26:24 +02:00
|
|
|
// Prepare samples
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
smps[i]->length = c->values;
|
|
|
|
smps[i]->sequence = t->counter;
|
|
|
|
smps[i]->ts.origin = now;
|
2019-06-23 16:13:23 +02:00
|
|
|
smps[i]->flags = (int)SampleFlags::HAS_DATA |
|
|
|
|
(int)SampleFlags::HAS_SEQUENCE |
|
|
|
|
(int)SampleFlags::HAS_TS_ORIGIN;
|
2021-08-10 10:12:48 -04:00
|
|
|
smps[i]->signals = n->getInputSignals(false);
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-10 09:26:24 +02:00
|
|
|
t->counter++;
|
|
|
|
}
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2019-04-10 09:26:24 +02:00
|
|
|
return i;
|
|
|
|
}
|
2017-07-06 23:48:19 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_write(NodeCompat *n, struct Sample *const smps[],
|
|
|
|
unsigned cnt) {
|
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2017-12-20 11:34:18 +01:00
|
|
|
|
|
|
|
if (t->current < 0)
|
|
|
|
return 0;
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
struct test_rtt_case *c =
|
|
|
|
(struct test_rtt_case *)list_at(&t->cases, t->current);
|
2017-07-06 23:48:19 +02:00
|
|
|
|
2019-04-08 08:59:51 +02:00
|
|
|
unsigned i;
|
2018-07-11 18:14:29 +02:00
|
|
|
for (i = 0; i < cnt; i++) {
|
2017-07-06 23:48:19 +02:00
|
|
|
if (smps[i]->length != c->values) {
|
2021-02-16 14:15:14 +01:00
|
|
|
n->logger->warn("Discarding invalid sample due to mismatching length: "
|
|
|
|
"expecting={}, has={}",
|
|
|
|
c->values, smps[i]->length);
|
2017-07-06 23:48:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-10 00:12:30 +02:00
|
|
|
t->formatter->print(t->stream, smps[i]);
|
2017-07-06 23:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int villas::node::test_rtt_poll_fds(NodeCompat *n, int fds[]) {
|
|
|
|
auto *t = n->getData<struct test_rtt>();
|
2017-09-04 14:39:15 +02:00
|
|
|
|
2020-03-04 13:06:28 +01:00
|
|
|
fds[0] = t->task.getFD();
|
2019-01-21 15:47:34 +01:00
|
|
|
|
|
|
|
return 1;
|
2017-08-30 00:25:42 +02:00
|
|
|
}
|
|
|
|
|
2019-04-08 08:59:51 +02:00
|
|
|
__attribute__((constructor(110))) static void register_plugin() {
|
2021-06-21 16:11:42 -04:00
|
|
|
p.name = "test_rtt";
|
|
|
|
p.description = "Test round-trip time with loopback";
|
|
|
|
p.vectorize = 0;
|
2021-08-10 10:12:48 -04:00
|
|
|
p.flags = (int)NodeFactory::Flags::PROVIDES_SIGNALS;
|
2021-06-21 16:11:42 -04:00
|
|
|
p.size = sizeof(struct test_rtt);
|
|
|
|
p.parse = test_rtt_parse;
|
|
|
|
p.prepare = test_rtt_prepare;
|
|
|
|
p.init = test_rtt_init;
|
|
|
|
p.destroy = test_rtt_destroy;
|
|
|
|
p.print = test_rtt_print;
|
|
|
|
p.start = test_rtt_start;
|
|
|
|
p.stop = test_rtt_stop;
|
|
|
|
p.read = test_rtt_read;
|
|
|
|
p.write = test_rtt_write;
|
2023-09-07 11:46:39 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
static NodeCompatFactory ncp(&p);
|
2019-04-08 08:59:51 +02:00
|
|
|
}
|