1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/include/villas/nodes/test_rtt.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
3.4 KiB
C++
Raw Permalink Normal View History

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
*/
#pragma once
2021-05-10 00:12:30 +02:00
#include <villas/format.hpp>
#include <villas/list.hpp>
#include <villas/node.hpp>
2020-03-04 13:06:28 +01:00
#include <villas/task.hpp>
2017-07-06 23:48:19 +02:00
namespace villas {
namespace node {
2017-09-16 15:34:16 +02:00
// Forward declarations
struct Sample;
class TestRTT : public Node {
2017-09-16 15:34:16 +02:00
protected:
class Case {
friend TestRTT;
2017-09-16 15:34:16 +02:00
protected:
TestRTT *node;
2021-02-16 14:15:14 +01:00
int id;
double rate;
double
warmup; // Number of seconds to wait between before recording samples.
double cooldown; // Number of seconds to wait between tests.
unsigned values;
unsigned count; // The number of samples we send per test.
unsigned sent;
unsigned received;
unsigned missed;
unsigned count_warmup; // The number of samples we send during warmup.
unsigned sent_warmup;
unsigned received_warmup;
unsigned missed_warmup;
struct timespec started;
struct timespec stopped;
std::string filename;
std::string filename_formatted;
json_t *getMetadata();
public:
Case(TestRTT *n, int id, int rate, float warmup, float cooldown, int values,
int count, int count_warmup, const std::string &filename)
: node(n), id(id), rate(rate), warmup(warmup), cooldown(cooldown),
values(values), count(count), sent(0), received(0), missed(0),
count_warmup(count_warmup), sent_warmup(0), received_warmup(0),
missed_warmup(0), filename(filename) {};
2017-07-06 23:48:19 +02:00
int start();
int stop();
double getEstimatedDuration() const;
};
Task task; // The periodic task for test_rtt_read()
Format::Ptr formatter; // The format of the output file
FILE *stream;
2017-09-16 15:34:16 +02:00
std::list<Case> cases; // List of test cases
std::list<Case>::iterator current; // Currently running test case
2017-07-06 23:48:19 +02:00
std::string output; // The directory where we place the results.
std::string prefix; // An optional prefix in the filename.
2017-07-06 23:48:19 +02:00
bool shutdown;
virtual int _read(struct Sample *smps[], unsigned cnt);
virtual int _write(struct Sample *smps[], unsigned cnt);
public:
enum Mode {
UNKNOWN,
MIN,
MAX,
STOP_COUNT,
STOP_DURATION,
AT_LEAST_COUNT,
AT_LEAST_DURATION
};
TestRTT(const uuid_t &id = {}, const std::string &name = "")
: Node(id, name), task(), formatter(nullptr), stream(nullptr),
shutdown(false) {}
virtual ~TestRTT() {};
virtual int prepare();
2017-07-06 23:48:19 +02:00
virtual int parse(json_t *json);
2017-07-06 23:48:19 +02:00
virtual int start();
2017-07-06 23:48:19 +02:00
virtual int stop();
2017-07-06 23:48:19 +02:00
virtual std::vector<int> getPollFDs();
2017-07-06 23:48:19 +02:00
virtual const std::string &getDetails();
double getEstimatedDuration() const;
};
2017-07-06 23:48:19 +02:00
class TestRTTNodeFactory : public NodeFactory {
public:
using NodeFactory::NodeFactory;
virtual Node *make(const uuid_t &id = {}, const std::string &nme = "") {
auto *n = new TestRTT(id, nme);
init(n);
return n;
}
virtual int getFlags() const {
return (int)NodeFactory::Flags::SUPPORTS_READ |
(int)NodeFactory::Flags::SUPPORTS_WRITE |
(int)NodeFactory::Flags::SUPPORTS_POLL;
}
virtual std::string getName() const { return "test_rtt"; }
virtual std::string getDescription() const {
return "Test round-trip time with loopback";
}
virtual int start(SuperNode *sn);
};
} // namespace node
} // namespace villas