2014-07-14 11:49:44 +00:00
|
|
|
/** Main routine.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, 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:29 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2015-08-22 17:42:38 +02:00
|
|
|
|
2016-06-14 01:19:17 +02:00
|
|
|
#include <villas/utils.h>
|
2017-03-12 17:01:24 -03:00
|
|
|
#include <villas/super_node.h>
|
2016-11-20 02:45:16 -05:00
|
|
|
#include <villas/memory.h>
|
2016-06-14 01:19:17 +02:00
|
|
|
#include <villas/node.h>
|
2017-03-17 01:08:48 -03:00
|
|
|
#include <villas/path.h>
|
2017-02-18 10:58:17 -05:00
|
|
|
#include <villas/api.h>
|
|
|
|
#include <villas/web.h>
|
2017-08-27 18:44:03 +02:00
|
|
|
#include <villas/task.h>
|
2017-03-03 20:21:33 -04:00
|
|
|
#include <villas/plugin.h>
|
2016-06-14 01:19:17 +02:00
|
|
|
#include <villas/kernel/kernel.h>
|
2016-06-26 15:27:14 +02:00
|
|
|
#include <villas/kernel/rt.h>
|
2016-11-20 13:11:37 -05:00
|
|
|
#include <villas/hook.h>
|
2017-03-12 17:01:24 -03:00
|
|
|
#include <villas/stats.h>
|
2017-02-18 10:58:17 -05:00
|
|
|
|
2015-03-17 22:46:46 +01:00
|
|
|
#ifdef ENABLE_OPAL_ASYNC
|
2016-11-20 02:45:39 -05:00
|
|
|
#include <villas/nodes/opal.h>
|
2015-03-17 22:46:46 +01:00
|
|
|
#endif
|
|
|
|
|
2017-03-29 04:25:30 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2017-03-12 17:01:24 -03:00
|
|
|
struct super_node sn;
|
2014-06-10 16:57:40 +00:00
|
|
|
|
2017-03-06 19:09:44 -04:00
|
|
|
static void quit(int signal, siginfo_t *sinfo, void *ctx)
|
2015-03-21 18:03:29 +01:00
|
|
|
{
|
2017-07-12 00:59:52 +02:00
|
|
|
int ret;
|
|
|
|
|
2017-07-12 00:56:08 +02:00
|
|
|
if (sn.stats > 0)
|
|
|
|
stats_print_footer(STATS_FORMAT_HUMAN);
|
2017-07-23 16:15:03 +02:00
|
|
|
|
2017-07-12 00:59:52 +02:00
|
|
|
ret = super_node_stop(&sn);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to stop super node");
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2017-07-12 00:59:52 +02:00
|
|
|
ret = super_node_destroy(&sn);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to destroy super node");
|
2015-03-21 18:03:55 +01:00
|
|
|
|
2017-07-12 00:59:52 +02:00
|
|
|
info(CLR_GRN("Goodbye!"));
|
2017-04-24 18:59:12 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
2014-06-05 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-22 20:37:02 -04:00
|
|
|
static void usage()
|
2014-12-05 12:41:06 +01:00
|
|
|
{
|
2017-09-16 11:52:30 +02:00
|
|
|
printf("Usage: villas-node [OPTIONS] [CONFIG]\n");
|
|
|
|
printf(" OPTIONS is one or more of the following options:\n");
|
|
|
|
printf(" -V show the version of the tool\n");
|
|
|
|
printf(" -h show this help\n");
|
2017-02-18 10:58:17 -05:00
|
|
|
printf(" CONFIG is the path to an optional configuration file\n");
|
|
|
|
printf(" if omitted, VILLASnode will start without a configuration\n");
|
|
|
|
printf(" and wait for provisioning over the web interface.\n\n");
|
2015-03-17 22:46:46 +01:00
|
|
|
#ifdef ENABLE_OPAL_ASYNC
|
2017-03-05 10:06:32 -04:00
|
|
|
printf("Usage: villas-node OPAL_ASYNC_SHMEM_NAME OPAL_ASYNC_SHMEM_SIZE OPAL_PRINT_SHMEM_NAME\n");
|
2015-03-17 22:46:46 +01:00
|
|
|
printf(" This type of invocation is used by OPAL-RT Asynchronous processes.\n");
|
|
|
|
printf(" See in the RT-LAB User Guide for more information.\n\n");
|
|
|
|
#endif
|
2017-08-05 21:02:09 +02:00
|
|
|
|
2017-07-23 16:15:03 +02:00
|
|
|
printf("Supported node-types:\n");
|
2017-03-03 20:21:33 -04:00
|
|
|
plugin_dump(PLUGIN_TYPE_NODE);
|
2015-08-22 17:42:38 +02:00
|
|
|
printf("\n");
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2016-06-08 22:38:21 +02:00
|
|
|
printf("Supported hooks:\n");
|
2017-03-03 20:21:33 -04:00
|
|
|
plugin_dump(PLUGIN_TYPE_HOOK);
|
2016-06-08 22:38:21 +02:00
|
|
|
printf("\n");
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-02-18 10:58:17 -05:00
|
|
|
printf("Supported API commands:\n");
|
2017-03-03 20:21:33 -04:00
|
|
|
plugin_dump(PLUGIN_TYPE_API);
|
2017-02-18 10:58:17 -05:00
|
|
|
printf("\n");
|
2016-01-15 15:25:22 +01:00
|
|
|
|
2017-08-05 21:02:09 +02:00
|
|
|
printf("Supported IO formats:\n");
|
2017-08-14 14:42:07 +02:00
|
|
|
plugin_dump(PLUGIN_TYPE_IO);
|
2017-08-05 21:02:09 +02:00
|
|
|
printf("\n");
|
|
|
|
|
2016-01-15 15:25:22 +01:00
|
|
|
print_copyright();
|
2015-03-21 18:16:28 +01:00
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
2014-12-05 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2017-08-27 18:44:03 +02:00
|
|
|
int ret;
|
|
|
|
|
2014-12-05 12:41:06 +01:00
|
|
|
/* Check arguments */
|
2015-03-17 22:46:46 +01:00
|
|
|
#ifdef ENABLE_OPAL_ASYNC
|
2017-02-18 10:58:17 -05:00
|
|
|
if (argc != 4)
|
|
|
|
usage(argv[0]);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-09-16 11:52:30 +02:00
|
|
|
opal_register_region(argc, argv);
|
|
|
|
|
2017-02-18 10:58:17 -05:00
|
|
|
char *uri = "opal-shmem.conf";
|
2015-03-12 22:56:58 +01:00
|
|
|
#else
|
2017-09-16 11:52:30 +02:00
|
|
|
char c;
|
|
|
|
while ((c = getopt(argc, argv, "hV")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'V':
|
|
|
|
print_version();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
exit(c == '?' ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
2017-03-05 11:10:10 -04:00
|
|
|
}
|
2017-09-16 11:52:30 +02:00
|
|
|
|
|
|
|
char *uri = argc == optind + 1 ? argv[optind] : NULL;
|
2017-02-18 10:58:17 -05:00
|
|
|
#endif
|
2017-09-16 11:52:30 +02:00
|
|
|
|
2017-07-12 00:50:29 +02:00
|
|
|
info("This is VILLASnode %s (built on %s, %s)", CLR_BLD(CLR_YEL(BUILDID)),
|
|
|
|
CLR_BLD(CLR_MAG(__DATE__)), CLR_BLD(CLR_MAG(__TIME__)));
|
2015-03-12 22:56:58 +01:00
|
|
|
|
2017-07-24 19:21:57 +02:00
|
|
|
#ifdef __linux__
|
2015-09-17 00:55:20 +02:00
|
|
|
/* Checks system requirements*/
|
2017-04-02 02:33:20 +02:00
|
|
|
struct version kver, reqv = { KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN };
|
|
|
|
if (kernel_get_version(&kver) == 0 && version_cmp(&kver, &reqv) < 0)
|
2015-09-17 00:55:20 +02:00
|
|
|
error("Your kernel version is to old: required >= %u.%u", KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN);
|
2017-07-24 19:21:57 +02:00
|
|
|
#endif /* __linux__ */
|
2015-05-07 19:02:12 +02:00
|
|
|
|
2017-08-27 18:44:03 +02:00
|
|
|
ret = signals_init(quit);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to initialize signal subsystem");
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-27 18:44:03 +02:00
|
|
|
ret = super_node_init(&sn);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to initialize super node");
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-09-16 11:52:30 +02:00
|
|
|
ret = super_node_parse_uri(&sn, uri);
|
2017-08-27 18:44:03 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to parse command line arguments");
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-27 18:44:03 +02:00
|
|
|
ret = super_node_check(&sn);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to verify configuration");
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-27 18:44:03 +02:00
|
|
|
ret = super_node_start(&sn);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to start super node");
|
2014-12-05 12:41:06 +01:00
|
|
|
|
2017-08-27 18:44:03 +02:00
|
|
|
if (sn.stats > 0) {
|
2017-07-12 00:56:08 +02:00
|
|
|
stats_print_header(STATS_FORMAT_HUMAN);
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2017-08-27 18:44:03 +02:00
|
|
|
struct task t;
|
2017-09-02 14:20:38 +02:00
|
|
|
|
2017-08-27 18:44:03 +02:00
|
|
|
ret = task_init(&t, 1.0 / sn.stats, CLOCK_REALTIME);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to create stats timer");
|
2017-07-28 18:25:54 +02:00
|
|
|
|
|
|
|
for (;;) {
|
2017-09-16 15:33:01 +02:00
|
|
|
task_wait(&t);
|
2017-07-28 18:25:54 +02:00
|
|
|
|
2017-03-25 21:23:31 +01:00
|
|
|
for (size_t i = 0; i < list_length(&sn.paths); i++) {
|
|
|
|
struct path *p = list_at(&sn.paths, i);
|
2017-07-23 16:15:03 +02:00
|
|
|
|
2017-07-12 00:59:01 +02:00
|
|
|
if (p->state != STATE_STARTED)
|
|
|
|
continue;
|
2017-03-25 21:23:31 +01:00
|
|
|
|
|
|
|
for (size_t j = 0; j < list_length(&p->hooks); j++) {
|
|
|
|
struct hook *h = list_at(&p->hooks, j);
|
|
|
|
|
2017-03-27 12:50:01 +02:00
|
|
|
hook_periodic(h);
|
2017-03-25 21:23:31 +01:00
|
|
|
}
|
2017-02-18 10:58:17 -05:00
|
|
|
}
|
2017-09-02 14:27:58 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < list_length(&sn.nodes); i++) {
|
|
|
|
struct node *n = list_at(&sn.nodes, i);
|
|
|
|
|
|
|
|
if (n->state != STATE_STARTED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (size_t j = 0; j < list_length(&n->hooks); j++) {
|
|
|
|
struct hook *h = list_at(&n->hooks, j);
|
|
|
|
|
|
|
|
hook_periodic(h);
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 14:52:29 +02:00
|
|
|
}
|
2014-07-04 09:47:28 +00:00
|
|
|
}
|
2017-07-28 18:25:54 +02:00
|
|
|
else {
|
|
|
|
for (;;)
|
|
|
|
pause();
|
|
|
|
}
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|