mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
smaller changes for vtable based node system
This commit is contained in:
parent
65ac7424e0
commit
c552ad9caa
6 changed files with 41 additions and 149 deletions
|
@ -24,4 +24,8 @@
|
|||
#define HIST_HEIGHT 50
|
||||
#define HIST_SEQ 17
|
||||
|
||||
/* Protocol numbers */
|
||||
#define IPPROTO_S2SS 137
|
||||
#define ETH_P_S2SS 0xBABE
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
||||
|
|
|
@ -51,24 +51,4 @@ int msg_fscan(FILE *f, struct msg *m);
|
|||
*/
|
||||
void msg_random(struct msg *m);
|
||||
|
||||
/** Send a message to a node.
|
||||
*
|
||||
* @param m A pointer to the message
|
||||
* @param n A pointer to the node
|
||||
* @return
|
||||
* - 0 on success
|
||||
* - otherwise an error occured
|
||||
*/
|
||||
int msg_send(struct msg *m, struct node *n);
|
||||
|
||||
/** Receive a message from a node.
|
||||
*
|
||||
* @param m A pointer to the message
|
||||
* @param n A pointer to the node
|
||||
* @return
|
||||
* - 0 on success
|
||||
* - otherwise an error occured
|
||||
*/
|
||||
int msg_recv(struct msg *m, struct node *n);
|
||||
|
||||
#endif /* _MSG_H_ */
|
||||
|
|
|
@ -9,10 +9,7 @@
|
|||
#define _UTILS_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sched.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
@ -43,8 +40,6 @@ enum log_level { DEBUG, INFO, WARN, ERROR };
|
|||
|
||||
/* Forward declarations */
|
||||
struct settings;
|
||||
struct sockaddr_in;
|
||||
struct sockaddr;
|
||||
struct timespec;
|
||||
|
||||
/* These global variables allow changing the output style and verbosity */
|
||||
|
@ -69,16 +64,6 @@ void epoch_reset();
|
|||
*/
|
||||
void print(enum log_level lvl, const char *fmt, ...);
|
||||
|
||||
/** Resolve host/service name by local databases and/or nameservers.
|
||||
*
|
||||
* @param addr A string containing the hostname/ip and port seperated by a colon
|
||||
* @param sa A pointer to the resolved address
|
||||
* @param flags Flags for gai
|
||||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int resolve_addr(const char *addr, struct sockaddr_in *sa, int flags);
|
||||
|
||||
/** Convert integer to cpu_set_t.
|
||||
*
|
||||
* @param set A cpu bitmask
|
||||
|
|
|
@ -5,11 +5,8 @@
|
|||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "if.h"
|
||||
#include "tc.h"
|
||||
|
@ -19,6 +16,10 @@
|
|||
#include "utils.h"
|
||||
#include "hooks.h"
|
||||
|
||||
#include "socket.h"
|
||||
#include "gtfpga.h"
|
||||
#include "opal.h"
|
||||
|
||||
int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
||||
struct node **nodes, struct path **paths)
|
||||
{
|
||||
|
@ -165,33 +166,56 @@ int config_parse_node(config_setting_t *cfg, struct node **nodes)
|
|||
if (!n->name)
|
||||
cerror(cfg, "Missing node name");
|
||||
|
||||
|
||||
/** @todo Implement */
|
||||
int config_parse_opal(config_setting_t *cfg, struct node *n)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @todo Implement */
|
||||
int config_parse_gtfpga(config_setting_t *cfg, struct node *n)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_socket(config_setting_t *cfg, struct node *n)
|
||||
{
|
||||
const char *local, *remote;
|
||||
int ret;
|
||||
|
||||
struct socket *s = (struct socket *) malloc(sizeof(struct socket));
|
||||
if (!s)
|
||||
perror("Failed to allocate memory");
|
||||
|
||||
memset(s, 0, sizeof(struct socket));
|
||||
|
||||
if (!config_setting_lookup_string(cfg, "remote", &remote))
|
||||
cerror(cfg, "Missing remote address for node '%s'", n->name);
|
||||
|
||||
if (!config_setting_lookup_string(cfg, "local", &local))
|
||||
cerror(cfg, "Missing local address for node '%s'", n->name);
|
||||
|
||||
ret = resolve_addr(local, &n->local, AI_PASSIVE);
|
||||
ret = socket_parse_addr(local, (struct sockaddr *) &s->local, node_type(n), AI_PASSIVE);
|
||||
if (ret)
|
||||
cerror(cfg, "Failed to resolve local address '%s' of node '%s': %s",
|
||||
local, n->name, gai_strerror(ret));
|
||||
|
||||
ret = resolve_addr(remote, &n->remote, 0);
|
||||
ret = socket_parse_addr(remote, (struct sockaddr *) &s->remote, node_type(n), 0);
|
||||
if (ret)
|
||||
cerror(cfg, "Failed to resolve remote address '%s' of node '%s': %s",
|
||||
remote, n->name, gai_strerror(ret));
|
||||
|
||||
/** @todo Netem settings are not usable AF_UNIX */
|
||||
config_setting_t *cfg_netem = config_setting_get_member(cfg, "netem");
|
||||
if (cfg_netem) {
|
||||
n->netem = (struct netem *) malloc(sizeof(struct netem));
|
||||
config_parse_netem(cfg_netem, n->netem);
|
||||
s->netem = (struct netem *) malloc(sizeof(struct netem));
|
||||
config_parse_netem(cfg_netem, s->netem);
|
||||
}
|
||||
|
||||
n->socket = s;
|
||||
|
||||
n->cfg = cfg;
|
||||
|
||||
list_add(*nodes, n);
|
||||
|
||||
return 0;
|
||||
return CONFIG_TRUE;
|
||||
}
|
||||
|
||||
int config_parse_netem(config_setting_t *cfg, struct netem *em)
|
||||
|
|
|
@ -76,44 +76,3 @@ void msg_random(struct msg *m)
|
|||
|
||||
m->endian = MSG_ENDIAN_HOST;
|
||||
}
|
||||
|
||||
int msg_send(struct msg *m, struct node *n)
|
||||
{
|
||||
/* Convert headers to network byte order */
|
||||
m->sequence = htons(m->sequence);
|
||||
|
||||
if (sendto(n->sd, m, MSG_LEN(m->length), 0,
|
||||
(struct sockaddr *) &n->remote,
|
||||
sizeof(struct sockaddr_in)) < 0)
|
||||
perror("Failed sendto");
|
||||
|
||||
debug(10, "Message sent to node '%s': version=%u, type=%u, endian=%u, length=%u, sequence=%u",
|
||||
n->name, m->version, m->type, m->endian, m->length, ntohs(m->sequence));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int msg_recv(struct msg *m, struct node *n)
|
||||
{
|
||||
/** @todo Fix this for multiple paths calling msg_recv. */
|
||||
|
||||
/* Receive message from socket */
|
||||
if (recv(n->sd, m, sizeof(struct msg), 0) < 0) {
|
||||
if (errno == EINTR)
|
||||
return -EINTR;
|
||||
|
||||
perror("Failed recv");
|
||||
}
|
||||
|
||||
/* Convert headers to host byte order */
|
||||
m->sequence = ntohs(m->sequence);
|
||||
|
||||
/* Convert message to host endianess */
|
||||
if (m->endian != MSG_ENDIAN_HOST)
|
||||
msg_swap(m);
|
||||
|
||||
debug(10, "Message received from node '%s': version=%u, type=%u, endian=%u, length=%u, sequence=%u",
|
||||
n->name, m->version, m->type, m->endian, m->length, m->sequence);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "cfg.h"
|
||||
#include "utils.h"
|
||||
|
@ -59,69 +56,12 @@ void print(enum log_level lvl, const char *fmt, ...)
|
|||
for (int i = 0; i < _indent-1; i++)
|
||||
fprintf(stderr, GFX("\x78") " ");
|
||||
|
||||
int print_addr(struct sockaddr *sa, char *buf, size_t len)
|
||||
{
|
||||
if (!sa)
|
||||
return -1;
|
||||
|
||||
switch (sa->sa_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
|
||||
inet_ntop(sa->sa_family, sa, buf, len);
|
||||
snprintf(buf+strlen(buf), len-strlen(buf), ":%hu", ntohs(sin->sin_port))
|
||||
break;
|
||||
}
|
||||
|
||||
case AF_PACKET: {
|
||||
struct sockaddr_ll *sll = (struct sockaddr_ll *) sa;
|
||||
char ifname[IF_NAMESIZE];
|
||||
|
||||
snprintf("%#x:%#x:%#x:%#x:%#x:%#x:%hu (%s)",
|
||||
sll->sll_addr[0], sll->sll_addr[1], sll->sll_addr[2],
|
||||
sll->sll_addr[3], sll->sll_addr[4], sll->sll_addr[5],
|
||||
ntohs(sll->sll_protocol), if_indextoname(sll->sll_ifindex, ifname));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
error("Unsupported address family");
|
||||
fprintf(stderr, GFX("\x74") " ");
|
||||
}
|
||||
}
|
||||
|
||||
int parse_addr(const char *addr, struct sockaddr_in *sa, int flags)
|
||||
{
|
||||
/* Split string */
|
||||
char *tmp = strdup(addr);
|
||||
char *node = strtok(tmp, ":");
|
||||
char *service = strtok(NULL, ":");
|
||||
|
||||
if (node && !strcmp(node, "*"))
|
||||
node = NULL;
|
||||
|
||||
if (service && !strcmp(service, "*"))
|
||||
service = NULL;
|
||||
|
||||
/* Get IP */
|
||||
struct addrinfo *result;
|
||||
struct addrinfo hint = {
|
||||
.ai_flags = flags,
|
||||
.ai_family = AF_INET,
|
||||
.ai_socktype = SOCK_DGRAM,
|
||||
.ai_protocol = 0
|
||||
};
|
||||
|
||||
int ret = getaddrinfo(node, service, &hint, &result);
|
||||
if (!ret) {
|
||||
memcpy(sa, result->ai_addr, result->ai_addrlen);
|
||||
freeaddrinfo(result);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
return ret;
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue