diff --git a/server/include/path.h b/server/include/path.h index 586ab2509..1d332b399 100644 --- a/server/include/path.h +++ b/server/include/path.h @@ -39,16 +39,19 @@ struct path /** A pointer to the last received message */ struct msg *last; - /** Counter for received messages */ - unsigned int received; - /** Counter for messages which arrived reordered */ - unsigned int delayed; - /** Counter for messages which arrived multiple times */ - unsigned int duplicated; /** Last known message number */ unsigned int sequence; + + /** Counter for sent messages */ + unsigned long sent; + /** Counter for received messages */ + unsigned long received; + /** Counter for messages which arrived reordered */ + unsigned long delayed; + /** Counter for messages which arrived multiple times */ + unsigned long duplicated; /** Counter for received messages with invalid device id or data */ - unsigned int invalid; + unsigned long invalid; /** The thread id for this path */ pthread_t tid; diff --git a/server/src/path.c b/server/src/path.c index 50d2cc5ea..3350d7813 100644 --- a/server/src/path.c +++ b/server/src/path.c @@ -22,6 +22,7 @@ /** Send messages */ static void * path_send(void *arg) { + int sig; struct path *p = (struct path *) arg; timer_t tmr; sigset_t set; @@ -49,10 +50,12 @@ static void * path_send(void *arg) perror("Failed to start timer"); while (1) { - int sig; sigwait(&set, &sig); - - msg_send(p->last, p->out); + if (p->last) { + msg_send(p->last, p->out); + p->last = NULL; + p->sent++; + } } return NULL; @@ -64,39 +67,42 @@ static void * path_run(void *arg) struct path *p = (struct path *) arg; struct msg m; - p->last = &m; - /* Main thread loop */ while (1) { msg_recv(&m, p->in); /* Receive message */ - /* Check message sequence number */ - if (m.sequence < p->sequence) { - p->delayed++; + p->received++; - /* Delayed messages will be skipped */ - continue; + if (m.sequence == 0 && p->sequence > 0) { + path_stats(p); + info("Simulation restarted"); + + p->sequence = 0; + p->received = 0; + p->sent = 0; + p->delayed = 0; + p->duplicated = 0; + p->invalid = 0; + } + else if (m.sequence < p->sequence) { + p->delayed++; } else if (m.sequence == p->sequence) { p->duplicated++; } - p->sequence = m.sequence; - p->received++; - /* Call hook */ - if (p->hook && p->hook(&m)) { - /* The hook can act as a simple filter - * Returning a non-zero value will skip - * the message from being forwarded */ + if (p->hook && p->hook(&m)) continue; - } /* At fixed rate mode, messages are send by another thread */ if (p->rate) - continue; + p->last = &m; + else + msg_send(p->last, p->out); - msg_send(p->last, p->out); + p->sequence = m.sequence; + p->sent++; } return NULL; @@ -126,8 +132,9 @@ int path_stop(struct path *p) void path_stats(struct path *p) { - info("%12s " MAG("=>") " %-12s: %-8u %-8u %-8u", + info("%12s " MAG("=>") " %-12s: %-8u %-8u %-8u %-8u %-8u", p->in->name, p->out->name, - p->received, p->delayed, - p->duplicated); + p->sent, p->received, p->delayed, + p->duplicated, p->invalid + ); } diff --git a/server/src/random.c b/server/src/random.c index c98282bf5..f8ee7fb35 100644 --- a/server/src/random.c +++ b/server/src/random.c @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) timer_create(CLOCKID, &sev, &t); timer_settime(t, 0, &its, NULL); - while(1) pause(); + while (1) pause(); timer_delete(t); diff --git a/server/src/send.c b/server/src/send.c index 94b900221..714fe8172 100644 --- a/server/src/send.c +++ b/server/src/send.c @@ -40,13 +40,13 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - struct node n; + struct node n = { + .name = "node" + }; struct msg m = { .length = atoi(argv[1]) * sizeof(double) }; - memset(&n, 0, sizeof(struct node)); - /* Setup signals */ struct sigaction sa_quit = { .sa_flags = SA_SIGINFO, diff --git a/server/src/server.c b/server/src/server.c index 09c90b872..a18c47e95 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -85,7 +85,6 @@ static void stop() /* Join all threads and print statistics */ for (struct path *p = paths; p; p = p->next) { path_stop(p); - path_stats(p); info("Stopping path: %12s " RED("=>") " %-12s", p->in->name, p->out->name); @@ -181,9 +180,9 @@ int main(int argc, char *argv[]) info(""); info("Runtime Statistics:"); - info("%12s " MAG("=>") " %-12s: %-8s %-8s %-8s", - "Source", "Destination", "#Recv", "#Delay", "#Duplicated"); - info("--------------------------------------------------------------"); + info("%12s " MAG("=>") " %-12s: %-8s %-8s %-8s %-8s %-8s", + "Source", "Destination", "#Sent", "#Recv", "#Delay", "#Dupl", "#Inval"); + info("---------------------------------------------------------------------------"); while (1) { sleep(5);