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
|
2022-12-14 17:41:58 +01:00
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2022-07-04 18:20:03 +02:00
|
|
|
* @license Apache 2.0
|
2017-03-03 20:20:13 -04:00
|
|
|
*********************************************************************************/
|
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/node/config.hpp>
|
|
|
|
#include <villas/socket_addr.hpp>
|
2021-05-10 00:12:30 +02:00
|
|
|
#include <villas/format.hpp>
|
2017-08-14 14:42:07 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2021-06-21 16:11:42 -04:00
|
|
|
/* Forward declarations */
|
2021-08-10 10:12:48 -04:00
|
|
|
class NodeCompat;
|
2021-06-21 16:11:42 -04:00
|
|
|
|
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
|
|
|
|
2021-08-10 10:12:48 -04: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
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
Format *formatter;
|
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
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_type_start(SuperNode *sn);
|
2015-05-06 11:48:30 +02:00
|
|
|
|
2018-07-16 08:08:17 +02:00
|
|
|
int socket_type_stop();
|
2015-05-06 11:48:30 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_init(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_destroy(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_start(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_check(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_stop(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_reverse(NodeCompat *n);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_fds(NodeCompat *n, int fds[]);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_write(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_read(NodeCompat *n, struct Sample * const smps[], unsigned cnt);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_parse(NodeCompat *n, json_t *json);
|
2015-03-31 13:48:41 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
char * socket_print(NodeCompat *n);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|