mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
trickle: enhancements
This commit is contained in:
parent
2a2855631e
commit
e0fbb14963
@ -2,6 +2,7 @@
|
|||||||
* Trickle constants and prototypes
|
* Trickle constants and prototypes
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013, 2014 INRIA.
|
* Copyright (C) 2013, 2014 INRIA.
|
||||||
|
* 2017 HAW Hamburg
|
||||||
*
|
*
|
||||||
* This file is subject to the terms and conditions of the GNU Lesser
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
* General Public License v2.1. See the file LICENSE in the top level
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
@ -12,14 +13,11 @@
|
|||||||
* @defgroup sys_trickle Trickle Timer
|
* @defgroup sys_trickle Trickle Timer
|
||||||
* @ingroup sys
|
* @ingroup sys
|
||||||
* @{
|
* @{
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
* @file
|
||||||
* @brief Implementation of a generic Trickle Algorithm (RFC 6206)
|
* @brief Implementation of a generic Trickle Algorithm (RFC 6206)
|
||||||
*
|
*
|
||||||
* @author Eric Engel <eric.engel@fu-berlin.de>
|
* @author Eric Engel <eric.engel@fu-berlin.de>
|
||||||
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
|
* @author Cenk Gündoğan <cenk.guendogan@haw-hamburg.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TRICKLE_H
|
#ifndef TRICKLE_H
|
||||||
@ -32,10 +30,13 @@
|
|||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
/** @brief a generic callback function with arguments that is called by trickle periodically */
|
/**
|
||||||
|
* @brief a generic callback function with arguments that is called by
|
||||||
|
* trickle periodically
|
||||||
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*func)(void *); /**< a generic callback function pointer */
|
void (*func)(void *); /**< callback function pointer */
|
||||||
void *args; /**< a generic parameter for the callback function pointer */
|
void *args; /**< callback function arguments */
|
||||||
} trickle_callback_t;
|
} trickle_callback_t;
|
||||||
|
|
||||||
/** @brief all state variables for a trickle timer */
|
/** @brief all state variables for a trickle timer */
|
||||||
@ -49,14 +50,10 @@ typedef struct {
|
|||||||
kernel_pid_t pid; /**< pid of trickles target thread */
|
kernel_pid_t pid; /**< pid of trickles target thread */
|
||||||
trickle_callback_t callback; /**< the callback function and parameter that trickle is calling
|
trickle_callback_t callback; /**< the callback function and parameter that trickle is calling
|
||||||
after each interval */
|
after each interval */
|
||||||
msg_t msg_interval; /**< the msg_t to use for intervals */
|
msg_t msg; /**< the msg_t to use for intervals */
|
||||||
uint64_t msg_interval_time; /**< interval in ms */
|
uint64_t msg_time; /**< interval in ms */
|
||||||
xtimer_t msg_interval_timer; /**< xtimer to send a msg_t to the target thread
|
xtimer_t msg_timer; /**< xtimer to send a msg_t to the target thread
|
||||||
for a new interval */
|
for a new interval */
|
||||||
msg_t msg_callback; /**< the msg_t to use for callbacks */
|
|
||||||
uint64_t msg_callback_time; /**< callback interval in ms */
|
|
||||||
xtimer_t msg_callback_timer; /**< xtimer to send a msg_t to the target thread
|
|
||||||
for a callback */
|
|
||||||
} trickle_t;
|
} trickle_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,14 +68,13 @@ void trickle_reset_timer(trickle_t *trickle);
|
|||||||
*
|
*
|
||||||
* @param[in] pid target thread
|
* @param[in] pid target thread
|
||||||
* @param[in] trickle trickle timer
|
* @param[in] trickle trickle timer
|
||||||
* @param[in] interval_msg_type msg_t.type for interval messages
|
* @param[in] msg_type msg_t.type for messages
|
||||||
* @param[in] callback_msg_type msg_t.type for callback messages
|
|
||||||
* @param[in] Imin minimum interval
|
* @param[in] Imin minimum interval
|
||||||
* @param[in] Imax maximum interval
|
* @param[in] Imax maximum interval
|
||||||
* @param[in] k redundancy constant
|
* @param[in] k redundancy constant
|
||||||
*/
|
*/
|
||||||
void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t interval_msg_type,
|
void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t msg_type,
|
||||||
uint16_t callback_msg_type, uint32_t Imin, uint8_t Imax, uint8_t k);
|
uint32_t Imin, uint8_t Imax, uint8_t k);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief stops the trickle timer
|
* @brief stops the trickle timer
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* Trickle implementation
|
* Trickle implementation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013, 2014 INRIA.
|
* Copyright (C) 2013, 2014 INRIA.
|
||||||
|
* 2017 HAW Hamburg
|
||||||
*
|
*
|
||||||
* This file is subject to the terms and conditions of the GNU Lesser
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
* General Public License v2.1. See the file LICENSE in the top level
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
@ -10,13 +11,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Eric Engel <eric.engel@fu-berlin.de>
|
* @author Eric Engel <eric.engel@fu-berlin.de>
|
||||||
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
|
* @author Cenk Gündoğan <cenk.guendogan@haw-hamburg.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "inttypes.h"
|
#include "inttypes.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "trickle.h"
|
#include "trickle.h"
|
||||||
@ -30,42 +27,42 @@ void trickle_callback(trickle_t *trickle)
|
|||||||
if ((trickle->c < trickle->k) || (trickle->k == 0)) {
|
if ((trickle->c < trickle->k) || (trickle->k == 0)) {
|
||||||
(*trickle->callback.func)(trickle->callback.args);
|
(*trickle->callback.func)(trickle->callback.args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trickle_interval(trickle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trickle_interval(trickle_t *trickle)
|
void trickle_interval(trickle_t *trickle)
|
||||||
{
|
{
|
||||||
uint32_t max_interval;
|
uint32_t old_interval = trickle->I;
|
||||||
|
uint32_t max_interval = trickle->Imin << trickle->Imax;
|
||||||
|
uint32_t diff = old_interval - trickle->t;
|
||||||
|
|
||||||
trickle->I = trickle->I * 2;
|
trickle->I *= 2;
|
||||||
max_interval = trickle->Imin << trickle->Imax;
|
|
||||||
|
|
||||||
if ((trickle->I == 0) || (trickle->I > max_interval)) {
|
if ((trickle->I == 0) || (trickle->I > max_interval)) {
|
||||||
trickle->I = max_interval;
|
trickle->I = max_interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("trickle: I == %" PRIu32 "\n", trickle->I);
|
DEBUG("trickle: I == %" PRIu32 ", diff == %" PRIu32 "\n", trickle->I, diff);
|
||||||
|
|
||||||
trickle->c = 0;
|
trickle->c = 0;
|
||||||
trickle->t = (trickle->I / 2) + random_uint32_range(0, (trickle->I / 2) + 1);
|
trickle->t = random_uint32_range(old_interval, trickle->I);
|
||||||
|
|
||||||
trickle->msg_callback_time = trickle->t * MS_PER_SEC;
|
trickle->msg_time = (trickle->t + diff) * MS_PER_SEC;
|
||||||
xtimer_set_msg64(&trickle->msg_callback_timer, trickle->msg_callback_time,
|
xtimer_set_msg64(&trickle->msg_timer, trickle->msg_time, &trickle->msg,
|
||||||
&trickle->msg_callback, trickle->pid);
|
trickle->pid);
|
||||||
|
|
||||||
trickle->msg_interval_time = trickle->I * MS_PER_SEC;
|
|
||||||
xtimer_set_msg64(&trickle->msg_interval_timer, trickle->msg_interval_time,
|
|
||||||
&trickle->msg_interval, trickle->pid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void trickle_reset_timer(trickle_t *trickle)
|
void trickle_reset_timer(trickle_t *trickle)
|
||||||
{
|
{
|
||||||
trickle_stop(trickle);
|
trickle_stop(trickle);
|
||||||
trickle_start(trickle->pid, trickle, trickle->msg_interval.type, trickle->msg_callback.type,
|
trickle_start(trickle->pid, trickle, trickle->msg.type, trickle->Imin,
|
||||||
trickle->Imin, trickle->Imax, trickle->k);
|
trickle->Imax, trickle->k);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t interval_msg_type,
|
void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t msg_type,
|
||||||
uint16_t callback_msg_type, uint32_t Imin, uint8_t Imax, uint8_t k)
|
uint32_t Imin, uint8_t Imax, uint8_t k)
|
||||||
{
|
{
|
||||||
trickle->pid = pid;
|
trickle->pid = pid;
|
||||||
|
|
||||||
@ -73,20 +70,18 @@ void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t interval_msg_t
|
|||||||
trickle->k = k;
|
trickle->k = k;
|
||||||
trickle->Imin = Imin;
|
trickle->Imin = Imin;
|
||||||
trickle->Imax = Imax;
|
trickle->Imax = Imax;
|
||||||
trickle->I = trickle->Imin + random_uint32_range(0, 4 * trickle->Imin);
|
trickle->I = trickle->t = random_uint32_range(trickle->Imin,
|
||||||
|
4 * trickle->Imin);
|
||||||
trickle->pid = pid;
|
trickle->pid = pid;
|
||||||
trickle->msg_interval.content.ptr = trickle;
|
trickle->msg.content.ptr = trickle;
|
||||||
trickle->msg_interval.type = interval_msg_type;
|
trickle->msg.type = msg_type;
|
||||||
trickle->msg_callback.content.ptr = trickle;
|
|
||||||
trickle->msg_callback.type = callback_msg_type;
|
|
||||||
|
|
||||||
trickle_interval(trickle);
|
trickle_interval(trickle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trickle_stop(trickle_t *trickle)
|
void trickle_stop(trickle_t *trickle)
|
||||||
{
|
{
|
||||||
xtimer_remove(&trickle->msg_interval_timer);
|
xtimer_remove(&trickle->msg_timer);
|
||||||
xtimer_remove(&trickle->msg_callback_timer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void trickle_increment_counter(trickle_t *trickle)
|
void trickle_increment_counter(trickle_t *trickle)
|
||||||
|
Loading…
Reference in New Issue
Block a user