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 - 2018 Cenk Gündoğan <cenk.guendogan@haw-hamburg.de>
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 
141 #ifndef NET_GNRC_RPL_H
142 #define NET_GNRC_RPL_H
143 
144 #include <string.h>
145 #include <stdint.h>
146 #include "kernel_defines.h"
147 #include "net/gnrc.h"
148 #include "net/gnrc/ipv6.h"
149 #include "net/ipv6/addr.h"
150 #include "net/gnrc/nettype.h"
151 #include "net/gnrc/rpl/structs.h"
152 #include "net/gnrc/rpl/dodag.h"
153 #include "net/gnrc/rpl/of_manager.h"
154 #include "net/fib.h"
155 #include "xtimer.h"
156 #include "trickle.h"
157 
158 #ifdef MODULE_NETSTATS_RPL
159 #include "net/rpl/rpl_netstats.h"
160 #endif
161 
162 #ifdef __cplusplus
163 extern "C" {
164 #endif
165 
169 #ifndef GNRC_RPL_STACK_SIZE
170 #define GNRC_RPL_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
171 #endif
172 
176 #ifndef GNRC_RPL_PRIO
177 #define GNRC_RPL_PRIO (GNRC_IPV6_PRIO + 1)
178 #endif
179 
188 #ifndef CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP
189 #define CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP (3U)
190 #endif
191 
195 #ifndef GNRC_RPL_MSG_QUEUE_SIZE
196 #define GNRC_RPL_MSG_QUEUE_SIZE (1 << CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP)
197 #endif
198 
207 #define GNRC_RPL_ALL_NODES_ADDR {{ 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1a }}
208 
212 #define GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE (0x0900)
213 
217 #define GNRC_RPL_MSG_TYPE_TRICKLE_MSG (0x0901)
218 
222 #define GNRC_RPL_MSG_TYPE_DAO_HANDLE (0x0903)
223 
230 #define GNRC_RPL_INFINITE_RANK (0xFFFF)
231 
238 #ifndef CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE
239 #define CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE (256)
240 #endif
241 
245 #ifndef CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE
246 #define CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE (0)
247 #endif
248 
252 #define GNRC_RPL_IMPLEMENTED_OFS_NUMOF (1)
253 
257 #define GNRC_RPL_DEFAULT_OCP (0)
258 
262 #ifndef CONFIG_GNRC_RPL_DEFAULT_INSTANCE
263 #define CONFIG_GNRC_RPL_DEFAULT_INSTANCE (0)
264 #endif
265 
270 #define GNRC_RPL_MOP_NO_DOWNWARD_ROUTES (0x00)
271 #define GNRC_RPL_MOP_NON_STORING_MODE (0x01)
272 #define GNRC_RPL_MOP_STORING_MODE_NO_MC (0x02)
273 #define GNRC_RPL_MOP_STORING_MODE_MC (0x03)
274 
275 /* translate Kconfig options to final value */
276 #if IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NO_DOWNWARD_ROUTES)
277 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NO_DOWNWARD_ROUTES
278 #elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NON_STORING_MODE)
279 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NON_STORING_MODE
280 #elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_NO_MC)
281 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
282 #elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_MC)
283 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_MC
284 #endif
285 
287 #ifndef GNRC_RPL_DEFAULT_MOP
288 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
289 #endif
290 
299 #define GNRC_RPL_COUNTER_MAX (255)
300 #define GNRC_RPL_COUNTER_LOWER_REGION (127)
301 #define GNRC_RPL_COUNTER_SEQ_WINDOW (16)
302 #define GNRC_RPL_COUNTER_INIT (GNRC_RPL_COUNTER_MAX - GNRC_RPL_COUNTER_SEQ_WINDOW + 1)
303 
304 static inline uint8_t GNRC_RPL_COUNTER_INCREMENT(uint8_t counter)
305 {
306  return ((counter > GNRC_RPL_COUNTER_LOWER_REGION) ?
307  ((counter == GNRC_RPL_COUNTER_MAX) ? counter = 0 : ++counter) :
308  ((counter == GNRC_RPL_COUNTER_LOWER_REGION) ? counter = 0 : ++counter));
309 }
310 
311 static inline bool GNRC_RPL_COUNTER_IS_INIT(uint8_t counter)
312 {
313  return (counter > GNRC_RPL_COUNTER_LOWER_REGION);
314 }
315 
316 static inline bool GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B)
317 {
318  return (((A < B) && (GNRC_RPL_COUNTER_LOWER_REGION + 1 - B + A < GNRC_RPL_COUNTER_SEQ_WINDOW))
319  || ((A > B) && (A - B < GNRC_RPL_COUNTER_SEQ_WINDOW)));
320 }
321 
322 static inline bool GNRC_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
323 {
324  return ((A > GNRC_RPL_COUNTER_LOWER_REGION) ? ((B > GNRC_RPL_COUNTER_LOWER_REGION) ?
325  GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) :
326  ((B > GNRC_RPL_COUNTER_LOWER_REGION) ? 1 : GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B)));
327 }
337 #ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS
338 #define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS (20)
339 #endif
340 
341 #ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN
342 #define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN (3)
343 #endif
344 
345 #ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT
346 #define CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT (10)
347 #endif
348 
358 #ifndef CONFIG_GNRC_RPL_DEFAULT_LIFETIME
359 #define CONFIG_GNRC_RPL_DEFAULT_LIFETIME (5)
360 #endif
361 #ifndef CONFIG_GNRC_RPL_LIFETIME_UNIT
362 #define CONFIG_GNRC_RPL_LIFETIME_UNIT (60)
363 #endif
364 
369 #define GNRC_RPL_DEFAULT_PREFIX_LEN (64)
370 
378 #define GNRC_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)
379 
386 #define GNRC_RPL_GROUNDED (1)
387 
395 #ifndef CONFIG_GNRC_RPL_DAO_SEND_RETRIES
396 #define CONFIG_GNRC_RPL_DAO_SEND_RETRIES (4)
397 #endif
398 #ifndef CONFIG_GNRC_RPL_DAO_ACK_DELAY
399 #define CONFIG_GNRC_RPL_DAO_ACK_DELAY (3000UL)
400 #endif
401 #ifndef CONFIG_GNRC_RPL_DAO_DELAY_LONG
402 
405 #define CONFIG_GNRC_RPL_DAO_DELAY_LONG (60000UL)
406 #endif
407 #ifndef CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT
408 
411 #define CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT (1000UL)
412 #endif
413 #ifndef CONFIG_GNRC_RPL_DAO_DELAY_JITTER
414 
417 #define CONFIG_GNRC_RPL_DAO_DELAY_JITTER (1000UL)
418 #endif
419 
424 #ifndef CONFIG_GNRC_RPL_CLEANUP_TIME
425 #define CONFIG_GNRC_RPL_CLEANUP_TIME (5 * MS_PER_SEC)
426 #endif
427 
432 #define GNRC_RPL_NORMAL_NODE (0)
433 #define GNRC_RPL_ROOT_NODE (1)
434 #define GNRC_RPL_LEAF_NODE (2)
435 
445 #define GNRC_RPL_OPT_PAD1 (0)
446 #define GNRC_RPL_OPT_PADN (1)
447 #define GNRC_RPL_OPT_DAG_METRIC_CONTAINER (2)
448 #define GNRC_RPL_OPT_ROUTE_INFO (3)
449 #define GNRC_RPL_OPT_DODAG_CONF (4)
450 #define GNRC_RPL_OPT_TARGET (5)
451 #define GNRC_RPL_OPT_TRANSIT (6)
452 #define GNRC_RPL_OPT_SOLICITED_INFO (7)
453 #define GNRC_RPL_OPT_PREFIX_INFO (8)
454 #define GNRC_RPL_OPT_TARGET_DESC (9)
455 
460 #define GNRC_RPL_ROOT_RANK (CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE)
461 
468 #define GNRC_RPL_ICMPV6_CODE_DIS (0x00)
469 
476 #define GNRC_RPL_ICMPV6_CODE_DIO (0x01)
477 
484 #define GNRC_RPL_ICMPV6_CODE_DAO (0x02)
485 
492 #define GNRC_RPL_ICMPV6_CODE_DAO_ACK (0x03)
493 
497 #define GNRC_RPL_LIFETIME_UPDATE_STEP (2)
498 
505 #define DAGRANK(rank,mhri) (rank/mhri)
506 
514 #define GNRC_RPL_INSTANCE_ID_MSB (1 << 7)
515 #define GNRC_RPL_GLOBAL_INSTANCE_MASK (0x7F)
516 #define GNRC_RPL_LOCAL_INSTANCE_MASK (0x3F)
517 #define GNRC_RPL_INSTANCE_D_FLAG_MASK (1 << 6)
518 
527 #define GNRC_RPL_DIS_SOLICITED_INFO_LENGTH (19)
528 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_V (1 << 7)
529 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_I (1 << 6)
530 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_D (1 << 5)
531 
537 
542 
543 #ifdef MODULE_NETSTATS_RPL
544 
547 extern netstats_rpl_t gnrc_rpl_netstats;
548 #endif
549 
553 #ifndef CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES
554 #define CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES (3)
555 #endif
556 
560 #ifndef CONFIG_GNRC_RPL_DEFAULT_NETIF
561 #define CONFIG_GNRC_RPL_DEFAULT_NETIF (KERNEL_PID_UNDEF)
562 #endif
563 
573 
587 gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
588  bool gen_inst_id, bool local_inst_id);
589 
596 void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination);
597 
606 void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination,
607  gnrc_rpl_internal_opt_t **options, size_t num_opts);
608 
616 void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime);
617 
625 void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq);
626 
637  ipv6_addr_t *dst, uint16_t len);
638 
649  uint16_t len);
650 
661  uint16_t len);
662 
673  ipv6_addr_t *dst, uint16_t len);
674 
681 
688 
699 gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
700  uint8_t mop);
701 
712  ipv6_addr_t *dodag_id);
713 
722 uint8_t gnrc_rpl_gen_instance_id(bool local);
723 
732 static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
733 {
734  if (!IS_ACTIVE(CONFIG_GNRC_RPL_WITHOUT_PIO)) {
735  dodag->dio_opts = (dodag->dio_opts & ~GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO) |
736  (status << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT);
737  }
738 }
739 
740 #ifdef __cplusplus
741 }
742 #endif
743 
744 #endif /* NET_GNRC_RPL_H */
745 
gnrc_rpl_dis_t
DODAG Information Solicitation.
Definition: structs.h:128
rpl_netstats.h
Definition of RPL related packet statistics.
gnrc_rpl_recv_DIS
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.
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
fib.h
Types and functions for FIB.
gnrc.h
Includes all essential GNRC network stack base modules.
ipv6_addr_all_rpl_nodes
const ipv6_addr_t ipv6_addr_all_rpl_nodes
gnrc_rpl_send
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.
gnrc_rpl_pid
kernel_pid_t gnrc_rpl_pid
PID of the RPL thread.
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
of_manager.h
RPL Objective functions manager header.
ipv6_addr_t
Data type to represent an IPv6 address.
Definition: addr.h:74
addr.h
Definitions for IPv6 addresses.
trickle.h
Trickle timer interface definition.
netstats_rpl_t
RPL statistics struct.
Definition: rpl_netstats.h:33
gnrc_rpl_instance_t
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition: structs.h:235
gnrc_rpl_config_pio
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:732
gnrc_priority_pktqueue_node::pkt
gnrc_pktsnip_t * pkt
queue node data
Definition: priority_pktqueue.h:41
dodag.h
DODAG-related functions for RPL.
structs.h
RPL data structs.
nettype.h
Protocol type definitions.
gnrc_rpl_gen_instance_id
uint8_t gnrc_rpl_gen_instance_id(bool local)
Generate a local or global instance id.
IS_ACTIVE
#define IS_ACTIVE(macro)
Allows to verify a macro definition outside the preprocessor.
Definition: kernel_defines.h:177
gnrc_rpl_dao_ack_t
Destination Advertisement Object Acknowledgement.
Definition: structs.h:167
ipv6.h
Definitions for GNRC's IPv6 implementation.
gnrc_rpl_long_delay_dao
void gnrc_rpl_long_delay_dao(gnrc_rpl_dodag_t *dodag)
Long delay the DAO sending interval.
gnrc_rpl_dio_t
DIO Base Object.
Definition: structs.h:90
gnrc_rpl_internal_opt_t
internal unpacked struct type for option insertion
Definition: structs.h:357
gnrc_rpl_root_init
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.
gnrc_rpl_delay_dao
void gnrc_rpl_delay_dao(gnrc_rpl_dodag_t *dodag)
Delay the DAO sending interval.
gnrc_rpl_send_DIS
void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, gnrc_rpl_internal_opt_t **options, size_t num_opts)
Send a DIS of the instance to the destination.
gnrc_rpl_recv_DIO
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.
gnrc_rpl_send_DAO_ACK
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.
gnrc_rpl_send_DAO
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.
gnrc_rpl_send_DIO
void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination)
Send a DIO of the instance to the destination.
gnrc_rpl_init
kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid)
Initialization of the RPL thread.
gnrc_rpl_recv_DAO
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.
gnrc_rpl_dodag_t
struct gnrc_rpl_dodag gnrc_rpl_dodag_t
DODAG representation.
Definition: structs.h:225
xtimer.h
xtimer interface definitions
gnrc_pktsnip
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108
gnrc_rpl_recv_DAO_ACK
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_root_instance_init
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.
gnrc_rpl_dao_t
Destination Advertisement Object.
Definition: structs.h:154