2014-07-14 11:49:44 +00:00
|
|
|
/** Nodes.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2015-06-02 21:53:04 +02:00
|
|
|
* @copyright 2014-2015, Institute for Automation of Complex Power Systems, EONERC
|
|
|
|
* This file is part of S2SS. All Rights Reserved. Proprietary and confidential.
|
2015-08-07 01:11:43 +02:00
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
#include "node.h"
|
2014-06-05 09:34:56 +00:00
|
|
|
#include "cfg.h"
|
2014-06-05 09:34:29 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
/* Node types */
|
2015-03-31 14:36:30 +02:00
|
|
|
#include "file.h"
|
2015-05-07 13:03:34 +02:00
|
|
|
#ifdef ENABLE_GTFPGA
|
2015-08-21 10:19:32 +02:00
|
|
|
#include "gtfpga.h"
|
2015-05-07 13:03:34 +02:00
|
|
|
#endif
|
2015-03-21 11:47:08 +01:00
|
|
|
#ifdef ENABLE_OPAL_ASYNC
|
2015-08-21 10:19:32 +02:00
|
|
|
#include "opal.h"
|
2015-03-21 11:47:08 +01:00
|
|
|
#endif
|
2015-08-22 17:42:02 +02:00
|
|
|
#ifdef ENABLE_SOCKET
|
|
|
|
#include "socket.h"
|
|
|
|
#include <netlink/route/qdisc.h>
|
|
|
|
#include <netlink/route/classifier.h>
|
|
|
|
#endif
|
2015-09-21 17:13:50 +02:00
|
|
|
#ifdef ENABLE_NGSI
|
|
|
|
#include "ngsi.h"
|
|
|
|
#include <jansson.h>
|
|
|
|
#endif
|
2014-12-05 12:39:52 +01:00
|
|
|
|
|
|
|
/** Vtable for virtual node sub types */
|
2015-09-19 15:26:30 +02:00
|
|
|
struct list node_types = LIST_INIT(NULL);
|
2014-12-05 12:39:52 +01:00
|
|
|
|
2015-05-06 11:48:30 +02:00
|
|
|
int node_init(int argc, char *argv[], struct settings *set)
|
2015-03-31 13:54:04 +02:00
|
|
|
{ INDENT
|
2015-10-09 12:50:35 +02:00
|
|
|
list_foreach(const struct node_type *vt, &node_types) {
|
2015-05-06 11:48:30 +02:00
|
|
|
if (vt->refcnt) {
|
|
|
|
info("Initializing '%s' node type", vt->name);
|
|
|
|
vt->init(argc, argv, set);
|
2015-03-31 13:54:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2015-03-31 13:54:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int node_deinit()
|
|
|
|
{ INDENT
|
|
|
|
/* De-initialize node types */
|
2015-10-09 12:50:35 +02:00
|
|
|
list_foreach(const struct node_type *vt, &node_types) {
|
2015-05-06 11:48:30 +02:00
|
|
|
if (vt->refcnt) {
|
|
|
|
info("De-initializing '%s' node type", vt->name);
|
|
|
|
vt->deinit();
|
2015-03-31 13:54:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-09 13:04:52 +02:00
|
|
|
|
2015-03-31 13:54:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
int node_start(struct node *n)
|
2015-03-21 15:29:00 +01:00
|
|
|
{ INDENT
|
2015-03-18 16:16:44 +01:00
|
|
|
if (!n->refcnt) {
|
|
|
|
warn("Node '%s' is unused. Skipping...", n->name);
|
2015-01-20 13:52:32 +00:00
|
|
|
return -1;
|
2015-03-18 16:16:44 +01:00
|
|
|
}
|
2014-12-05 12:39:52 +01:00
|
|
|
|
2015-09-22 12:58:37 +02:00
|
|
|
char *buf = node_print(n);
|
2015-10-12 18:47:52 +02:00
|
|
|
debug(1, "Starting node '%s' of type '%s' (%s)", n->name, n->_vt->name, buf);
|
2015-09-22 12:58:37 +02:00
|
|
|
free(buf);
|
2014-12-05 12:39:52 +01:00
|
|
|
|
|
|
|
{ INDENT
|
2015-10-12 18:47:52 +02:00
|
|
|
return n->_vt->open(n);
|
2014-06-05 09:34:56 +00:00
|
|
|
}
|
2014-12-05 12:39:52 +01:00
|
|
|
}
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
int node_stop(struct node *n)
|
2015-03-21 15:29:00 +01:00
|
|
|
{ INDENT
|
2014-12-05 12:39:52 +01:00
|
|
|
int ret;
|
|
|
|
info("Stopping node '%s'", n->name);
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
{ INDENT
|
2015-10-12 18:47:52 +02:00
|
|
|
ret = n->_vt->close(n);
|
2014-12-05 12:39:52 +01:00
|
|
|
}
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
return ret;
|
2014-06-05 09:34:29 +00:00
|
|
|
}
|
2015-03-18 16:18:10 +01:00
|
|
|
|
2015-03-21 15:29:00 +01:00
|
|
|
void node_reverse(struct node *n)
|
2015-03-18 16:18:10 +01:00
|
|
|
{
|
2015-10-12 18:47:52 +02:00
|
|
|
switch (n->_vt->type) {
|
2015-09-14 20:04:04 +02:00
|
|
|
#ifdef ENABLE_SOCKET
|
2015-08-07 01:24:19 +02:00
|
|
|
case BSD_SOCKET:
|
2015-03-18 16:18:10 +01:00
|
|
|
SWAP(n->socket->remote, n->socket->local);
|
|
|
|
break;
|
2015-09-14 20:04:04 +02:00
|
|
|
#endif
|
2015-08-09 23:52:44 +02:00
|
|
|
case LOG_FILE:
|
|
|
|
SWAP(n->file->path_in, n->file->path_out);
|
|
|
|
break;
|
2015-03-18 16:18:10 +01:00
|
|
|
default: { }
|
|
|
|
}
|
2015-03-21 15:29:00 +01:00
|
|
|
}
|
2015-03-21 15:23:57 +01:00
|
|
|
|
|
|
|
struct node * node_create()
|
|
|
|
{
|
|
|
|
return alloc(sizeof(struct node));
|
|
|
|
}
|
|
|
|
|
|
|
|
void node_destroy(struct node *n)
|
|
|
|
{
|
2015-10-12 18:47:52 +02:00
|
|
|
switch (n->_vt->type) {
|
2015-09-19 18:54:27 +02:00
|
|
|
#ifdef ENABLE_NGSI
|
|
|
|
case NGSI:
|
2015-09-21 17:13:50 +02:00
|
|
|
json_decref(n->ngsi->context);
|
|
|
|
free(n->ngsi->context_map);
|
2015-09-19 18:54:27 +02:00
|
|
|
break;
|
|
|
|
#endif
|
2015-08-22 17:42:02 +02:00
|
|
|
#ifdef ENABLE_SOCKET
|
2015-08-07 01:24:19 +02:00
|
|
|
case BSD_SOCKET:
|
2015-08-22 17:42:02 +02:00
|
|
|
rtnl_qdisc_put(n->socket->tc_qdisc);
|
|
|
|
rtnl_cls_put(n->socket->tc_classifier);
|
2015-08-07 01:24:19 +02:00
|
|
|
break;
|
2015-08-22 17:42:02 +02:00
|
|
|
#endif
|
2015-08-09 23:52:44 +02:00
|
|
|
case LOG_FILE:
|
|
|
|
free(n->file->path_in);
|
|
|
|
free(n->file->path_out);
|
|
|
|
break;
|
2015-03-21 15:23:57 +01:00
|
|
|
default: { }
|
|
|
|
}
|
|
|
|
|
|
|
|
free(n->socket);
|
|
|
|
free(n);
|
2015-03-18 16:18:10 +01:00
|
|
|
}
|