forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trickle.h
137 lines (114 loc) · 2.99 KB
/
trickle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** @file
* @brief Trickle timer library
*
* This implements Trickle timer as specified in RFC 6206
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __TRICKLE_H
#define __TRICKLE_H
#include <stdbool.h>
#include <zephyr/types.h>
#include <kernel.h>
#include <net/net_core.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Trickle algorithm library
* @defgroup trickle Trickle Algorithm Library
* @{
*/
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 {
u32_t Imin; /* Min interval size in ms */
u8_t Imax; /* Max number of doublings */
u8_t k; /* Redundancy constant */
u32_t I; /* Current interval size */
u32_t Istart; /* Start of the interval in ms */
u8_t c; /* Consistency counter */
u32_t Imax_abs; /* Max interval size in ms (not doublings)
*/
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,
u32_t Imin,
u8_t Imax,
u8_t k);
/**
* @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;
}
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __TRICKLE_H */