1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

moved config_parse_{socket,opal,gtfpga} to their own source files

This commit is contained in:
Steffen Vogel 2015-03-31 13:48:41 +02:00
parent 7873a8e473
commit 64e0785504
8 changed files with 138 additions and 170 deletions

View file

@ -72,10 +72,25 @@ int config_parse_global(config_setting_t *cfg, struct settings *set);
*/
int config_parse_path(config_setting_t *cfg,
struct list *paths, struct list *nodes);
/** Parse an array or single node and checks if they exist in the "nodes" section.
*
* Examples:
* out = [ "sintef", "scedu" ]
* out = "acs"
*
* @param cfg The libconfig object handle for "out".
* @param nodes The nodes will be added to this list.
* @param all This list contains all valid nodes.
*/
int config_parse_nodelist(config_setting_t *cfg, struct list *nodes, struct list *all);
/** Parse an array or single hook function.
*
* Examples:
* hooks = [ "print", "fir" ]
* hooks = "log"
**/
int config_parse_hooks(config_setting_t *cfg, struct list *hooks);
/** Parse a single node and add it to the global configuration.
@ -87,40 +102,4 @@ int config_parse_hooks(config_setting_t *cfg, struct list *hooks);
*/
int config_parse_node(config_setting_t *cfg, struct list *nodes);
/** Parse node connection details for OPAL type
*
* @param cfg A libconfig object pointing to the node.
* @param nodes Add new nodes to this linked list.
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int config_parse_opal(config_setting_t *cfg, struct node *n);
/** Parse node connection details for GTFPGA type
*
* @param cfg A libconfig object pointing to the node.
* @param n A pointer to the node structure which should be parsed.
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int config_parse_gtfpga(config_setting_t *cfg, struct node *n);
/** Parse node connection details for SOCKET type
*
* @param cfg A libconfig object pointing to the node.
* @param n A pointer to the node structure which should be parsed.
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int config_parse_socket(config_setting_t *cfg, struct node *n);
/** Parse network emulator (netem) settings.
*
* @param cfg A libconfig object containing the settings.
* @param em A pointer to the netem settings structure (part of the path structure).
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int config_parse_netem(config_setting_t *cfg, struct netem *em);
#endif /* _CFG_H_ */

View file

