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
|
|
|
*
|
2014-06-28 06:40:52 +00:00
|
|
|
* @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-05-05 19:24:16 +00:00
|
|
|
*
|
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-05-05 19:24:16 +00:00
|
|
|
*
|
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
|
|
|
*********************************************************************************/
|
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
|
|
|
|
2019-06-30 14:46:55 +02:00
|
|
|
#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
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
2018-06-29 09:06:04 +02:00
|
|
|
#include <villas/list.h>
|
2018-10-20 14:20:06 +02:00
|
|
|
#include <villas/api.hpp>
|
|
|
|
#include <villas/web.hpp>
|
|
|
|
#include <villas/log.hpp>
|
2019-03-26 07:03:57 +01:00
|
|
|
#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>
|
2020-09-13 11:01:20 +02:00
|
|
|
#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 {
|
2018-06-28 13:42:50 +02:00
|
|
|
|
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;
|
2018-07-04 15:07:54 +02:00
|
|
|
|
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;
|
2020-09-13 11:01:20 +02:00
|
|
|
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
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-03-26 07:03:57 +01: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. */
|
2020-09-13 08:14:41 +02:00
|
|
|
double statsRate; /**< Rate at which we display the periodic stats. */
|
2019-03-26 07:03:57 +01:00
|
|
|
|
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
|
|
|
|
2019-03-26 07:03:57 +01:00
|
|
|
Config config; /** The configuration file. */
|
2014-06-05 09:34:52 +00:00
|
|
|
|
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();
|
2016-07-14 09:47:00 +02:00
|
|
|
|
2019-03-26 07:03:57 +01:00
|
|
|
/** 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.
|
|
|
|
*/
|
2019-03-26 07:03:57 +01:00
|
|
|
void parse(json_t *cfg);
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2018-07-03 21:51:48 +02:00
|
|
|
/** Check validity of super node configuration. */
|
2019-03-22 13:44:42 +01:00
|
|
|
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();
|
2019-01-21 22:11:30 +01:00
|
|
|
void start();
|
|
|
|
void stop();
|
2018-07-03 21:51:48 +02:00
|
|
|
void run();
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2019-02-24 11:13:28 +01:00
|
|
|
void preparePaths();
|
|
|
|
void prepareNodes();
|
|
|
|
|
2019-01-21 22:11:30 +01:00
|
|
|
void startPaths();
|
|
|
|
void startNodes();
|
|
|
|
void startNodeTypes();
|
|
|
|
void startInterfaces();
|
|
|
|
|
|
|
|
void stopPaths();
|
|
|
|
void stopNodes();
|
|
|
|
void stopNodeTypes();
|
|
|
|
void stopInterfaces();
|
|
|
|
|
2019-06-30 14:46:55 +02:00
|
|
|
#ifdef WITH_GRAPHVIZ
|
|
|
|
graph_t * getGraph();
|
|
|
|
#endif
|
|
|
|
|
2018-07-03 21:51:48 +02:00
|
|
|
/** Run periodic hooks of this super node. */
|
|
|
|
int periodic();
|
2017-03-12 17:01:24 -03:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
void setState(enum State st)
|
2019-02-11 16:38:20 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-09-13 11:01:20 +02:00
|
|
|
struct vlist * getPaths()
|
|
|
|
{
|
2018-10-20 14:20:06 +02:00
|
|
|
return &paths;
|
|
|
|
}
|
|
|
|
|
2020-09-13 11:01:20 +02:00
|
|
|
std::list<kernel::Interface *> & getInterfaces()
|
|
|
|
{
|
|
|
|
return interfaces;
|
2019-01-21 15:44:39 +01:00
|
|
|
}
|
|
|
|
|
2020-09-13 11:01:20 +02:00
|
|
|
enum State getState() const
|
|
|
|
{
|
2019-02-11 16:38:20 +01:00
|
|
|
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
|
2020-09-13 11:01:20 +02:00
|
|
|
Api * getApi()
|
|
|
|
{
|
2018-10-20 14:20:06 +02:00
|
|
|
return &api;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_WEB
|
2020-09-13 11:01:20 +02:00
|
|
|
Web * getWeb()
|
|
|
|
{
|
2018-10-20 14:20:06 +02:00
|
|
|
return &web;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
json_t * getConfig()
|
|
|
|
{
|
2019-03-26 07:03:57 +01:00
|
|
|
return config.root;
|
2018-10-20 14:20:06 +02:00
|
|
|
}
|
|
|
|
|
2020-09-13 11:01:20 +02:00
|
|
|
std::string getConfigUri() const
|
2018-10-20 14:20:06 +02:00
|
|
|
{
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2020-09-13 11:01:20 +02:00
|
|
|
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();
|
|
|
|
};
|
2018-08-20 19:06:24 +02:00
|
|
|
|
2020-07-08 13:43:15 +02:00
|
|
|
} /* namespace node */
|
|
|
|
} /* namespace villas */
|