The friendly Operating System for the Internet of Things
rpl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 - 2014 INRIA.
3  * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
4  * Copyright (C) 2015 Cenk Gündoğan <cnkgndgn@gmail.com>
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
98 #ifndef GNRC_RPL_H
99 #define GNRC_RPL_H
100 
101 #include <string.h>
102 #include <stdint.h>
103 #include "net/gnrc.h"
104 #include "net/gnrc/ipv6.h"
105 #include "net/ipv6/addr.h"
106 #include "net/gnrc/nettype.h"
107 #include "net/gnrc/rpl/structs.h"
108 #include "net/gnrc/rpl/dodag.h"
109 #include "net/gnrc/rpl/of_manager.h"
110 #include "net/fib.h"
111 #include "xtimer.h"
112 #include "trickle.h"
113 
114 #ifdef MODULE_NETSTATS_RPL
115 #include "net/rpl/rpl_netstats.h"
116 #endif
117 
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121 
125 #ifndef GNRC_RPL_STACK_SIZE
126 #define GNRC_RPL_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
127 #endif
128 
132 #ifndef GNRC_RPL_PRIO
133 #define GNRC_RPL_PRIO (GNRC_IPV6_PRIO + 1)
134 #endif
135 
139 #ifndef GNRC_RPL_MSG_QUEUE_SIZE
140 #define GNRC_RPL_MSG_QUEUE_SIZE (8U)
141 #endif
142 
151 #define GNRC_RPL_ALL_NODES_ADDR {{ 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1a }}
152 
156 #define GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE (0x0900)
157 
161 #define GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL (0x0901)
162 
166 #define GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK (0x0902)
167 
171 #define GNRC_RPL_MSG_TYPE_DAO_HANDLE (0x0903)
172 
179 #define GNRC_RPL_INFINITE_RANK (0xFFFF)
180 
187 #ifndef GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE
188 #define GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE (256)
189 #endif
190 
194 #ifndef GNRC_RPL_DEFAULT_MAX_RANK_INCREASE
195 #define GNRC_RPL_DEFAULT_MAX_RANK_INCREASE (0)
196 #endif
197 
201 #define GNRC_RPL_IMPLEMENTED_OFS_NUMOF (1)
202 
206 #define GNRC_RPL_DEFAULT_OCP (0)
207 
211 #ifndef GNRC_RPL_DEFAULT_INSTANCE
212 #define GNRC_RPL_DEFAULT_INSTANCE (0)
213 #endif
214 
219 #define GNRC_RPL_MOP_NO_DOWNWARD_ROUTES (0x00)
220 #define GNRC_RPL_MOP_NON_STORING_MODE (0x01)
221 #define GNRC_RPL_MOP_STORING_MODE_NO_MC (0x02)
222 #define GNRC_RPL_MOP_STORING_MODE_MC (0x03)
223 
225 #ifndef GNRC_RPL_DEFAULT_MOP
226 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
227 #endif
228 
237 #define GNRC_RPL_COUNTER_MAX (255)
238 #define GNRC_RPL_COUNTER_LOWER_REGION (127)
239 #define GNRC_RPL_COUNTER_SEQ_WINDOW (16)
240 #define GNRC_RPL_COUNTER_INIT (GNRC_RPL_COUNTER_MAX - GNRC_RPL_COUNTER_SEQ_WINDOW + 1)
241 
242 static inline uint8_t GNRC_RPL_COUNTER_INCREMENT(uint8_t counter)
243 {
244  return ((counter > GNRC_RPL_COUNTER_LOWER_REGION) ?
245  ((counter == GNRC_RPL_COUNTER_MAX) ? counter = 0 : ++counter) :
246  ((counter == GNRC_RPL_COUNTER_LOWER_REGION) ? counter = 0 : ++counter));
247 }
248 
249 static inline bool GNRC_RPL_COUNTER_IS_INIT(uint8_t counter)
250 {
251  return (counter > GNRC_RPL_COUNTER_LOWER_REGION);
252 }
253 
254 static inline bool GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B)
255 {
256  return (((A < B) && (GNRC_RPL_COUNTER_LOWER_REGION + 1 - B + A < GNRC_RPL_COUNTER_SEQ_WINDOW))
257  || ((A > B) && (A - B < GNRC_RPL_COUNTER_SEQ_WINDOW)));
258 }
259 
260 static inline bool GNRC_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
261 {
262  return ((A > GNRC_RPL_COUNTER_LOWER_REGION) ? ((B > GNRC_RPL_COUNTER_LOWER_REGION) ?
263  GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) :
264  ((B > GNRC_RPL_COUNTER_LOWER_REGION) ? 1 : GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B)));
265 }
275 #ifndef GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS
276 #define GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS (20)
277 #endif
278 
279 #ifndef GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN
280 #define GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN (3)
281 #endif
282 
283 #ifndef GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT
284 #define GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT (10)
285 #endif
286 
296 #ifndef GNRC_RPL_DEFAULT_LIFETIME
297 #define GNRC_RPL_DEFAULT_LIFETIME (5)
298 #endif
299 #ifndef GNRC_RPL_LIFETIME_UNIT
300 #define GNRC_RPL_LIFETIME_UNIT (60)
301 #endif
302 
307 #define GNRC_RPL_DEFAULT_PREFIX_LEN (64)
308 
316 #define GNRC_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)
317 
324 #define GNRC_RPL_GROUNDED (1)
325 
333 #ifndef GNRC_RPL_DAO_SEND_RETRIES
334 #define GNRC_RPL_DAO_SEND_RETRIES (4)
335 #endif
336 #ifndef GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK
337 #define GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK (3)
338 #endif
339 #ifndef GNRC_RPL_REGULAR_DAO_INTERVAL
340 #define GNRC_RPL_REGULAR_DAO_INTERVAL (60)
341 #endif
342 #ifndef GNRC_RPL_DEFAULT_DAO_DELAY
343 #define GNRC_RPL_DEFAULT_DAO_DELAY (1)
344 #endif
345 
350 #define GNRC_RPL_CLEANUP_TIME (5)
351 
356 #define GNRC_RPL_NORMAL_NODE (0)
357 #define GNRC_RPL_ROOT_NODE (1)
358 #define GNRC_RPL_LEAF_NODE (2)
359 
369 #define GNRC_RPL_OPT_PAD1 (0)
370 #define GNRC_RPL_OPT_PADN (1)
371 #define GNRC_RPL_OPT_DAG_METRIC_CONTAINER (2)
372 #define GNRC_RPL_OPT_ROUTE_INFO (3)
373 #define GNRC_RPL_OPT_DODAG_CONF (4)
374 #define GNRC_RPL_OPT_TARGET (5)
375 #define GNRC_RPL_OPT_TRANSIT (6)
376 #define GNRC_RPL_OPT_SOLICITED_INFO (7)
377 #define GNRC_RPL_OPT_PREFIX_INFO (8)
378 #define GNRC_RPL_OPT_TARGET_DESC (9)
379 
384 #define GNRC_RPL_ROOT_RANK (GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE)
385 
392 #define GNRC_RPL_ICMPV6_CODE_DIS (0x00)
393 
400 #define GNRC_RPL_ICMPV6_CODE_DIO (0x01)
401 
408 #define GNRC_RPL_ICMPV6_CODE_DAO (0x02)
409 
416 #define GNRC_RPL_ICMPV6_CODE_DAO_ACK (0x03)
417 
421 #define GNRC_RPL_LIFETIME_UPDATE_STEP (2)
422 
429 #define DAGRANK(rank,mhri) (rank/mhri)
430 
438 #define GNRC_RPL_INSTANCE_ID_MSB (1 << 7)
439 #define GNRC_RPL_GLOBAL_INSTANCE_MASK (0x7F)
440 #define GNRC_RPL_LOCAL_INSTANCE_MASK (0x3F)
441 #define GNRC_RPL_INSTANCE_D_FLAG_MASK (1 << 6)
442 
448 
453 
454 #ifdef MODULE_NETSTATS_RPL
455 
458 extern netstats_rpl_t gnrc_rpl_netstats;
459 #endif
460 
470 
484 gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
485  bool gen_inst_id, bool local_inst_id);
486 
493 void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination);
494 
501 void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination);
502 
510 void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime);
511 
519 void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq);
520 
531  ipv6_addr_t *dst, uint16_t len);
532 
543  uint16_t len);
544 
555  uint16_t len);
556 
567  ipv6_addr_t *dst, uint16_t len);
568 
575 
582 
593 gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
594  uint8_t mop);
595 
606  ipv6_addr_t *dodag_id);
607 
616 uint8_t gnrc_rpl_gen_instance_id(bool local);
617 
618 #ifndef GNRC_RPL_WITHOUT_PIO
619 
626 static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
627 {
628  dodag->dio_opts = (dodag->dio_opts & ~GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO) |
629  (status << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT);
630 }
631 #endif
632 
633 #ifdef __cplusplus
634 }
635 #endif
636 
637 #endif /* GNRC_RPL_H */
638 
Implementation of a generic Trickle Algorithm (RFC 6206)
RPL data structs.
Definitions for IPv6 addresses.
Types and functions for FIB.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination)
Send a DIO of the instance to the destination.
void gnrc_rpl_delay_dao(gnrc_rpl_dodag_t *dodag)
Delay the DAO sending interval.
void gnrc_rpl_recv_DIO(gnrc_rpl_dio_t *dio, kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *dst, uint16_t len)
Parse a DIO.
RPL Objective functions manager header.
DIO Base Object.
Definition: structs.h:88
void gnrc_rpl_recv_DAO_ACK(gnrc_rpl_dao_ack_t *dao_ack, kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *dst, uint16_t len)
Parse a DAO-ACK.
gnrc_rpl_instance_t * gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_t *dodag_id, uint8_t mop)
Create a new RPL instance and RPL DODAG.
void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination)
Send a DIS of the instace to the destination.
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition: structs.h:216
Includes all essential GNRC network stack base modules.
void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime)
Send a DAO of the dodag to the destination.
Definitions for GNRC's IPv6 implementation.
DODAG-related functions for RPL.
xtimer interface definitions
Destination Advertisement Object.
Definition: structs.h:137
gnrc_rpl_instance_t * gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id, bool gen_inst_id, bool local_inst_id)
Initialization of a node as root.
void gnrc_rpl_recv_DIS(gnrc_rpl_dis_t *dis, kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *dst, uint16_t len)
Parse a DIS.
void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq)
Send a DAO-ACK of the instance to the destination.
Definition of RPL related packet statistics.
static void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
(De-)Activate the transmission of Prefix Information Options within DIOs for a particular DODAG ...
Definition: rpl.h:626
kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid)
Initialization of the RPL thread.
RPL statistics struct.
Definition: rpl_netstats.h:33
DODAG Information Solicitation.
Definition: structs.h:126
Type to represent parts (either headers or payload) of a packet, called snips.
Data type to represent an IPv6 address.
Definition: ipv6/addr.h:74
uint8_t gnrc_rpl_gen_instance_id(bool local)
Generate a local or global instance id.
const ipv6_addr_t ipv6_addr_all_rpl_nodes
Destination Advertisement Object Acknowledgement.
Definition: structs.h:150
void gnrc_rpl_send(gnrc_pktsnip_t *pkt, kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *dst, ipv6_addr_t *dodag_id)
Send a control message.
kernel_pid_t gnrc_rpl_pid
PID of the RPL thread.
Protocol type definitions.
void gnrc_rpl_long_delay_dao(gnrc_rpl_dodag_t *dodag)
Long delay the DAO sending interval.
struct gnrc_rpl_dodag gnrc_rpl_dodag_t
DODAG representation.
Definition: structs.h:206
void gnrc_rpl_recv_DAO(gnrc_rpl_dao_t *dao, kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *dst, uint16_t len)
Parse a DAO.