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 network emulation

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@242 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-09-11 14:40:40 +00:00
parent 7ccecdbb1a
commit b8546f0985
2 changed files with 37 additions and 21 deletions

View file

@ -23,19 +23,6 @@ int node_connect(struct node *n)
if (n->sd < 0)
perror("Failed to create socket");
/* Set socket options */
int prio = SOCKET_PRIO;
if (setsockopt(n->sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
perror("Failed to set socket priority");
else
debug(4, "Set socket priority of node '%s' to %u", n->name, prio);
/* Set mark for outgoing packets */
if (setsockopt(n->sd, SOL_SOCKET, SO_MARK, &n->mark, sizeof(n->mark)))
perror("Failed to set mark for outgoing packets");
else
debug(4, "Set mark of outgoing packets of node '%s' to %u", n->name, n->mark);
/* Bind socket for receiving */
if (bind(n->sd, (struct sockaddr *) &n->local, sizeof(struct sockaddr_in)))
perror("Failed to bind to socket");

View file

@ -67,16 +67,45 @@ static void start()
list_add(interfaces, n->interface);
}
n->mark = 1 + n->interface->refcnt++;
/* Create queueing discipline */
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);
/* Set fwmark for outgoing packets */
if (n->netem) {
n->mark = 1 + n->interface->refcnt++;
if (setsockopt(n->sd, SOL_SOCKET, SO_MARK, &n->mark, sizeof(n->mark)))
perror("Failed to set fwmark for outgoing packets");
else
debug(4, "Set fwmark of outgoing packets of node '%s' to %u",
n->name, n->mark);
}
#if 0 /* Set QoS or TOS IP options */
int prio = SOCKET_PRIO;
if (setsockopt(n->sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
perror("Failed to set socket priority");
else
debug(4, "Set socket priority for node '%s' to %u", n->name, prio);
#else
int tos = IPTOS_LOWDELAY;
if (setsockopt(n->sd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))
perror("Failed to set type of service (QoS)");
else
debug(4, "Set QoS/TOS IP option for node '%s' to %#x", n->name, tos);
#endif
}
/* Setup network emulation */
for (struct interface *i = interfaces; i; i = i->next) {
if (i->refcnt)
tc_prio(i, TC_HDL(4000, 0), i->refcnt);
}
for (struct node *n = nodes; n; n = n->next) {
if (n->netem) {
tc_mark(n->interface, TC_HDL(4000, n->mark), n->mark);
tc_netem(n->interface, TC_HDL(4000, n->mark), n->netem);
}
}
/* Start on thread per path for asynchronous processing */