mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
moved code out of path_run() into separate functions
This commit is contained in:
parent
d50a5b40ff
commit
7da5f5a3db
3 changed files with 36 additions and 20 deletions
|
@ -27,6 +27,16 @@ struct node;
|
|||
*/
|
||||
void msg_swap(struct msg *m);
|
||||
|
||||
/** Check the consistency of a message.
|
||||
*
|
||||
* The functions checks the header fields of a message.
|
||||
*
|
||||
* @param m A pointer to the message
|
||||
* @retval 0 The message header is valid.
|
||||
* @retval <0 The message header is invalid.
|
||||
*/
|
||||
int msg_verify(struct msg *m);
|
||||
|
||||
/** Print a raw UDP message in human readable form.
|
||||
*
|
||||
* @param f The file stream
|
||||
|
|
|
@ -29,6 +29,14 @@ void msg_swap(struct msg *m)
|
|||
m->endian ^= 1;
|
||||
}
|
||||
|
||||
int msg_verify(struct msg *m)
|
||||
{
|
||||
return ((m->version == MSG_VERSION) &&
|
||||
(m->type == MSG_TYPE_DATA))
|
||||
? 0
|
||||
: -1;
|
||||
}
|
||||
|
||||
int msg_fprint(FILE *f, struct msg *m)
|
||||
{
|
||||
if (m->endian != MSG_ENDIAN_HOST)
|
||||
|
|
|
@ -79,7 +79,6 @@ static void * path_run(void *arg)
|
|||
node_start_defer(p->in);
|
||||
// FIXME: node_start_defer(p->out);
|
||||
|
||||
|
||||
/* Main thread loop */
|
||||
while (1) {
|
||||
node_read(p->in, p->current); /* Receive message */
|
||||
|
@ -87,13 +86,12 @@ static void * path_run(void *arg)
|
|||
p->received++;
|
||||
|
||||
/* Check header fields */
|
||||
if (p->current->version != MSG_VERSION ||
|
||||
p->current->type != MSG_TYPE_DATA) {
|
||||
if (msg_verify(p->current)) {
|
||||
p->invalid++;
|
||||
continue;
|
||||
continue; /* Drop message */
|
||||
}
|
||||
|
||||
/* Update histogram */
|
||||
/* Update histogram and handle wrap-around */
|
||||
int dist = (UINT16_MAX + p->current->sequence - p->previous->sequence) % UINT16_MAX;
|
||||
if (dist > UINT16_MAX / 2)
|
||||
dist -= UINT16_MAX;
|
||||
|
@ -102,23 +100,10 @@ static void * path_run(void *arg)
|
|||
|
||||
/* Handle simulation restart */
|
||||
if (p->current->sequence == 0 && abs(dist) >= 1) {
|
||||
if (p->received) {
|
||||
path_print_stats(p);
|
||||
hist_print(&p->histogram);
|
||||
}
|
||||
|
||||
path_print(p, buf, sizeof(buf));
|
||||
warn("Simulation for path %s restarted (prev->seq=%u, current->seq=%u, dist=%d)",
|
||||
buf, p->previous->sequence, p->current->sequence, dist);
|
||||
|
||||
/* Reset counters */
|
||||
p->sent = 0;
|
||||
p->received = 1;
|
||||
p->invalid = 0;
|
||||
p->skipped = 0;
|
||||
p->dropped = 0;
|
||||
|
||||
hist_reset(&p->histogram);
|
||||
path_reset(p);
|
||||
}
|
||||
else if (dist <= 0 && p->received > 1) {
|
||||
p->dropped++;
|
||||
|
@ -184,6 +169,19 @@ int path_stop(struct path *p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int path_reset(struct path *p)
|
||||
{
|
||||
p->sent = 0;
|
||||
p->received = 1;
|
||||
p->invalid = 0;
|
||||
p->skipped = 0;
|
||||
p->dropped = 0;
|
||||
|
||||
hist_reset(&p->histogram);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void path_print_stats(struct path *p)
|
||||
{
|
||||
char buf[33];
|
||||
|
@ -200,7 +198,7 @@ int path_print(struct path *p, char *buf, int len)
|
|||
strap(buf, len, "%s " MAG("=>"), p->in->name);
|
||||
|
||||
if (list_length(&p->destinations) > 1) {
|
||||
strap(buf, len " [");
|
||||
strap(buf, len, " [");
|
||||
FOREACH(&p->destinations, it)
|
||||
strap(buf, len, " %s", it->node->name);
|
||||
strap(buf, len, " ]");
|
||||
|
|
Loading…
Add table
Reference in a new issue