mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added reference counters for nodes
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@244 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
5b1038fc9d
commit
8bb14500fc
3 changed files with 21 additions and 12 deletions
|
@ -35,6 +35,10 @@ struct node
|
|||
{
|
||||
/** The socket descriptor */
|
||||
int sd;
|
||||
/** How many paths are sending / receiving from this node? */
|
||||
int refcnt;
|
||||
/** Socket mark for netem, routing and filtering */
|
||||
int mark;
|
||||
|
||||
/** A short identifier of the node, only used for configuration and logging */
|
||||
const char *name;
|
||||
|
@ -46,13 +50,9 @@ struct node
|
|||
|
||||
/** The egress interface */
|
||||
struct interface *interface;
|
||||
|
||||
/** Network emulator settings */
|
||||
struct netem *netem;
|
||||
|
||||
/** Socket mark for netem, routing and filtering */
|
||||
int mark;
|
||||
|
||||
/** A pointer to the libconfig object which instantiated this node */
|
||||
config_setting_t *cfg;
|
||||
|
||||
|
|
|
@ -119,19 +119,25 @@ int config_parse_path(config_setting_t *cfg,
|
|||
p->cfg = cfg;
|
||||
|
||||
if (enabled) {
|
||||
p->in->refcnt++;
|
||||
p->out->refcnt++;
|
||||
|
||||
list_add(*paths, p);
|
||||
|
||||
if (reverse) {
|
||||
struct path *prev = (struct path *) malloc(sizeof(struct path));
|
||||
if (!prev)
|
||||
struct path *rev = (struct path *) malloc(sizeof(struct path));
|
||||
if (!rev)
|
||||
error("Failed to allocate memory for path");
|
||||
else
|
||||
memcpy(prev, path, sizeof(struct path));
|
||||
memcpy(rev, p, sizeof(struct path));
|
||||
|
||||
prev->in = p->out; /* Swap in/out */
|
||||
prev->out = p->in;
|
||||
rev->in = p->out; /* Swap in/out */
|
||||
rev->out = p->in;
|
||||
|
||||
list_add(*paths, prev);
|
||||
rev->in->refcnt++;
|
||||
rev->out->refcnt++;
|
||||
|
||||
list_add(*paths, rev);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -36,6 +36,8 @@ static void start()
|
|||
{
|
||||
/* Connect and bind nodes to their sockets, set socket options */
|
||||
for (struct node *n = nodes; n; n = n->next) {
|
||||
if (!n->refcnt) continue;
|
||||
|
||||
/* Determine outgoing interface */
|
||||
int index = if_getegress(&n->remote);
|
||||
if (index < 0)
|
||||
|
@ -97,8 +99,9 @@ static void start()
|
|||
|
||||
/* Setup network emulation */
|
||||
for (struct interface *i = interfaces; i; i = i->next) {
|
||||
if (i->refcnt)
|
||||
tc_prio(i, TC_HDL(4000, 0), i->refcnt);
|
||||
if (!i->refcnt) continue;
|
||||
|
||||
tc_prio(i, TC_HDL(4000, 0), i->refcnt);
|
||||
}
|
||||
|
||||
for (struct node *n = nodes; n; n = n->next) {
|
||||
|
|
Loading…
Add table
Reference in a new issue