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
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2015-08-22 17:42:38 +02:00
|
|
|
|
2016-06-14 01:19:17 +02:00
|
|
|
#include <villas/utils.h>
|
|
|
|
#include <villas/cfg.h>
|
|
|
|
#include <villas/path.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-02-18 10:58:17 -05:00
|
|
|
#include <villas/api.h>
|
|
|
|
#include <villas/web.h>
|
|
|
|
#include <villas/timing.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-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-05 10:06:32 -04:00
|
|
|
struct cfg cfg;
|
2014-06-10 16:57:40 +00:00
|
|
|
|
2014-12-05 12:41:06 +01:00
|
|
|
static void quit()
|
2015-03-21 18:03:29 +01:00
|
|
|
{
|
2015-03-31 18:13:43 +02:00
|
|
|
info("Stopping paths");
|
2017-03-05 10:06:32 -04:00
|
|
|
list_foreach(struct path *p, &cfg.paths) { INDENT
|
2015-10-09 12:50:35 +02:00
|
|
|
path_stop(p);
|
2015-12-11 17:56:14 +01:00
|
|
|
}
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2015-03-31 18:13:43 +02:00
|
|
|
info("Stopping nodes");
|
2017-03-05 10:06:32 -04:00
|
|
|
list_foreach(struct node *n, &cfg.nodes) { INDENT
|
2015-10-09 12:50:35 +02:00
|
|
|
node_stop(n);
|
2015-12-11 17:56:14 +01:00
|
|
|
}
|
2014-06-25 01:53:49 +00:00
|
|
|
|
2017-03-05 10:06:32 -04:00
|
|
|
cfg_deinit(&cfg);
|
|
|
|
cfg_destroy(&cfg);
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2015-10-13 16:11:58 +02:00
|
|
|
info(GRN("Goodbye!"));
|
2015-03-21 18:03:55 +01:00
|
|
|
|
2014-06-05 09:34:45 +00:00
|
|
|
_exit(EXIT_SUCCESS);
|
2014-06-05 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 12:41:06 +01:00
|
|
|
/* Setup exit handler */
|
2015-06-02 22:04:03 +02:00
|
|
|
static void signals_init()
|
2016-01-15 15:34:28 +01:00
|
|
|
{ INDENT
|
2014-12-05 12:41:06 +01:00
|
|
|
struct sigaction sa_quit = {
|
|
|
|
.sa_flags = SA_SIGINFO,
|
|
|
|
.sa_sigaction = quit
|
|
|
|
};
|
|
|
|
|
|
|
|
sigemptyset(&sa_quit.sa_mask);
|
|
|
|
sigaction(SIGINT, &sa_quit, NULL);
|
2015-06-02 22:24:44 +02:00
|
|
|
sigaction(SIGTERM, &sa_quit, NULL);
|
2014-12-05 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
2016-10-22 20:37:02 -04:00
|
|
|
static void usage()
|
2014-12-05 12:41:06 +01:00
|
|
|
{
|
2017-03-05 10:06:32 -04:00
|
|
|
printf("Usage: villas-node [CONFIG]\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
|
2015-09-21 17:12:40 +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");
|
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-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
|
|
|
|
|
|
|
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[])
|
|
|
|
{
|
|
|
|
/* 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]);
|
|
|
|
|
|
|
|
char *uri = "opal-shmem.conf";
|
2015-03-12 22:56:58 +01:00
|
|
|
#else
|
2017-03-05 11:10:10 -04:00
|
|
|
if (argc == 2) {
|
|
|
|
if (!strcmp(argv[1], "-h") ||
|
|
|
|
!strcmp(argv[1], "--help"))
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
else if (argc > 2)
|
|
|
|
usage();
|
2017-02-18 10:58:17 -05:00
|
|
|
#endif
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2017-03-05 10:06:32 -04:00
|
|
|
log_init(&cfg.log, V, LOG_ALL);
|
2015-03-21 18:03:29 +01:00
|
|
|
|
2016-06-08 23:21:42 +02:00
|
|
|
info("This is VILLASnode %s (built on %s, %s)", BLD(YEL(VERSION)),
|
2015-09-17 00:58:04 +02:00
|
|
|
BLD(MAG(__DATE__)), BLD(MAG(__TIME__)));
|
2015-03-12 22:56:58 +01:00
|
|
|
|
2015-09-17 00:55:20 +02:00
|
|
|
/* Checks system requirements*/
|
2016-03-18 12:38:28 +01:00
|
|
|
if (kernel_has_version(KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN))
|
2015-09-17 00:55:20 +02:00
|
|
|
error("Your kernel version is to old: required >= %u.%u", KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN);
|
2015-05-07 19:02:12 +02:00
|
|
|
|
2017-03-06 19:08:45 -04:00
|
|
|
signals_init(quit);
|
2016-01-15 15:34:28 +01:00
|
|
|
|
2017-03-05 10:06:32 -04:00
|
|
|
cfg_init_pre(&cfg);
|
2017-03-06 08:58:58 -04:00
|
|
|
cfg_parse_cli(&cfg, argc, argv);
|
2017-03-05 10:06:32 -04:00
|
|
|
cfg_init_post(&cfg);
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2015-03-31 18:13:43 +02:00
|
|
|
info("Starting nodes");
|
2017-03-05 10:06:32 -04:00
|
|
|
list_foreach(struct node *n, &cfg.nodes) { INDENT
|
|
|
|
int refs = list_count(&cfg.paths, (cmp_cb_t) path_uses_node, n);
|
2015-12-04 01:54:33 +01:00
|
|
|
if (refs > 0)
|
2015-11-23 16:32:24 +01:00
|
|
|
node_start(n);
|
|
|
|
else
|
2015-12-11 17:56:14 +01:00
|
|
|
warn("No path is using the node %s. Skipping...", node_name(n));
|
2015-11-23 16:32:24 +01:00
|
|
|
}
|
2014-06-05 09:35:10 +00:00
|
|
|
|
2015-03-31 18:13:43 +02:00
|
|
|
info("Starting paths");
|
2017-03-05 10:06:32 -04:00
|
|
|
list_foreach(struct path *p, &cfg.paths) { INDENT
|
2016-06-08 22:38:21 +02:00
|
|
|
if (p->enabled) {
|
2017-03-05 10:06:32 -04:00
|
|
|
path_init(p, &cfg);
|
2015-11-23 16:32:24 +01:00
|
|
|
path_start(p);
|
2016-06-08 22:38:21 +02:00
|
|
|
}
|
2015-11-23 16:32:24 +01:00
|
|
|
else
|
2015-11-29 22:45:46 +01:00
|
|
|
warn("Path %s is disabled. Skipping...", path_name(p));
|
2015-11-23 16:32:24 +01:00
|
|
|
}
|
2014-12-05 12:41:06 +01:00
|
|
|
|
2017-03-05 10:06:32 -04:00
|
|
|
if (cfg.stats > 0)
|
2016-10-22 20:43:36 -04:00
|
|
|
stats_print_header();
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2017-02-18 10:58:17 -05:00
|
|
|
struct timespec now, last = time_now();
|
|
|
|
|
|
|
|
/* Run! Until signal handler is invoked */
|
|
|
|
while (1) {
|
|
|
|
now = time_now();
|
2017-03-05 10:06:32 -04:00
|
|
|
if (cfg.stats > 0 && time_delta(&last, &now) > cfg.stats) {
|
|
|
|
list_foreach(struct path *p, &cfg.paths) {
|
2016-06-08 22:38:21 +02:00
|
|
|
hook_run(p, NULL, 0, HOOK_PERIODIC);
|
2017-02-18 10:58:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
last = time_now();
|
2015-10-14 14:52:29 +02:00
|
|
|
}
|
2017-02-18 10:58:17 -05:00
|
|
|
|
2017-03-05 10:06:32 -04:00
|
|
|
web_service(&cfg.web); /** @todo Maybe we should move this to another thread */
|
2014-07-04 09:47:28 +00:00
|
|
|
}
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|