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/super_node.hpp

208 lines
4 KiB
C++
Raw Permalink Normal View History

/** The super node object holding the state of the application.
*
* @file
2015-06-02 21:53:04 +02:00
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @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.
*
2017-04-27 12:56:43 +02:00
* 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.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-06-02 21:53:04 +02:00
*********************************************************************************/
2017-02-16 09:04:12 -03:00
#pragma once
#include <villas/node/config.h>
#ifdef WITH_GRAPHVIZ
2020-03-04 13:59:46 +01:00
extern "C" {
2021-02-19 06:38:38 +01:00
#include <graphviz/gvc.h>
2020-03-04 13:59:46 +01:00
}
#endif
#include <fstream>
#include <villas/list.h>
2018-10-20 14:20:06 +02:00
#include <villas/api.hpp>
#include <villas/web.hpp>
#include <villas/log.hpp>
#include <villas/config.hpp>
2018-07-03 21:51:48 +02:00
#include <villas/node.h>
2020-03-04 13:07:20 +01:00
#include <villas/task.hpp>
#include <villas/common.hpp>
#include <villas/kernel/if.hpp>
2017-02-18 10:31:42 -05:00
2019-04-23 13:14:47 +02:00
/* Forward declarations */
2020-08-25 21:00:52 +02:00
struct vnode;
2019-04-23 13:14:47 +02:00
2018-07-03 21:51:48 +02:00
namespace villas {
namespace node {
2017-02-18 10:31:42 -05:00
/** Global configuration */
2018-07-03 21:51:48 +02:00
class SuperNode {
protected:
2019-06-23 16:13:23 +02:00
enum State state;
2019-02-12 15:07:50 +01:00
int idleStop;
2019-01-17 20:28:20 +01:00
Logger logger;
2018-10-20 14:20:06 +02:00
2019-01-07 10:28:55 +01:00
struct vlist nodes;
struct vlist 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
Api api;
#endif
#ifdef WITH_WEB
Web web;
#endif
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. */
2020-03-04 13:06:28 +01:00
struct Task task; /**< Task for periodic stats output */
2017-08-05 21:02:09 +02:00
2020-10-15 14:47:43 +02:00
uuid_t uuid; /**< A globally unique identifier of the instance */
struct timespec started; /**< The time at which the instance has been started. */
2018-10-20 14:20:06 +02:00
std::string uri; /**< URI of configuration */
2017-02-18 10:31:42 -05:00
Config config; /** The configuration file. */
2018-07-03 21:51:48 +02:00
public:
/** Inititalize configuration object before parsing the configuration. */
SuperNode();
2016-02-04 16:27:14 +01:00
2018-07-03 21:51:48 +02:00
int init();
/** Wrapper for parse() which loads the config first. */
void parse(const std::string &name);
2017-02-18 10:31:42 -05:00
2018-07-03 21:51:48 +02:00
/** Parse super-node configuration.
*
* @param cfg A libjansson object which contains the configuration.
*/
void parse(json_t *cfg);
2018-07-03 21:51:48 +02:00
/** Check validity of super node configuration. */
void check();
2017-03-06 08:59:28 -04:00
2018-07-03 21:51:48 +02:00
/** Initialize after parsing the configuration file. */
2019-02-24 11:13:28 +01:00
void prepare();
void start();
void stop();
2018-07-03 21:51:48 +02:00
void run();
2019-02-24 11:13:28 +01:00
void preparePaths();
void prepareNodes();
void startPaths();
void startNodes();
void startNodeTypes();
void startInterfaces();
void stopPaths();
void stopNodes();
void stopNodeTypes();
void stopInterfaces();
#ifdef WITH_GRAPHVIZ
graph_t * getGraph();
#endif
2018-07-03 21:51:48 +02:00
/** Run periodic hooks of this super node. */
int periodic();
2019-06-23 16:13:23 +02:00
void setState(enum State st)
{
state = st;
}
2020-08-25 21:00:52 +02:00
struct vnode * getNode(const std::string &name)
2018-10-20 14:20:06 +02:00
{
2020-08-25 21:00:52 +02:00
return vlist_lookup_name<struct vnode>(&nodes, name);
2018-10-20 14:20:06 +02:00
}
2019-01-07 10:28:55 +01:00
struct vlist * getNodes()
2018-10-20 14:20:06 +02:00
{
return &nodes;
}
struct vlist * getPaths()
{
2018-10-20 14:20:06 +02:00
return &paths;
}
std::list<kernel::Interface *> & getInterfaces()
{
return interfaces;
}
enum State getState() const
{
return state;
}
2020-10-15 14:47:43 +02:00
void getUUID(uuid_t out) const
{
uuid_copy(out, uuid);
}
struct timespec getStartTime() const
{
return started;
}
2018-10-20 14:20:06 +02:00
#ifdef WITH_API
Api * getApi()
{
2018-10-20 14:20:06 +02:00
return &api;
}
#endif
#ifdef WITH_WEB
Web * getWeb()
{
2018-10-20 14:20:06 +02:00
return &web;
}
#endif
json_t * getConfig()
{
return config.root;
2018-10-20 14:20:06 +02:00
}
std::string getConfigUri() const
2018-10-20 14:20:06 +02:00
{
return uri;
}
int getAffinity() const
{
return affinity;
}
2018-10-20 14:20:06 +02:00
/** Destroy configuration object. */
2018-07-03 21:51:48 +02:00
~SuperNode();
};
2020-07-08 13:43:15 +02:00
} /* namespace node */
} /* namespace villas */