1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

added "deduplication" hook: do not send messages which are too similar to their precursors

This commit is contained in:
Steffen Vogel 2015-09-28 19:18:39 +02:00
parent 5155d0bd92
commit ec26e4c346
3 changed files with 36 additions and 3 deletions

View file

@ -53,10 +53,12 @@
{ "/dev/sda2", "\x53\xf6\xb5\xeb\x8b\x16\x46\xdc\x8d\x8f\x5b\x70\xb8\xc9\x1a\x2a", 0x468 } }
/* Hook function configuration */
#define HOOK_FIR_INDEX 1 /**< The first value of message should be filtered. */
#define HOOK_TS_INDEX -1 /**< The last value of message should be overwritten by a timestamp. */
#define HOOK_DECIMATE_RATIO 30 /**< Only forward every 30th message to the destination nodes. */
#define HOOK_FIR_INDEX 1 /**< The first value of message should be filtered. */
#define HOOK_TS_INDEX -1 /**< The last value of message should be overwritten by a timestamp. */
#define HOOK_DECIMATE_RATIO 30 /**< Only forward every 30th message to the destination nodes. */
#define HOOK_DEDUP_TYPE HOOK_ASYNC
#define HOOK_DEDUP_TRESH 1e-3 /**< Do not send messages when difference of values to last message is smaller than this threshold */
/** Global configuration */
struct settings {
/** Process priority (lower is better) */

View file

@ -76,6 +76,9 @@ struct hook {
* @{
*/
/** Example hook: Drop messages whose values are similiar to the previous ones */
int hook_deduplicate(struct path *);
/** Example hook: Print the message. */
int hook_print(struct path *p);

View file

@ -13,6 +13,7 @@
*********************************************************************************/
#include <string.h>
#include <math.h>
#include "timing.h"
#include "config.h"
@ -25,6 +26,33 @@
struct list hooks;
REGISTER_HOOK("deduplicate", 99, hook_deduplicate, HOOK_DEDUP_TYPE)
int hook_deduplicate(struct path *p)
{
int ret = 0;
#if HOOK_DEDUP_TYPE == HOOK_ASYNC
/** Thread local storage (TLS) is used to maintain a copy of the last run of the hook */
static __thread struct msg previous = MSG_INIT(0);
struct msg *prev = &previous;
#else
struct msg *prev = p->previous;
#endif
struct msg *cur = p->current;
for (int i = 0; i < MIN(cur->length, prev->length); i++) {
if (fabs(cur->data[i].f - prev->data[i].f) > HOOK_DEDUP_TRESH)
goto out;
}
ret = -1; /* no appreciable change in values, we will drop the packet */
out:
#if HOOK_DEDUP_TYPE == HOOK_ASYNC
memcpy(prev, cur, sizeof(struct msg)); /* save current message for next run */
#endif
return ret;
}
REGISTER_HOOK("print", 99, hook_print, HOOK_MSG)
int hook_print(struct path *p)
{