diff --git a/include/node.h b/include/node.h index 83521e5d0..aa36fb4cc 100644 --- a/include/node.h +++ b/include/node.h @@ -44,6 +44,9 @@ struct node /** The socket descriptor */ int sd; + /** A short identifier of the node */ + const char *name; + /** The type of this node */ enum node_type type; @@ -59,9 +62,6 @@ struct node /** Socket mark for netem, routing and filtering */ int mark; - /** A short identifier of the node */ - const char *name; - /** A pointer to the libconfig object which instantiated this node */ config_setting_t *cfg; @@ -69,7 +69,7 @@ struct node struct node *next; }; -/** Connect and bind the UDP socket of this node +/** Connect and bind the UDP socket of this node. * * @param n A pointer to the node structure * @return diff --git a/include/utils.h b/include/utils.h index 203f69f4d..ea3bcd7ad 100644 --- a/include/utils.h +++ b/include/utils.h @@ -24,19 +24,14 @@ #define CYN(str) "\x1B[36m" str "\x1B[0m" #define WHT(str) "\x1B[37m" str "\x1B[0m" +/** The log level which is passed as first argument to print() */ +enum log_level { DEBUG, INFO, WARN, ERROR }; + +/* Forward declarations */ struct settings; struct sockaddr_in; struct sockaddr; -/** The log level which is passed as first argument to print() */ -enum log_level -{ - DEBUG, - INFO, - WARN, - ERROR -}; - /** Logs variadic messages to stdout. * * @param lvl The log level @@ -73,7 +68,7 @@ int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b); * @param set A cpu bitmask * @return The opaque cpu_set_t datatype */ -cpu_set_t to_cpu_set_t(int set); +cpu_set_t to_cpu_set(int set); /** Append an element to a single linked list */ #define list_add(list, elm) do { \ diff --git a/src/cfg.c b/src/cfg.c index a2a12a654..4ee4aefce 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -123,8 +123,6 @@ int config_parse_path(config_setting_t *cfg, if (!config_setting_lookup_string(cfg, "out", &out_str)) cerror(cfg, "Missing output node for path"); - info("Loading path from '%s' to '%s'", in_str, out_str); - path->in = node_lookup_name(in_str, nodes); if (!path->in) cerror(cfg, "Invalid input node '%s'"); @@ -135,6 +133,8 @@ int config_parse_path(config_setting_t *cfg, path->cfg = cfg; + debug(3, "Loaded path from '%s' to '%s'", path->in->name, path->out->name); + if (enabled) { list_add(*paths, path); diff --git a/src/server.c b/src/server.c index 8dafb2ad9..9e6269bcb 100644 --- a/src/server.c +++ b/src/server.c @@ -45,8 +45,18 @@ static void start() for (struct node *n = nodes; n; n = n->next) { 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)); - debug(1, " We sent to node '%s' at %s:%u", n->name, inet_ntoa(n->remote.sin_addr), ntohs(n->remote.sin_port)); + /* Create queueing discipline */ + if (n->netem && n->interface->index != 1) { + tc_mark(n->interface, TC_HDL(4000, n->mark), n->mark); + tc_netem(n->interface, TC_HDL(4000, n->mark), n->netem); + } + + debug(1, " We listen for node '%s' at %s:%u", + n->name, inet_ntoa(n->local.sin_addr), + ntohs(n->local.sin_port)); + debug(1, " We sent to node '%s' at %s:%u", + n->name, inet_ntoa(n->remote.sin_addr), + ntohs(n->remote.sin_port)); } /* Start on thread per path for asynchronous processing */ @@ -66,12 +76,13 @@ static void stop() info("Stopping path: %12s " RED("=>") " %s " RED("=>") " %-12s", p->in->name, settings.name, p->out->name); + info(" %u messages received", p->received); info(" %u messages duplicated", p->duplicated); info(" %u messages delayed", p->delayed); } - /* Close all sockets we listing on */ + /* Close all sockets we listen on */ for (struct node *n = nodes; n; n = n->next) { node_disconnect(n); } @@ -136,10 +147,9 @@ int main(int argc, char *argv[]) debug(3, "Set task priority to %u", settings.priority); /* Pin threads to CPUs by setting the affinity */ - cpu_set_t cset = to_cpu_set_t(settings.affinity); - pid_t pid = getpid(); - if (sched_setaffinity(pid, sizeof(cset), &cset)) - perror("Failed to set CPU affinity"); + cpu_set_t cset = to_cpu_set(settings.affinity); + if (sched_setaffinity(0, sizeof(cset), &cset)) + perror("Failed to set CPU affinity to '%#x'", settings.affinity); else debug(3, "Set affinity to %#x", settings.affinity); diff --git a/src/utils.c b/src/utils.c index 78b63db0b..6c787ddc6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -104,11 +104,13 @@ int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b) return -1; } -cpu_set_t to_cpu_set_t(int set) +cpu_set_t to_cpu_set(int set) { cpu_set_t cset; - for (int i = 0; i < sizeof(int) * 8; i++) { + CPU_ZERO(&cset); + + for (int i = 0; i < sizeof(set) * 8; i++) { if (set & (1L << i)) CPU_SET(i, &cset); }