TSCH: reduce keep-alive traffic as we get more accurate drift estimates

This commit is contained in:
Simon Duquennoy 2016-06-23 18:43:12 +02:00 committed by Simon Duquennoy
parent ab706a6f33
commit 15dc86aeb1
3 changed files with 31 additions and 7 deletions

View file

@ -38,8 +38,10 @@
* *
*/ */
#include "tsch-adaptive-timesync.h" #include "net/mac/tsch/tsch.h"
#include "tsch-log.h" #include "net/mac/tsch/tsch-conf.h"
#include "net/mac/tsch/tsch-adaptive-timesync.h"
#include "net/mac/tsch/tsch-log.h"
#include <stdio.h> #include <stdio.h>
#if TSCH_ADAPTIVE_TIMESYNC #if TSCH_ADAPTIVE_TIMESYNC
@ -72,6 +74,10 @@ timesync_entry_add(int32_t val, uint32_t time_delta)
buffer[pos] = val; buffer[pos] = val;
if(timesync_entry_count < NUM_TIMESYNC_ENTRIES) { if(timesync_entry_count < NUM_TIMESYNC_ENTRIES) {
timesync_entry_count++; timesync_entry_count++;
} else {
/* We now have accurate drift compensation.
* Increase keep-alive timeout. */
tsch_set_ka_timeout(TSCH_MAX_KEEPALIVE_TIMEOUT);
} }
pos = (pos + 1) % NUM_TIMESYNC_ENTRIES; pos = (pos + 1) % NUM_TIMESYNC_ENTRIES;

View file

@ -151,6 +151,8 @@ uint8_t tsch_join_priority;
static uint8_t tsch_packet_seqno = 0; static uint8_t tsch_packet_seqno = 0;
/* Current period for EB output */ /* Current period for EB output */
static clock_time_t tsch_current_eb_period; static clock_time_t tsch_current_eb_period;
/* Current period for keepalive output */
static clock_time_t tsch_current_ka_timeout;
/* timer for sending keepalive messages */ /* timer for sending keepalive messages */
static struct ctimer keepalive_timer; static struct ctimer keepalive_timer;
@ -187,6 +189,12 @@ tsch_set_join_priority(uint8_t jp)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
tsch_set_ka_timeout(uint32_t timeout)
{
tsch_current_ka_timeout = timeout;
}
/*---------------------------------------------------------------------------*/
void
tsch_set_eb_period(uint32_t period) tsch_set_eb_period(uint32_t period)
{ {
tsch_current_eb_period = MIN(period, TSCH_MAX_EB_PERIOD); tsch_current_eb_period = MIN(period, TSCH_MAX_EB_PERIOD);
@ -256,10 +264,10 @@ keepalive_send()
void void
tsch_schedule_keepalive() tsch_schedule_keepalive()
{ {
/* Pick a delay in the range [TSCH_KEEPALIVE_TIMEOUT*0.9, TSCH_KEEPALIVE_TIMEOUT[ */ /* Pick a delay in the range [tsch_current_ka_timeout*0.9, tsch_current_ka_timeout[ */
if(!tsch_is_coordinator && tsch_is_associated) { if(!tsch_is_coordinator && tsch_is_associated && tsch_current_ka_timeout > 0) {
unsigned long delay = (TSCH_KEEPALIVE_TIMEOUT - TSCH_KEEPALIVE_TIMEOUT / 10) unsigned long delay = (tsch_current_ka_timeout - tsch_current_ka_timeout / 10)
+ random_rand() % (TSCH_KEEPALIVE_TIMEOUT / 10); + random_rand() % (tsch_current_ka_timeout / 10);
ctimer_set(&keepalive_timer, delay, keepalive_send, NULL); ctimer_set(&keepalive_timer, delay, keepalive_send, NULL);
} }
} }

View file

@ -49,11 +49,19 @@
#define TSCH_KEEPALIVE_TIMEOUT (12 * CLOCK_SECOND) #define TSCH_KEEPALIVE_TIMEOUT (12 * CLOCK_SECOND)
#endif #endif
/* With TSCH_ADAPTIVE_TIMESYNC enabled: keep-alive timeout used after reaching
* accurate drift compensation. */
#ifdef TSCH_CONF_MAX_KEEPALIVE_TIMEOUT
#define TSCH_MAX_KEEPALIVE_TIMEOUT TSCH_CONF_MAX_KEEPALIVE_TIMEOUT
#else
#define TSCH_MAX_KEEPALIVE_TIMEOUT (60 * CLOCK_SECOND)
#endif
/* Max time without synchronization before leaving the PAN */ /* Max time without synchronization before leaving the PAN */
#ifdef TSCH_CONF_DESYNC_THRESHOLD #ifdef TSCH_CONF_DESYNC_THRESHOLD
#define TSCH_DESYNC_THRESHOLD TSCH_CONF_DESYNC_THRESHOLD #define TSCH_DESYNC_THRESHOLD TSCH_CONF_DESYNC_THRESHOLD
#else #else
#define TSCH_DESYNC_THRESHOLD (4 * TSCH_KEEPALIVE_TIMEOUT) #define TSCH_DESYNC_THRESHOLD (2 * TSCH_MAX_KEEPALIVE_TIMEOUT)
#endif #endif
/* Period between two consecutive EBs */ /* Period between two consecutive EBs */
@ -166,6 +174,8 @@ extern const struct mac_driver tschmac_driver;
void tsch_set_join_priority(uint8_t jp); void tsch_set_join_priority(uint8_t jp);
/* The period at which EBs are sent */ /* The period at which EBs are sent */
void tsch_set_eb_period(uint32_t period); void tsch_set_eb_period(uint32_t period);
/* The keep-alive timeout */
void tsch_set_ka_timeout(uint32_t timeout);
/* Set the node as PAN coordinator */ /* Set the node as PAN coordinator */
void tsch_set_coordinator(int enable); void tsch_set_coordinator(int enable);
/* Set the pan as secured or not */ /* Set the pan as secured or not */