@ -71,6 +71,15 @@ int opal_init(int argc, char *argv[]);
*/
int opal_deinit();
/** Parse node connection details for OPAL type
*
* @param cfg A libconfig object pointing to the node.
* @param nodes Add new nodes to this linked list.
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int opal_parse(config_setting_t *cfg, struct node *n);
int opal_print(struct node *n, char *buf, int len);
int opal_print_global(struct opal_global *g);

View file

@ -67,6 +67,15 @@ int socket_write(struct node *n, struct msg *m);
*/
int socket_read(struct node *n, struct msg *m);
/** Parse node connection details for SOCKET type
*
* @param cfg A libconfig object pointing to the node.
* @param n A pointer to the node structure which should be parsed.
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int socket_parse(config_setting_t *cfg, struct node *n);
/** Print details of socket connection
*
* @param n A pointer to the node structure

View file

@ -14,6 +14,7 @@
#define _TC_H_
#include <stdint.h>
#include <libconfig.h>
/** A type alias for TC handles.
*
@ -64,6 +65,15 @@ struct netem {
int duplicate;
};
/** Parse network emulator (netem) settings.
*
* @param cfg A libconfig object containing the settings.
* @param em A pointer to the netem settings structure (part of the path structure).
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int tc_parse(config_setting_t *cfg, struct netem *em);
/** Remove all queuing disciplines and filters.
*
* @param i The interface

View file

@ -257,133 +257,3 @@ int config_parse_node(config_setting_t *cfg, struct list *nodes)
return ret;
}
#ifdef ENABLE_OPAL_ASYNC
/** @todo: Remove this global variable. */
extern struct opal_global *og;
int config_parse_opal(config_setting_t *cfg, struct node *n)
{
if (!og) {
warn("Skipping node '%s', because this server is not running as an OPAL Async process!", n->name);
return -1;
}
struct opal *o = alloc(sizeof(struct opal));
config_setting_lookup_int(cfg, "send_id", &o->send_id);
config_setting_lookup_int(cfg, "recv_id", &o->recv_id);
config_setting_lookup_bool(cfg, "reply", &o->reply);
/* Search for valid send and recv ids */
int sfound = 0, rfound = 0;
for (int i=0; i<og->send_icons; i++)
sfound += og->send_ids[i] == o->send_id;
for (int i=0; i<og->send_icons; i++)
rfound += og->send_ids[i] == o->send_id;
if (!sfound)
cerror(config_setting_get_member(cfg, "send_id"),
"Invalid send_id '%u' for node '%s'", o->send_id, n->name);
if (!rfound)
cerror(config_setting_get_member(cfg, "recv_id"),
"Invalid recv_id '%u' for node '%s'", o->recv_id, n->name);
n->opal = o;
n->opal->global = og;
n->cfg = cfg;
return 0;
}
#endif /* ENABLE_OPAL_ASYNC */
#ifdef ENABLE_GTFPGA
/** @todo Implement */
int config_parse_gtfpga(config_setting_t *cfg, struct node *n)
{
char *slot, *id;
config_setting_t *cfg_slot, *cfg_id;
struct gtfpga *g = alloc(sizeof(struct gtfpga));
pci_filter_init(NULL, &g->filter);
if (cfg_slot = config_setting_get_member(cfg, "slot")) {
if (slot = config_setting_get_string(cfg_slot)) {
if ((err = pci_filter_parse_slot(&g->filter, slot))
cerror(cfg_slot, "%s", err);
}
else
cerror(cfg_slot, "Invalid slot format");
}
if (cfg_id = config_setting_get_member(cfg, "id")) {
if (id = config_setting_get_string(cfg_id)) {
if ((err = pci_filter_parse_id(&g->filter, id))
cerror(cfg_id, "%s", err);
}
else
cerror(cfg_slot, "Invalid id format");
}
return 0;
}
#endif /* ENABLE_GTFPGA */
int config_parse_socket(config_setting_t *cfg, struct node *n)
{
const char *local, *remote;
int ret;
struct socket *s = alloc(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 = 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 = 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) {
s->netem = alloc(sizeof(struct netem));
config_parse_netem(cfg_netem, s->netem);
}
n->socket = s;
return 0;
}
int config_parse_netem(config_setting_t *cfg, struct netem *em)
{
em->valid = 0;
if (config_setting_lookup_string(cfg, "distribution", &em->distribution))
em->valid |= TC_NETEM_DISTR;
if (config_setting_lookup_int(cfg, "delay", &em->delay))
em->valid |= TC_NETEM_DELAY;
if (config_setting_lookup_int(cfg, "jitter", &em->jitter))
em->valid |= TC_NETEM_JITTER;
if (config_setting_lookup_int(cfg, "loss", &em->loss))
em->valid |= TC_NETEM_LOSS;
if (config_setting_lookup_int(cfg, "duplicate", &em->duplicate))
em->valid |= TC_NETEM_DUPL;
if (config_setting_lookup_int(cfg, "corrupt", &em->corrupt))
em->valid |= TC_NETEM_CORRUPT;
/** @todo Validate netem config values */
return 0;
}

View file

@ -12,8 +12,7 @@
#include "opal.h"
#include "utils.h"
/** @todo: delcare statice */
struct opal_global *og = NULL;
static struct opal_global *og = NULL;
int opal_init(int argc, char *argv[])
{
@ -112,6 +111,40 @@ int opal_print_global(struct opal_global *g)
return 0;
}
int opal_parse(config_setting_t *cfg, struct node *n)
{
if (!og) {
warn("Skipping node '%s', because this server is not running as an OPAL Async process!", n->name);
return -1;
}
struct opal *o = alloc(sizeof(struct opal));
config_setting_lookup_int(cfg, "send_id", &o->send_id);
config_setting_lookup_int(cfg, "recv_id", &o->recv_id);
config_setting_lookup_bool(cfg, "reply", &o->reply);
/* Search for valid send and recv ids */
int sfound = 0, rfound = 0;
for (int i=0; i<og->send_icons; i++)
sfound += og->send_ids[i] == o->send_id;
for (int i=0; i<og->send_icons; i++)
rfound += og->send_ids[i] == o->send_id;
if (!sfound)
cerror(config_setting_get_member(cfg, "send_id"),
"Invalid send_id '%u' for node '%s'", o->send_id, n->name);
if (!rfound)
cerror(config_setting_get_member(cfg, "recv_id"),
"Invalid recv_id '%u' for node '%s'", o->recv_id, n->name);
n->opal = o;
n->opal->global = og;
n->cfg = cfg;
return 0;
}
int opal_print(struct node *n, char *buf, int len)
{
struct opal *o = n->opal;

View file

@ -172,6 +172,42 @@ int socket_write(struct node *n, struct msg *m)
return 0;
}
int socket_parse(config_setting_t *cfg, struct node *n)
{
const char *local, *remote;
int ret;
struct socket *s = alloc(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 = 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 = 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) {
s->netem = alloc(sizeof(struct netem));
tc_parse(cfg_netem, s->netem);
}
n->socket = s;
return 0;
}
int socket_print_addr(char *buf, int len, struct sockaddr *sa)
{
switch (sa->sa_family) {

View file

@ -14,6 +14,28 @@
#include "if.h"
#include "tc.h"
int tc_parse(config_setting_t *cfg, struct netem *em)
{
em->valid = 0;
if (config_setting_lookup_string(cfg, "distribution", &em->distribution))
em->valid |= TC_NETEM_DISTR;
if (config_setting_lookup_int(cfg, "delay", &em->delay))
em->valid |= TC_NETEM_DELAY;
if (config_setting_lookup_int(cfg, "jitter", &em->jitter))
em->valid |= TC_NETEM_JITTER;
if (config_setting_lookup_int(cfg, "loss", &em->loss))
em->valid |= TC_NETEM_LOSS;
if (config_setting_lookup_int(cfg, "duplicate", &em->duplicate))
em->valid |= TC_NETEM_DUPL;
if (config_setting_lookup_int(cfg, "corrupt", &em->corrupt))
em->valid |= TC_NETEM_CORRUPT;
/** @todo Validate netem config values */
return 0;
}
int tc_reset(struct interface *i)
{
char cmd[128];