2020-01-21 14:20:49 +01:00
|
|
|
/** The socket node-type for Layer 2, 3, 4 BSD-style sockets
|
2014-12-05 12:30:48 +01:00
|
|
|
*
|
2015-05-06 11:36:51 +02: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/>.
|
2017-03-03 20:20:13 -04:00
|
|
|
*********************************************************************************/
|
|
|
|
|
2015-09-19 18:48:00 +02:00
|
|
|
/**
|
2015-05-06 11:36:51 +02:00
|
|
|
* @addtogroup socket BSD Socket Node Type
|
2015-09-19 18:48:00 +02:00
|
|
|
* @ingroup node
|
2015-05-06 11:36:51 +02:00
|
|
|
* @{
|
2017-03-03 20:20:13 -04:00
|
|
|
*/
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2018-08-23 17:31:01 +02:00
|
|
|
#include <villas/node/config.h>
|
2018-08-23 17:37:16 +02:00
|
|
|
#include <villas/node.h>
|
2019-04-05 10:44:08 +02:00
|
|
|
#include <villas/socket_addr.h>
|
2018-05-12 15:25:29 +02:00
|
|
|
#include <villas/io.h>
|
2018-02-06 21:26:12 +01:00
|
|
|
|
2017-08-14 14:42:07 +02:00
|
|
|
/* Forward declarations */
|
2018-05-12 13:56:12 +02:00
|
|
|
struct format_type;
|
2017-08-14 14:42:07 +02:00
|
|
|
|
|
|
|
/** The maximum length of a packet which contains stuct msg. */
|
2018-12-04 10:39:31 +01:00
|
|
|
#define SOCKET_INITIAL_BUFFER_LEN (64*1024)
|
2017-08-14 14:42:07 +02:00
|
|
|
|
2014-12-05 12:30:48 +01:00
|
|
|
struct socket {
|
2018-06-29 08:37:14 +02:00
|
|
|
int sd; /**< The socket descriptor */
|
|
|
|
int verify_source; /**< Verify the source address of incoming packets against socket::remote. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2019-06-23 16:13:23 +02:00
|
|
|
enum SocketLayer layer; /**< The OSI / IP layer which should be used for this socket */
|
2015-08-07 01:24:19 +02:00
|
|
|
|
2018-05-12 13:56:12 +02:00
|
|
|
struct format_type *format;
|
2018-05-12 15:25:29 +02:00
|
|
|
struct io io;
|
2017-08-14 14:42:07 +02:00
|
|
|
|
2017-06-28 10:39:41 +02:00
|
|
|
/* Multicast options */
|
|
|
|
struct multicast {
|
2018-06-29 08:37:14 +02:00
|
|
|
int enabled; /**< Is multicast enabled? */
|
|
|
|
unsigned char loop; /** Loopback multicast packets to local host? */
|
|
|
|
unsigned char ttl; /**< The time to live for multicast packets. */
|
|
|
|
struct ip_mreq mreq; /**< A multicast group to join. */
|
2017-06-28 10:39:41 +02:00
|
|
|
} multicast;
|
2016-09-10 20:40:37 -04:00
|
|
|
|
2018-11-02 14:55:36 +01:00
|
|
|
struct {
|
|
|
|
char *buf; /**< Buffer for receiving messages */
|
|
|
|
size_t buflen;
|
2019-01-21 15:50:18 +01:00
|
|
|
union sockaddr_union saddr; /**< Remote address of the socket */
|
2018-11-02 14:55:36 +01:00
|
|
|
} in, out;
|
2014-12-05 12:30:48 +01:00
|
|
|
};
|
|
|
|
|
2015-05-06 11:48:30 +02:00
|
|
|
|
2018-07-16 08:08:17 +02:00
|
|
|
/** @see node_vtable::type_start */
|
2019-04-23 13:14:47 +02:00
|
|
|
int socket_type_start(villas::node::SuperNode *sn);
|
2015-05-06 11:48:30 +02:00
|
|
|
|
2018-07-16 08:08:17 +02:00
|
|
|
/** @see node_type::type_stop */
|
|
|
|
int socket_type_stop();
|
2015-05-06 11:48:30 +02:00
|
|
|
|
2020-01-21 14:27:28 +01:00
|
|
|
/** @see node_type::start */
|
2020-08-25 21:00:52 +02:00
|
|
|
int socket_start(struct vnode *n);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2020-01-21 14:27:28 +01:00
|
|
|
/** @see node_type::stop */
|
2020-08-25 21:00:52 +02:00
|
|
|
int socket_stop(struct vnode *n);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::write */
|
2020-08-25 21:00:52 +02:00
|
|
|
int socket_write(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::read */
|
2020-08-25 21:00:52 +02:00
|
|
|
int socket_read(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::parse */
|
2020-08-25 21:00:52 +02:00
|
|
|
int socket_parse(struct vnode *n, json_t *cfg);
|
2015-03-31 13:48:41 +02:00
|
|
|
|
2017-04-18 17:58:23 +02:00
|
|
|
/** @see node_type::print */
|
2020-08-25 21:00:52 +02:00
|
|
|
char * socket_print(struct vnode *n);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2018-06-29 08:37:14 +02:00
|
|
|
/** @} */
|