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

fixed interface intialization if not interface is up

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@134 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-07-04 15:58:10 +00:00
parent 3678f6773b
commit bbe2a6a02e
4 changed files with 44 additions and 46 deletions

View file

@ -34,13 +34,12 @@ struct settings {
* @param set The global configuration structure
* @param nodes A linked list of nodes which should be parsed
* @param paths A linked list of paths which should be parsed
* @param interfaces A linked list of interfaces which should be parsed
* @return
* - 0 on success
* - otherwise an error occured
*/
int config_parse(const char *filename, config_t *cfg, struct settings *set,
struct node **nodes, struct path **paths, struct interface **interfaces);
struct node **nodes, struct path **paths);
/** Parse the global section of a configuration file.
*
@ -68,13 +67,12 @@ int config_parse_path(config_setting_t *cfg,
*
* @param cfg A libconfig object pointing to the node
* @param nodes Add new nodes to this linked list
* @param interfaces Search this list for existing interfaces
* @return
* - 0 on success
* - otherwise an error occured
*/
int config_parse_node(config_setting_t *cfg,
struct node **nodes, struct interface **interfaces);
struct node **nodes);
/** Parse network emulator (netem) settings
*

View file

@ -19,7 +19,7 @@
#include "utils.h"
int config_parse(const char *filename, config_t *cfg, struct settings *set,
struct node **nodes, struct path **paths, struct interface **interfaces)
struct node **nodes, struct path **paths)
{
config_set_auto_convert(cfg, 1);
@ -50,7 +50,7 @@ int config_parse(const char *filename, config_t *cfg, struct settings *set,
/* Parse nodes */
for (int i = 0; i < config_setting_length(cfg_nodes); i++) {
config_setting_t *cfg_node = config_setting_get_elem(cfg_nodes, i);
config_parse_node(cfg_node, nodes, interfaces);
config_parse_node(cfg_node, nodes);
}
/* Parse paths */
@ -131,8 +131,7 @@ int config_parse_path(config_setting_t *cfg,
return 0;
}
int config_parse_node(config_setting_t *cfg,
struct node **nodes, struct interface **interfaces)
int config_parse_node(config_setting_t *cfg, struct node **nodes)
{
const char *remote_str = NULL;
const char *local_str = NULL;
@ -170,21 +169,6 @@ int config_parse_node(config_setting_t *cfg,
config_parse_netem(cfg_netem, node->netem);
}
/* Determine outgoing interface */
int index = if_getegress(&node->remote);
struct interface *i = if_lookup_index(index, *interfaces);
if (!i) {
i = malloc(sizeof(struct interface));
memset(i, 0, sizeof(struct interface));
i->index = index;
list_add(*interfaces, i);
}
node->mark = 1 + i->refcnt++;
node->interface = i;
node->cfg = cfg;
list_add(*nodes, node);

View file

@ -32,16 +32,14 @@ int if_getegress(struct sockaddr_in *sa)
if (!p)
return -1;
while (fscanf(p, "%31s", token)) {
while (!feof(p) && fscanf(p, "%31s", token)) {
if (!strcmp(token, "dev")) {
fscanf(p, "%31s", token);
break;
}
}
fclose(p);
return if_nametoindex(token);
return (WEXITSTATUS(fclose(p))) ? -1 : if_nametoindex(token);
}
int if_getirqs(struct interface *i)

View file

@ -37,32 +37,50 @@ static config_t config;
static void start()
{
/* Configure interfaces */
for (struct interface *i = interfaces; i; i = i->next) {
if_indextoname(i->index, i->name);
debug(3, "Setup interface '%s'",
i->name, i->index, i->refcnt);
if (settings.affinity) {
if_getirqs(i);
if_setaffinity(i, settings.affinity);
}
/* Create priority queuing discipline */
tc_prio(i, TC_HDL(4000, 0), i->refcnt);
}
/* Connect and bind nodes to their sockets, set socket options */
for (struct node *n = nodes; n; n = n->next) {
node_connect(n);
/* Determine outgoing interface */
int index = if_getegress(&n->remote);
if (index < 0)
error("Failed to get egress interface for node '%s'", n->name);
n->interface = if_lookup_index(index, interfaces);
/* Create new interface */
if (!n->interface) {
n->interface = malloc(sizeof(struct interface));
if (!n->interface)
error("Failed to allocate memory for interface");
else
memset(n->interface, 0, sizeof(struct interface));
n->interface->index = index;
if_indextoname(index, n->interface->name);
debug(3, "Setup interface '%s'", n->interface->name,
n->interface->index, n->interface->refcnt);
if (settings.affinity) {
if_getirqs(n->interface);
if_setaffinity(n->interface, settings.affinity);
}
/* Create priority queuing discipline */
tc_prio(n->interface, TC_HDL(4000, 0), n->interface->refcnt);
list_add(interfaces, n->interface);
}
n->mark = 1 + n->interface->refcnt++;
/* Create queueing discipline */
if (n->netem) {
if (n->netem && n->mark) {
tc_mark(n->interface, TC_HDL(4000, n->mark), n->mark);
tc_netem(n->interface, TC_HDL(4000, n->mark), n->netem);
}
node_connect(n);
debug(1, " We listen for node '%s' at %s:%u",
n->name, inet_ntoa(n->local.sin_addr),
ntohs(n->local.sin_port));
@ -145,7 +163,7 @@ int main(int argc, char *argv[])
/* Parse configuration file */
config_init(&config);
config_parse(argv[1], &config, &settings, &nodes, &paths, &interfaces);
config_parse(argv[1], &config, &settings, &nodes, &paths);
/* Check for realtime kernel patch */
struct stat st;