2017-08-03 00:19:27 +02:00
|
|
|
/* The super node object holding the state of the application.
|
2014-06-05 09:34:32 +00:00
|
|
|
*
|
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
|
2015-06-02 21:53:04 +02:00
|
|
|
*/
|
2014-06-05 09:34:32 +00:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-06-05 09:34:32 +00:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/node/config.hpp>
|
2019-06-30 14:46:55 +02:00
|
|
|
|
|
|
|
#ifdef WITH_GRAPHVIZ
|
2020-03-04 13:59:46 +01:00
|
|
|
extern "C" {
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <graphviz/gvc.h>
|
2020-03-04 13:59:46 +01:00
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
2018-10-20 14:20:06 +02:00
|
|
|
#include <villas/api.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/common.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/config_class.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/kernel/if.hpp>
|
|
|
|
#include <villas/log.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/node.hpp>
|
2021-06-21 16:12:47 -04:00
|
|
|
#include <villas/node_list.hpp>
|
|
|
|
#include <villas/path_list.hpp>
|
2020-03-04 13:07:20 +01:00
|
|
|
#include <villas/task.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/web.hpp>
|
2017-02-18 10:31:42 -05:00
|
|
|
|
2018-07-03 21:51:48 +02:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
2018-06-28 13:42:50 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
// Forward declarations
|
|
|
|
class Node;
|
|
|
|
|
2017-02-18 10:31:42 -05:00
|
|
|
// Global configuration
|
2018-07-03 21:51:48 +02:00
|
|
|
class SuperNode {
|
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
enum State state;
|
2018-07-04 15:07:54 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int idleStop;
|
2019-02-12 15:07:50 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
Logger logger;
|
2018-10-20 14:20:06 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
NodeList nodes;
|
|
|
|
PathList paths;
|
|
|
|
std::list<kernel::Interface *> interfaces;
|
2017-02-18 10:31:42 -05:00
|
|
|
|
2018-10-20 14:20:06 +02:00
|
|
|
#ifdef WITH_API
|
2023-09-07 11:46:39 +02:00
|
|
|
Api api;
|
2018-10-20 14:20:06 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_WEB
|
2023-09-07 11:46:39 +02:00
|
|
|
Web web;
|
2018-10-20 14:20:06 +02:00
|
|
|
#endif
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int priority; // Process priority (lower is better)
|
|
|
|
int affinity; // Process affinity of the server and all created threads
|
|
|
|
int hugepages; // Number of hugepages to reserve.
|
|
|
|
double statsRate; // Rate at which we display the periodic stats.
|
2019-03-26 07:03:57 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct Task task; // Task for periodic stats output
|
2017-08-05 21:02:09 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
uuid_t uuid; // A globally unique identifier of the instance
|
2020-10-15 14:47:43 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct timespec started; // The time at which the instance has been started.
|
2020-10-15 14:47:43 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::string uri; // URI of configuration
|
2017-02-18 10:31:42 -05:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
Config config; // The configuration file.
|
2014-06-05 09:34:52 +00:00
|
|
|
|
2018-07-03 21:51:48 +02:00
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
// Inititalize configuration object before parsing the configuration.
|
|
|
|
SuperNode();
|
2016-02-04 16:27:14 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int init();
|
2016-07-14 09:47:00 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Wrapper for parse() which loads the config first.
|
|
|
|
void parse(const std::string &name);
|
2017-02-18 10:31:42 -05:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Parse super-node configuration.
|
2018-07-03 21:51:48 +02:00
|
|
|
*
|
2021-02-16 14:15:14 +01:00
|
|
|
* @param json A libjansson object which contains the configuration.
|
2018-07-03 21:51:48 +02:00
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
void parse(json_t *json);
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Check validity of super node configuration.
|
|
|
|
void check();
|
2017-03-06 08:59:28 -04:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Initialize after parsing the configuration file.
|
|
|
|
void prepare();
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
void run();
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void preparePaths();
|
|
|
|
void prepareNodes();
|
|
|
|
void prepareNodeTypes();
|
2019-02-24 11:13:28 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void startPaths();
|
|
|
|
void startNodes();
|
|
|
|
void startInterfaces();
|
2019-01-21 22:11:30 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void stopPaths();
|
|
|
|
void stopNodes();
|
|
|
|
void stopNodeTypes();
|
|
|
|
void stopInterfaces();
|
2019-01-21 22:11:30 +01:00
|
|
|
|
2019-06-30 14:46:55 +02:00
|
|
|
#ifdef WITH_GRAPHVIZ
|
2023-09-07 11:46:39 +02:00
|
|
|
graph_t *getGraph();
|
2019-06-30 14:46:55 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Run periodic hooks of this super node.
|
|
|
|
int periodic();
|
|
|
|
|
|
|
|
void setState(enum State st) { state = st; }
|
|
|
|
|
|
|
|
Node *getNode(const std::string &name) { return nodes.lookup(name); }
|
|
|
|
|
|
|
|
NodeList &getNodes() { return nodes; }
|
|
|
|
|
|
|
|
PathList &getPaths() { return paths; }
|
|
|
|
|
|
|
|
std::list<kernel::Interface *> &getInterfaces() { return interfaces; }
|
|
|
|
|
|
|
|
enum State getState() const { return state; }
|
|
|
|
|
|
|
|
const uuid_t &getUuid() const { return uuid; }
|
|
|
|
|
|
|
|
struct timespec getStartTime() const { return started; }
|
2020-10-15 14:47:43 +02:00
|
|
|
|
2018-10-20 14:20:06 +02:00
|
|
|
#ifdef WITH_API
|
2023-09-07 11:46:39 +02:00
|
|
|
Api *getApi() { return &api; }
|
2018-10-20 14:20:06 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_WEB
|
2023-09-07 11:46:39 +02:00
|
|
|
Web *getWeb() { return &web; }
|
2018-10-20 14:20:06 +02:00
|
|
|
#endif
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
json_t *getConfig() { return config.root; }
|
2018-10-20 14:20:06 +02:00
|
|
|
|
2023-12-12 14:15:55 +01:00
|
|
|
std::filesystem::path &getConfigPath() { return config.getConfigPath(); }
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::string getConfigUri() const { return uri; }
|
2018-10-20 14:20:06 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int getAffinity() const { return affinity; }
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
Logger getLogger() { return logger; }
|
2021-02-16 14:15:14 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// Destroy configuration object.
|
|
|
|
~SuperNode();
|
2018-07-03 21:51:48 +02:00
|
|
|
};
|
2018-08-20 19:06:24 +02:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|