structs.h
11.2 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
* Copyright (C) 2013 INRIA.
* Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
*
* 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
* directory for more details.
*/
/**
* @ingroup net_gnrc_rpl
* @{
*
* @file
* @brief RPL data structs
*
* Header file, which defines all structs used by RPL.
*
* @author Eric Engel <eric.engel@fu-berlin.de>
* @author Cenk Gündoğan <cnkgndgn@gmail.com>
*/
#ifndef GNRC_RPL_STRUCTS_H_
#define GNRC_RPL_STRUCTS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "net/gnrc/ipv6/netif.h"
#include "net/ipv6/addr.h"
#include "xtimer.h"
#include "trickle.h"
/**
* @name Option lengths
* @{
*/
#define GNRC_RPL_OPT_DODAG_CONF_LEN (14)
#define GNRC_RPL_OPT_PREFIX_INFO_LEN (30)
#define GNRC_RPL_OPT_TARGET_LEN (18)
#define GNRC_RPL_OPT_TRANSIT_INFO_LEN (4)
/** @} */
/**
* @name DAO flag macros
* @{
*/
#define GNRC_RPL_DAO_D_BIT (1 << 6)
#define GNRC_RPL_DAO_K_BIT (1 << 7)
/** @} */
/**
* @name DAO-ACK flag macros
* @{
*/
#define GNRC_RPL_DAO_ACK_D_BIT (1 << 7)
/** @} */
/**
* @anchor GNRC_RPL_REQ_DIO_OPTS
* @name DIO Options for gnrc_rpl_dodag_t::dio_opts
* @{
*/
#define GNRC_RPL_REQ_DIO_OPT_DODAG_CONF_SHIFT (0)
#define GNRC_RPL_REQ_DIO_OPT_DODAG_CONF (1 << GNRC_RPL_REQ_DIO_OPT_DODAG_CONF_SHIFT)
#define GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT (1)
#define GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO (1 << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT)
/** @} */
/**
* @brief RPL-Option Generic Format
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.1">
* RFC6550, section 6.7.1, RPL Control Message Option Generic Format
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< Option Type */
uint8_t length; /**< Option Length, does not include the first two byte */
} gnrc_rpl_opt_t;
/**
* @brief DIO Base Object
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.3.1">
* RFC6550, section 6.3.1, Format of the DIO Base Object
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t instance_id; /**< id of the instance */
uint8_t version_number; /**< version number of the DODAG */
network_uint16_t rank; /**< rank of the parent emitting the DIO */
uint8_t g_mop_prf; /**< grounded, MOP, preferred flags */
uint8_t dtsn; /**< Destination Advertisement Trigger Sequence Number */
uint8_t flags; /**< unused */
uint8_t reserved; /**< reserved */
ipv6_addr_t dodag_id; /**< id of the dodag */
} gnrc_rpl_dio_t;
/**
* @brief DODAG Configuration Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.6">
* RFC6550, section 6.7.6, DODAG Configuration
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< Option Type: 0x04 */
uint8_t length; /**< length of option, not including first two bytes */
uint8_t flags_a_pcs; /**< flags */
uint8_t dio_int_doubl; /**< trickle Imax parameter */
uint8_t dio_int_min; /**< trickle Imin parameter */
uint8_t dio_redun; /**< trickle k parameter */
network_uint16_t max_rank_inc; /**< allowable increase in rank */
network_uint16_t min_hop_rank_inc; /**< DAGRank(rank) = floor(rank/MinHopRankIncrease) */
network_uint16_t ocp; /**< Objective Code Point */
uint8_t reserved; /**< reserved */
uint8_t default_lifetime; /**< lifetime of RPL routes (lifetime * lifetime_unit) */
network_uint16_t lifetime_unit; /**< unit in seconds */
} gnrc_rpl_opt_dodag_conf_t;
/**
* @brief DODAG Information Solicitation
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.2">
* RFC6550, section 6.2, DODAG Information Solicitation
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t flags; /**< unused */
uint8_t reserved; /**< reserved */
} gnrc_rpl_dis_t;
/**
* @brief Destination Advertisement Object
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.4">
* RFC6550, section 6.4, Destination Advertisement Object
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t instance_id; /**< id of the instance */
uint8_t k_d_flags; /**< K and D flags */
uint8_t reserved; /**< reserved */
uint8_t dao_sequence; /**< sequence of the DAO, needs to be used for DAO-ACK */
} gnrc_rpl_dao_t;
/**
* @brief Destination Advertisement Object Acknowledgement
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.5">
* RFC6550, section 6.5, Destination Advertisement Object Acknowledgement
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t instance_id; /**< id of the instance */
uint8_t d_reserved; /**< if set, indicates that the DODAG id should be included */
uint8_t dao_sequence; /**< sequence must be equal to the sequence from the DAO object */
uint8_t status; /**< indicates completion */
} gnrc_rpl_dao_ack_t;
/**
* @brief Target Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.7">
* RFC6550, section 6.7.7, RPL Target
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t flags; /**< unused */
uint8_t prefix_length; /**< number of valid leading bits in the IPv6 prefix */
ipv6_addr_t target; /**< IPv6 prefix, address or multicast group */
} gnrc_rpl_opt_target_t;
/**
* @brief Transit Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.8">
* RFC6550, section 6.7.8, Transit Information
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t e_flags; /**< external flag indicates external routes */
uint8_t path_control; /**< limits the number of DAO parents */
uint8_t path_sequence; /**< increased value for route updates */
uint8_t path_lifetime; /**< lifetime of routes */
} gnrc_rpl_opt_transit_t;
/**
* @brief Prefix Information Option
* @see <a href="https://tools.ietf.org/html/rfc6550#section-6.7.10">
* RFC6550, section 6.7.10, Prefix Information
* </a>
*/
typedef struct __attribute__((packed)) {
uint8_t type; /**< option type */
uint8_t length; /**< option length without the first two bytes */
uint8_t prefix_len; /**< prefix length */
uint8_t LAR_flags; /**< flags and resereved */
uint32_t valid_lifetime; /**< valid lifetime */
uint32_t pref_lifetime; /**< preferred lifetime */
uint32_t reserved; /**< reserved */
ipv6_addr_t prefix; /**< prefix used for Stateless Address Autoconfiguration */
} gnrc_rpl_opt_prefix_info_t;
typedef struct gnrc_rpl_dodag gnrc_rpl_dodag_t;
typedef struct gnrc_rpl_parent gnrc_rpl_parent_t;
typedef struct gnrc_rpl_instance gnrc_rpl_instance_t;
/**
* @brief Parent representation
*/
struct gnrc_rpl_parent {
gnrc_rpl_parent_t *next; /**< pointer to the next parent */
uint8_t state; /**< 0 for unsued, 1 for used */
ipv6_addr_t addr; /**< link-local IPv6 address of this parent */
uint8_t dtsn; /**< last seen dtsn of this parent */
uint16_t rank; /**< rank of the parent */
gnrc_rpl_dodag_t *dodag; /**< DODAG the parent belongs to */
uint32_t lifetime; /**< lifetime of this parent in seconds */
double link_metric; /**< metric of the link */
uint8_t link_metric_type; /**< type of the metric */
};
/**
* @brief Objective function representation
*/
typedef struct {
uint16_t ocp; /**< objective code point */
uint16_t (*calc_rank)(gnrc_rpl_parent_t *parent, uint16_t base_rank); /**< calculate the rank */
gnrc_rpl_parent_t *(*which_parent)(gnrc_rpl_parent_t *, gnrc_rpl_parent_t *); /**< compare for parents */
gnrc_rpl_dodag_t *(*which_dodag)(gnrc_rpl_dodag_t *, gnrc_rpl_dodag_t *); /**< compare for dodags */
void (*reset)(gnrc_rpl_dodag_t *); /**< resets the OF */
void (*parent_state_callback)(gnrc_rpl_parent_t *, int, int); /**< retrieves the state of a parent*/
void (*init)(void); /**< OF specific init function */
void (*process_dio)(void); /**< DIO processing callback (acc. to OF0 spec, chpt 5) */
} gnrc_rpl_of_t;
/**
* @brief DODAG representation
*/
struct gnrc_rpl_dodag {
ipv6_addr_t dodag_id; /**< id of the DODAG */
gnrc_ipv6_netif_addr_t *netif_addr; /**< netif address for this DODAG */
gnrc_rpl_parent_t *parents; /**< pointer to the parents list of this DODAG */
gnrc_rpl_instance_t *instance; /**< pointer to the instance that this dodag is part of */
uint8_t dtsn; /**< DAO Trigger Sequence Number */
uint8_t prf; /**< preferred flag */
uint8_t dio_interval_doubl; /**< trickle Imax parameter */
uint8_t dio_min; /**< trickle Imin parameter */
uint8_t dio_redun; /**< trickle k parameter */
uint8_t default_lifetime; /**< lifetime of routes (lifetime * unit) */
uint16_t lifetime_unit; /**< unit in seconds of the lifetime */
kernel_pid_t iface; /**< interface PID this DODAG operates on */
uint8_t version; /**< version of this DODAG */
uint8_t grounded; /**< grounded flag */
uint16_t my_rank; /**< rank/position in the DODAG */
uint8_t node_status; /**< leaf, normal, or root node */
uint8_t dao_seq; /**< dao sequence number */
uint8_t dao_counter; /**< amount of retried DAOs */
bool dao_ack_received; /**< flag to check for DAO-ACK */
uint8_t dio_opts; /**< options in the next DIO
(see @ref GNRC_RPL_REQ_DIO_OPTS "DIO Options") */
uint8_t dao_time; /**< time to schedule a DAO in seconds */
trickle_t trickle; /**< trickle representation */
};
/**
* @brief Instance representation
*/
struct gnrc_rpl_instance {
uint8_t id; /**< id of the instance */
uint8_t state; /**< 0 for unused, 1 for used */
gnrc_rpl_dodag_t dodag; /**< DODAG of this instance */
uint8_t mop; /**< configured Mode of Operation */
gnrc_rpl_of_t *of; /**< configured Objective Function */
uint16_t min_hop_rank_inc; /**< minimum hop rank increase */
uint16_t max_rank_inc; /**< max increase in the rank */
int8_t cleanup; /**< cleanup time in seconds */
};
#ifdef __cplusplus
}
#endif
#endif /* GNRC_RPL_STRUCTS_H_ */
/**
* @}
*/