2016-11-12 06:13:24 +08:00
|
|
|
/** @file
|
|
|
|
* @brief Trickle timer library
|
|
|
|
*
|
|
|
|
* This implements Trickle timer as specified in RFC 6206
|
|
|
|
*/
|
|
|
|
|
2016-08-05 20:13:33 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-08-05 20:13:33 +08:00
|
|
|
*/
|
|
|
|
|
2016-11-12 06:13:24 +08:00
|
|
|
#ifndef __TRICKLE_H
|
|
|
|
#define __TRICKLE_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-11-12 06:13:24 +08:00
|
|
|
|
|
|
|
#include <kernel.h>
|
2017-03-06 19:06:27 +08:00
|
|
|
#include <net/net_core.h>
|
2016-11-12 06:13:24 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2016-08-05 20:13:33 +08:00
|
|
|
#endif
|
2016-11-12 06:13:24 +08:00
|
|
|
|
2017-07-20 21:29:45 +08:00
|
|
|
/**
|
|
|
|
* @brief Trickle algorithm library
|
|
|
|
* @defgroup trickle Trickle Algorithm Library
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-11-12 06:13:24 +08:00
|
|
|
struct net_trickle;
|
|
|
|
|
|
|
|
typedef void (*net_trickle_cb_t)(struct net_trickle *trickle,
|
|
|
|
bool do_suppress, void *user_data);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The variable names are taken directly from RFC when applicable.
|
|
|
|
* Note that the struct members should not be accessed directly but
|
|
|
|
* only via the Trickle API.
|
|
|
|
*/
|
|
|
|
struct net_trickle {
|
2017-04-21 22:27:50 +08:00
|
|
|
u32_t Imin; /* Min interval size in ms */
|
|
|
|
u8_t Imax; /* Max number of doublings */
|
2017-07-26 18:35:53 +08:00
|
|
|
u8_t k; /* Redundancy constant */
|
2016-11-12 06:13:24 +08:00
|
|
|
|
2017-04-21 22:27:50 +08:00
|
|
|
u32_t I; /* Current interval size */
|
2017-07-26 18:35:53 +08:00
|
|
|
u32_t Istart; /* Start of the interval in ms */
|
|
|
|
u8_t c; /* Consistency counter */
|
2016-11-12 06:13:24 +08:00
|
|
|
|
2017-07-26 18:35:53 +08:00
|
|
|
u32_t Imax_abs; /* Max interval size in ms (not doublings)
|
2016-11-12 06:13:24 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct k_delayed_work timer;
|
|
|
|
net_trickle_cb_t cb; /* Callback to be called when timer expires */
|
|
|
|
void *user_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NET_TRICKLE_INFINITE_REDUNDANCY 0
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a Trickle timer.
|
|
|
|
*
|
|
|
|
* @param trickle Pointer to Trickle struct.
|
|
|
|
* @param Imin Imin configuration parameter in ms.
|
|
|
|
* @param Imax Max number of doublings.
|
|
|
|
* @param k Redundancy constant parameter. See RFC 6206 for details.
|
|
|
|
*
|
|
|
|
* @return Return 0 if ok and <0 if error.
|
|
|
|
*/
|
|
|
|
int net_trickle_create(struct net_trickle *trickle,
|
2017-04-21 22:27:50 +08:00
|
|
|
u32_t Imin,
|
|
|
|
u8_t Imax,
|
|
|
|
u8_t k);
|
2016-11-12 06:13:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Start a Trickle timer.
|
|
|
|
*
|
|
|
|
* @param trickle Pointer to Trickle struct.
|
|
|
|
* @param cb User callback to call at time T within the current trickle
|
|
|
|
* interval
|
|
|
|
* @param user_data User pointer that is passed to callback.
|
|
|
|
*
|
|
|
|
* @return Return 0 if ok and <0 if error.
|
|
|
|
*/
|
|
|
|
int net_trickle_start(struct net_trickle *trickle,
|
|
|
|
net_trickle_cb_t cb,
|
|
|
|
void *user_data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stop a Trickle timer.
|
|
|
|
*
|
|
|
|
* @param trickle Pointer to Trickle struct.
|
|
|
|
*
|
|
|
|
* @return Return 0 if ok and <0 if error.
|
|
|
|
*/
|
|
|
|
int net_trickle_stop(struct net_trickle *trickle);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief To be called by the protocol handler when it hears a consistent
|
|
|
|
* network transmission.
|
|
|
|
*
|
|
|
|
* @param trickle Pointer to Trickle struct.
|
|
|
|
*/
|
|
|
|
void net_trickle_consistency(struct net_trickle *trickle);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief To be called by the protocol handler when it hears an inconsistent
|
|
|
|
* network transmission.
|
|
|
|
*
|
|
|
|
* @param trickle Pointer to Trickle struct.
|
|
|
|
*/
|
|
|
|
void net_trickle_inconsistency(struct net_trickle *trickle);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if the Trickle timer is running or not.
|
|
|
|
*
|
|
|
|
* @param trickle Pointer to Trickle struct.
|
|
|
|
*
|
|
|
|
* @return Return True if timer is running and False if not.
|
|
|
|
*/
|
|
|
|
static inline bool net_trickle_is_running(struct net_trickle *trickle)
|
|
|
|
{
|
|
|
|
NET_ASSERT(trickle);
|
|
|
|
|
|
|
|
return trickle->I != 0;
|
|
|
|
}
|
|
|
|
|
2017-07-20 21:29:45 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-11-12 06:13:24 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __TRICKLE_H */
|