rpl.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2013-2014 INRIA
3  * SPDX-FileCopyrightText: 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
4  * SPDX-FileCopyrightText: 2015-2018 Cenk Gündoğan <cenk.guendogan@haw-hamburg.de>
5  * SPDX-License-Identifier: LGPL-2.1-only
6  */
7 
8 #pragma once
9 
140 #include <string.h>
141 #include <stdint.h>
142 #include "modules.h"
143 #include "net/gnrc.h"
144 #include "net/gnrc/ipv6.h"
145 #include "net/ipv6/addr.h"
146 #include "net/gnrc/nettype.h"
147 #include "net/gnrc/rpl/structs.h"
148 #include "net/gnrc/rpl/dodag.h"
149 #include "net/gnrc/rpl/of_manager.h"
150 #include "net/fib.h"
151 #include "trickle.h"
152 
153 #ifdef MODULE_NETSTATS_RPL
154 #include "net/rpl/rpl_netstats.h"
155 #endif
156 
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160 
164 #ifndef GNRC_RPL_STACK_SIZE
165 #define GNRC_RPL_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
166 #endif
167 
171 #ifndef GNRC_RPL_PRIO
172 #define GNRC_RPL_PRIO (GNRC_IPV6_PRIO + 1)
173 #endif
174 
183 #ifndef CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP
184 #define CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP (3U)
185 #endif
186 
190 #ifndef GNRC_RPL_MSG_QUEUE_SIZE
191 #define GNRC_RPL_MSG_QUEUE_SIZE (1 << CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP)
192 #endif
193 
202 #define GNRC_RPL_ALL_NODES_ADDR {{ 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1a }}
203 
207 #define GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE (0x0900)
208 
212 #define GNRC_RPL_MSG_TYPE_TRICKLE_MSG (0x0901)
213 
217 #define GNRC_RPL_MSG_TYPE_DAO_HANDLE (0x0903)
218 
225 #define GNRC_RPL_INFINITE_RANK (0xFFFF)
226 
233 #ifndef CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE
234 #define CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE (256)
235 #endif
236 
240 #ifndef CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE
241 #define CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE (0)
242 #endif
243 
247 #define GNRC_RPL_IMPLEMENTED_OFS_NUMOF (1)
248 
252 #define GNRC_RPL_DEFAULT_OCP (0)
253 
257 #ifndef CONFIG_GNRC_RPL_DEFAULT_INSTANCE
258 #define CONFIG_GNRC_RPL_DEFAULT_INSTANCE (0)
259 #endif
260 
265 #define GNRC_RPL_MOP_NO_DOWNWARD_ROUTES (0x00)
266 #define GNRC_RPL_MOP_NON_STORING_MODE (0x01)
267 #define GNRC_RPL_MOP_STORING_MODE_NO_MC (0x02)
268 #define GNRC_RPL_MOP_STORING_MODE_MC (0x03)
269 
270 /* translate Kconfig options to final value */
271 #if IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NO_DOWNWARD_ROUTES)
272 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NO_DOWNWARD_ROUTES
273 #elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NON_STORING_MODE)
274 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NON_STORING_MODE
275 #elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_NO_MC)
276 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
277 #elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_MC)
278 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_MC
279 #endif
280 
282 #ifndef GNRC_RPL_DEFAULT_MOP
283 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
284 #endif
294 #define GNRC_RPL_COUNTER_MAX (255)
295 #define GNRC_RPL_COUNTER_LOWER_REGION (127)
296 #define GNRC_RPL_COUNTER_SEQ_WINDOW (16)
297 #define GNRC_RPL_COUNTER_INIT (GNRC_RPL_COUNTER_MAX - GNRC_RPL_COUNTER_SEQ_WINDOW + 1)
298 
299 static inline uint8_t GNRC_RPL_COUNTER_INCREMENT(uint8_t counter)
300 {
301  return ((counter > GNRC_RPL_COUNTER_LOWER_REGION) ?
302  ((counter == GNRC_RPL_COUNTER_MAX) ? counter = 0 : ++counter) :
303  ((counter == GNRC_RPL_COUNTER_LOWER_REGION) ? counter = 0 : ++counter));
304 }
305 
306 static inline bool GNRC_RPL_COUNTER_IS_INIT(uint8_t counter)
307 {
308  return (counter > GNRC_RPL_COUNTER_LOWER_REGION);
309 }
310 
311 static inline bool GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B)
312 {
313  return (((A < B) && (GNRC_RPL_COUNTER_LOWER_REGION + 1 - B + A < GNRC_RPL_COUNTER_SEQ_WINDOW))
314  || ((A > B) && (A - B < GNRC_RPL_COUNTER_SEQ_WINDOW)));
315 }
316 
317 static inline bool GNRC_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
318 {
319  return ((A > GNRC_RPL_COUNTER_LOWER_REGION) ? ((B > GNRC_RPL_COUNTER_LOWER_REGION) ?
320  GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) :
321  ((B > GNRC_RPL_COUNTER_LOWER_REGION) ? 1 : GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B)));
322 }
332 #ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS
333 #define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS (20)
334 #endif
335 
336 #ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN
337 #define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN (3)
338 #endif
339 
340 #ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT
341 #define CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT (10)
342 #endif
353 #ifndef CONFIG_GNRC_RPL_DEFAULT_LIFETIME
354 #define CONFIG_GNRC_RPL_DEFAULT_LIFETIME (5)
355 #endif
356 #ifndef CONFIG_GNRC_RPL_LIFETIME_UNIT
357 #define CONFIG_GNRC_RPL_LIFETIME_UNIT (60)
358 #endif
364 #define GNRC_RPL_DEFAULT_PREFIX_LEN (64)
365 
373 #define GNRC_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)
374 
381 #define GNRC_RPL_GROUNDED (1)
382 
390 #ifndef CONFIG_GNRC_RPL_DAO_SEND_RETRIES
391 #define CONFIG_GNRC_RPL_DAO_SEND_RETRIES (4)
392 #endif
393 #ifndef CONFIG_GNRC_RPL_DAO_ACK_DELAY
394 #define CONFIG_GNRC_RPL_DAO_ACK_DELAY (3000UL)
395 #endif
396 #ifndef CONFIG_GNRC_RPL_DAO_DELAY_LONG
400 #define CONFIG_GNRC_RPL_DAO_DELAY_LONG (60000UL)
401 #endif
402 #ifndef CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT
406 #define CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT (1000UL)
407 #endif
408 #ifndef CONFIG_GNRC_RPL_DAO_DELAY_JITTER
412 #define CONFIG_GNRC_RPL_DAO_DELAY_JITTER (1000UL)
413 #endif
419 #ifndef CONFIG_GNRC_RPL_CLEANUP_TIME
420 #define CONFIG_GNRC_RPL_CLEANUP_TIME (5 * MS_PER_SEC)
421 #endif
422 
427 #define GNRC_RPL_NORMAL_NODE (0)
428 #define GNRC_RPL_ROOT_NODE (1)
429 #define GNRC_RPL_LEAF_NODE (2)
442 #define GNRC_RPL_OPT_PAD1 (0)
446 #define GNRC_RPL_OPT_PADN (1)
450 #define GNRC_RPL_OPT_DAG_METRIC_CONTAINER (2)
454 #define GNRC_RPL_OPT_ROUTE_INFO (3)
458 #define GNRC_RPL_OPT_DODAG_CONF (4)
462 #define GNRC_RPL_OPT_TARGET (5)
466 #define GNRC_RPL_OPT_TRANSIT (6)
471 #define GNRC_RPL_OPT_TRANSIT_E_FLAG_SHIFT (7)
475 #define GNRC_RPL_OPT_SOLICITED_INFO (7)
479 #define GNRC_RPL_OPT_PREFIX_INFO (8)
484 #define GNRC_RPL_PREFIX_AUTO_ADDRESS_BIT (1 << 6)
488 #define GNRC_RPL_OPT_TARGET_DESC (9)
501 #define GNRC_RPL_GROUNDED_SHIFT (7)
505 #define GNRC_RPL_MOP_SHIFT (3)
509 #define GNRC_RPL_SHIFTED_MOP_MASK (0x7)
513 #define GNRC_RPL_PRF_MASK (0x7)
520 #define GNRC_RPL_ROOT_RANK (CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE)
521 
528 #define GNRC_RPL_ICMPV6_CODE_DIS (0x00)
529 
536 #define GNRC_RPL_ICMPV6_CODE_DIO (0x01)
537 
544 #define GNRC_RPL_ICMPV6_CODE_DAO (0x02)
545 
552 #define GNRC_RPL_ICMPV6_CODE_DAO_ACK (0x03)
553 
557 #define GNRC_RPL_LIFETIME_UPDATE_STEP (2)
558 
565 #define DAGRANK(rank,mhri) (rank/mhri)
566 
574 #define GNRC_RPL_INSTANCE_ID_MSB (1 << 7)
575 #define GNRC_RPL_GLOBAL_INSTANCE_MASK (0x7F)
576 #define GNRC_RPL_LOCAL_INSTANCE_MASK (0x3F)
577 #define GNRC_RPL_INSTANCE_D_FLAG_MASK (1 << 6)
587 #define GNRC_RPL_DIS_SOLICITED_INFO_LENGTH (19)
588 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_V (1 << 7)
589 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_I (1 << 6)
590 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_D (1 << 5)
597 
602 
603 #ifdef MODULE_NETSTATS_RPL
617 extern netstats_rpl_t gnrc_rpl_netstats;
618 #endif
619 
623 #ifndef CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES
624 #define CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES (3)
625 #endif
626 
630 #ifndef CONFIG_GNRC_RPL_DEFAULT_NETIF
631 #define CONFIG_GNRC_RPL_DEFAULT_NETIF (KERNEL_PID_UNDEF)
632 #endif
633 
643 
657 gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, const ipv6_addr_t *dodag_id,
658  bool gen_inst_id, bool local_inst_id);
659 
666 void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination);
667 
676 void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination,
677  gnrc_rpl_internal_opt_t **options, size_t num_opts);
678 
686 void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime);
687 
695 void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq);
696 
707  ipv6_addr_t *dst, uint16_t len);
708 
719  uint16_t len);
720 
731  uint16_t len);
732 
743  ipv6_addr_t *dst, uint16_t len);
744 
751 
758 
769 gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, const ipv6_addr_t *dodag_id,
770  uint8_t mop);
771 
782  ipv6_addr_t *dodag_id);
783 
792 uint8_t gnrc_rpl_gen_instance_id(bool local);
793 
802 static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
803 {
804  if (!IS_ACTIVE(CONFIG_GNRC_RPL_WITHOUT_PIO)) {
805  dodag->dio_opts = (dodag->dio_opts & ~GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO) |
806  (status << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT);
807  }
808 }
809 
810 #if IS_USED(MODULE_GNRC_RPL) || DOXYGEN
817 void gnrc_rpl_configure_root(gnrc_netif_t *netif, const ipv6_addr_t *dodag_id);
818 #else
819 #define gnrc_rpl_configure_root(netif, dodag_id) ((void)netif)
820 #endif
821 
822 #ifdef __cplusplus
823 }
824 #endif
825 
DODAG-related functions for RPL.
Types and functions for FIB.
Definitions for GNRC's IPv6 implementation.
Includes all essential GNRC network stack base modules.
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:135
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.
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_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.
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.
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.
kernel_pid_t gnrc_rpl_pid
PID of the RPL thread.
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_instance_t * gnrc_rpl_root_init(uint8_t instance_id, const ipv6_addr_t *dodag_id, bool gen_inst_id, bool local_inst_id)
Initialization of a node as root.
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.
uint8_t gnrc_rpl_gen_instance_id(bool local)
Generate a local or global instance id.
gnrc_rpl_instance_t * gnrc_rpl_root_instance_init(uint8_t instance_id, const ipv6_addr_t *dodag_id, uint8_t mop)
Create a new RPL instance and RPL DODAG.
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:802
const ipv6_addr_t ipv6_addr_all_rpl_nodes
See GNRC_RPL_ALL_NODES_ADDR.
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.
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 gnrc_rpl_init(kernel_pid_t if_pid)
Initialization of the RPL thread.
void gnrc_rpl_configure_root(gnrc_netif_t *netif, const ipv6_addr_t *dodag_id)
Convenience function to start a RPL root using the default configuration.
void gnrc_rpl_long_delay_dao(gnrc_rpl_dodag_t *dodag)
Long delay the DAO sending interval.
void gnrc_rpl_delay_dao(gnrc_rpl_dodag_t *dodag)
Delay the DAO sending interval.
Definitions for IPv6 addresses.
Common macros and compiler attributes/pragmas configuration.
#define IS_ACTIVE(macro)
Allows to verify a macro definition outside the preprocessor.
Definition: modules.h:56
Protocol type definitions.
RPL Objective functions manager header.
Definition of RPL related packet statistics.
Representation of a network interface.
Definition: netif.h:129
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:105
Destination Advertisement Object Acknowledgement.
Definition: structs.h:163
Destination Advertisement Object.
Definition: structs.h:150
DIO Base Object.
Definition: structs.h:86
DODAG Information Solicitation.
Definition: structs.h:124
internal unpacked struct type for option insertion
Definition: structs.h:353
RPL statistics struct.
Definition: rpl_netstats.h:44
RPL data structs.
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition: structs.h:231
struct gnrc_rpl_dodag gnrc_rpl_dodag_t
DODAG representation.
Definition: structs.h:221
Trickle timer interface definition.
Data type to represent an IPv6 address.
Definition: addr.h:64