2019-01-21 11:01:25 +01:00
|
|
|
/* Rate-limiting hook.
|
|
|
|
*
|
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
|
2019-01-21 11:01:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-03-26 15:33:47 +01:00
|
|
|
#include <villas/hook.hpp>
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2019-04-12 09:50:42 +02:00
|
|
|
class LimitRateHook : public LimitHook {
|
2019-03-26 15:33:47 +01:00
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
// The timestamp which should be used for limiting.
|
|
|
|
enum { LIMIT_RATE_LOCAL, LIMIT_RATE_RECEIVED, LIMIT_RATE_ORIGIN } mode;
|
2019-03-26 15:33:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
double deadtime;
|
|
|
|
timespec last;
|
2019-03-26 15:33:47 +01:00
|
|
|
|
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
LimitRateHook(Path *p, Node *n, int fl, int prio, bool en = true)
|
|
|
|
: LimitHook(p, n, fl, prio, en), mode(LIMIT_RATE_LOCAL), deadtime(0),
|
|
|
|
last({0, 0}) {}
|
|
|
|
|
|
|
|
virtual void setRate(double rate, double maxRate = -1) {
|
|
|
|
deadtime = 1.0 / rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void parse(json_t *json);
|
|
|
|
|
|
|
|
virtual Hook::Reason process(struct Sample *smp);
|
2019-03-26 15:33:47 +01:00
|
|
|
};
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|