Loading...
Searching...
No Matches
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
11#pragma once
12
142
143#include <string.h>
144#include <stdint.h>
145#include "modules.h"
146#include "net/gnrc.h"
147#include "net/gnrc/ipv6.h"
148#include "net/ipv6/addr.h"
149#include "net/gnrc/nettype.h"
150#include "net/gnrc/rpl/structs.h"
151#include "net/gnrc/rpl/dodag.h"
153#include "net/fib.h"
154#include "trickle.h"
155
156#ifdef MODULE_NETSTATS_RPL
157#include "net/rpl/rpl_netstats.h"
158#endif
159
160#ifdef __cplusplus
161extern "C" {
162#endif
163
167#ifndef GNRC_RPL_STACK_SIZE
168#define GNRC_RPL_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
169#endif
170
174#ifndef GNRC_RPL_PRIO
175#define GNRC_RPL_PRIO (GNRC_IPV6_PRIO + 1)
176#endif
177
186#ifndef CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP
187#define CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP (3U)
188#endif
189
193#ifndef GNRC_RPL_MSG_QUEUE_SIZE
194#define GNRC_RPL_MSG_QUEUE_SIZE (1 << CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP)
195#endif
196
205#define GNRC_RPL_ALL_NODES_ADDR {{ 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1a }}
206
210#define GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE (0x0900)
211
215#define GNRC_RPL_MSG_TYPE_TRICKLE_MSG (0x0901)
216
220#define GNRC_RPL_MSG_TYPE_DAO_HANDLE (0x0903)
221
228#define GNRC_RPL_INFINITE_RANK (0xFFFF)
229
236#ifndef CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE
237#define CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE (256)
238#endif
239
243#ifndef CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE
244#define CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE (0)
245#endif
246
250#define GNRC_RPL_IMPLEMENTED_OFS_NUMOF (1)
251
255#define GNRC_RPL_DEFAULT_OCP (0)
256
260#ifndef CONFIG_GNRC_RPL_DEFAULT_INSTANCE
261#define CONFIG_GNRC_RPL_DEFAULT_INSTANCE (0)
262#endif
263
268#define GNRC_RPL_MOP_NO_DOWNWARD_ROUTES (0x00)
269#define GNRC_RPL_MOP_NON_STORING_MODE (0x01)
270#define GNRC_RPL_MOP_STORING_MODE_NO_MC (0x02)
271#define GNRC_RPL_MOP_STORING_MODE_MC (0x03)
272
273/* translate Kconfig options to final value */
274#if IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NO_DOWNWARD_ROUTES)
275#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NO_DOWNWARD_ROUTES
276#elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NON_STORING_MODE)
277#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NON_STORING_MODE
278#elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_NO_MC)
279#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
280#elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_MC)
281#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_MC
282#endif
283
285#ifndef GNRC_RPL_DEFAULT_MOP
286#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
287#endif
289
297#define GNRC_RPL_COUNTER_MAX (255)
298#define GNRC_RPL_COUNTER_LOWER_REGION (127)
299#define GNRC_RPL_COUNTER_SEQ_WINDOW (16)
300#define GNRC_RPL_COUNTER_INIT (GNRC_RPL_COUNTER_MAX - GNRC_RPL_COUNTER_SEQ_WINDOW + 1)
301
302static inline uint8_t GNRC_RPL_COUNTER_INCREMENT(uint8_t counter)
303{
304 return ((counter > GNRC_RPL_COUNTER_LOWER_REGION) ?
305 ((counter == GNRC_RPL_COUNTER_MAX) ? counter = 0 : ++counter) :
306 ((counter == GNRC_RPL_COUNTER_LOWER_REGION) ? counter = 0 : ++counter));
307}
308
309static inline bool GNRC_RPL_COUNTER_IS_INIT(uint8_t counter)
310{
311 return (counter > GNRC_RPL_COUNTER_LOWER_REGION);
312}
313
314static inline bool GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B)
315{
316 return (((A < B) && (GNRC_RPL_COUNTER_LOWER_REGION + 1 - B + A < GNRC_RPL_COUNTER_SEQ_WINDOW))
317 || ((A > B) && (A - B < GNRC_RPL_COUNTER_SEQ_WINDOW)));
318}
319
320static inline bool GNRC_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
321{
322 return ((A > GNRC_RPL_COUNTER_LOWER_REGION) ? ((B > GNRC_RPL_COUNTER_LOWER_REGION) ?
323 GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) :
324 ((B > GNRC_RPL_COUNTER_LOWER_REGION) ? 1 : GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B)));
325}
327
335#ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS
336#define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS (20)
337#endif
338
339#ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN
340#define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN (3)
341#endif
342
343#ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT
344#define CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT (10)
345#endif
347
356#ifndef CONFIG_GNRC_RPL_DEFAULT_LIFETIME
357#define CONFIG_GNRC_RPL_DEFAULT_LIFETIME (5)
358#endif
359#ifndef CONFIG_GNRC_RPL_LIFETIME_UNIT
360#define CONFIG_GNRC_RPL_LIFETIME_UNIT (60)
361#endif
363
367#define GNRC_RPL_DEFAULT_PREFIX_LEN (64)
368
376#define GNRC_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)
377
384#define GNRC_RPL_GROUNDED (1)
385
393#ifndef CONFIG_GNRC_RPL_DAO_SEND_RETRIES
394#define CONFIG_GNRC_RPL_DAO_SEND_RETRIES (4)
395#endif
396#ifndef CONFIG_GNRC_RPL_DAO_ACK_DELAY
397#define CONFIG_GNRC_RPL_DAO_ACK_DELAY (3000UL)
398#endif
399#ifndef CONFIG_GNRC_RPL_DAO_DELAY_LONG
403#define CONFIG_GNRC_RPL_DAO_DELAY_LONG (60000UL)
404#endif
405#ifndef CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT
409#define CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT (1000UL)
410#endif
411#ifndef CONFIG_GNRC_RPL_DAO_DELAY_JITTER
415#define CONFIG_GNRC_RPL_DAO_DELAY_JITTER (1000UL)
416#endif
418
422#ifndef CONFIG_GNRC_RPL_CLEANUP_TIME
423#define CONFIG_GNRC_RPL_CLEANUP_TIME (5 * MS_PER_SEC)
424#endif
425
430#define GNRC_RPL_NORMAL_NODE (0)
431#define GNRC_RPL_ROOT_NODE (1)
432#define GNRC_RPL_LEAF_NODE (2)
434
442#define GNRC_RPL_OPT_PAD1 (0)
443#define GNRC_RPL_OPT_PADN (1)
444#define GNRC_RPL_OPT_DAG_METRIC_CONTAINER (2)
445#define GNRC_RPL_OPT_ROUTE_INFO (3)
446#define GNRC_RPL_OPT_DODAG_CONF (4)
447#define GNRC_RPL_OPT_TARGET (5)
448#define GNRC_RPL_OPT_TRANSIT (6)
449#define GNRC_RPL_OPT_SOLICITED_INFO (7)
450#define GNRC_RPL_OPT_PREFIX_INFO (8)
451#define GNRC_RPL_OPT_TARGET_DESC (9)
453
457#define GNRC_RPL_ROOT_RANK (CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE)
458
465#define GNRC_RPL_ICMPV6_CODE_DIS (0x00)
466
473#define GNRC_RPL_ICMPV6_CODE_DIO (0x01)
474
481#define GNRC_RPL_ICMPV6_CODE_DAO (0x02)
482
489#define GNRC_RPL_ICMPV6_CODE_DAO_ACK (0x03)
490
494#define GNRC_RPL_LIFETIME_UPDATE_STEP (2)
495
502#define DAGRANK(rank,mhri) (rank/mhri)
503
511#define GNRC_RPL_INSTANCE_ID_MSB (1 << 7)
512#define GNRC_RPL_GLOBAL_INSTANCE_MASK (0x7F)
513#define GNRC_RPL_LOCAL_INSTANCE_MASK (0x3F)
514#define GNRC_RPL_INSTANCE_D_FLAG_MASK (1 << 6)
516
524#define GNRC_RPL_DIS_SOLICITED_INFO_LENGTH (19)
525#define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_V (1 << 7)
526#define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_I (1 << 6)
527#define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_D (1 << 5)
529
534
539
540#ifdef MODULE_NETSTATS_RPL
554extern netstats_rpl_t gnrc_rpl_netstats;
555#endif
556
560#ifndef CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES
561#define CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES (3)
562#endif
563
567#ifndef CONFIG_GNRC_RPL_DEFAULT_NETIF
568#define CONFIG_GNRC_RPL_DEFAULT_NETIF (KERNEL_PID_UNDEF)
569#endif
570
580
594gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, const ipv6_addr_t *dodag_id,
595 bool gen_inst_id, bool local_inst_id);
596
604
614 gnrc_rpl_internal_opt_t **options, size_t num_opts);
615
623void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime);
624
632void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq);
633
644 ipv6_addr_t *dst, uint16_t len);
645
656 uint16_t len);
657
668 uint16_t len);
669
680 ipv6_addr_t *dst, uint16_t len);
681
688
695
706gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, const ipv6_addr_t *dodag_id,
707 uint8_t mop);
708
719 ipv6_addr_t *dodag_id);
720
729uint8_t gnrc_rpl_gen_instance_id(bool local);
730
739static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
740{
741 if (!IS_ACTIVE(CONFIG_GNRC_RPL_WITHOUT_PIO)) {
742 dodag->dio_opts = (dodag->dio_opts & ~GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO) |
743 (status << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT);
744 }
745}
746
747#if IS_USED(MODULE_GNRC_RPL) || DOXYGEN
755#else
756#define gnrc_rpl_configure_root(netif, dodag_id) ((void)netif)
757#endif
758
759#ifdef __cplusplus
760}
761#endif
762
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:138
struct gnrc_pktsnip gnrc_pktsnip_t
Type to represent parts (either headers or payload) of a packet, called snips.
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.
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.
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.
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_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.
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:739
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:59
Protocol type definitions.
RPL Objective functions manager header.
Definition of RPL related packet statistics.
Representation of a network interface.
Definition netif.h:135
Destination Advertisement Object Acknowledgement.
Definition structs.h:166
Destination Advertisement Object.
Definition structs.h:153
DIO Base Object.
Definition structs.h:89
DODAG Information Solicitation.
Definition structs.h:127
internal unpacked struct type for option insertion
Definition structs.h:356
RPL statistics struct.
RPL data structs.
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition structs.h:234
struct gnrc_rpl_dodag gnrc_rpl_dodag_t
DODAG representation.
Definition structs.h:224
Trickle timer interface definition.
Data type to represent an IPv6 address.
Definition addr.h:67