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
141#ifndef NET_GNRC_RPL_H
142#define NET_GNRC_RPL_H
143
144#include <string.h>
145#include <stdint.h>
146#include "modules.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"
154#include "net/fib.h"
155#include "trickle.h"
156
157#ifdef MODULE_NETSTATS_RPL
158#include "net/rpl/rpl_netstats.h"
159#endif
160
161#ifdef __cplusplus
162extern "C" {
163#endif
164
168#ifndef GNRC_RPL_STACK_SIZE
169#define GNRC_RPL_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
170#endif
171
175#ifndef GNRC_RPL_PRIO
176#define GNRC_RPL_PRIO (GNRC_IPV6_PRIO + 1)
177#endif
178
187#ifndef CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP
188#define CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP (3U)
189#endif
190
194#ifndef GNRC_RPL_MSG_QUEUE_SIZE
195#define GNRC_RPL_MSG_QUEUE_SIZE (1 << CONFIG_GNRC_RPL_MSG_QUEUE_SIZE_EXP)
196#endif
197
206#define GNRC_RPL_ALL_NODES_ADDR {{ 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1a }}
207
211#define GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE (0x0900)
212
216#define GNRC_RPL_MSG_TYPE_TRICKLE_MSG (0x0901)
217
221#define GNRC_RPL_MSG_TYPE_DAO_HANDLE (0x0903)
222
229#define GNRC_RPL_INFINITE_RANK (0xFFFF)
230
237#ifndef CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE
238#define CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE (256)
239#endif
240
244#ifndef CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE
245#define CONFIG_GNRC_RPL_DEFAULT_MAX_RANK_INCREASE (0)
246#endif
247
251#define GNRC_RPL_IMPLEMENTED_OFS_NUMOF (1)
252
256#define GNRC_RPL_DEFAULT_OCP (0)
257
261#ifndef CONFIG_GNRC_RPL_DEFAULT_INSTANCE
262#define CONFIG_GNRC_RPL_DEFAULT_INSTANCE (0)
263#endif
264
269#define GNRC_RPL_MOP_NO_DOWNWARD_ROUTES (0x00)
270#define GNRC_RPL_MOP_NON_STORING_MODE (0x01)
271#define GNRC_RPL_MOP_STORING_MODE_NO_MC (0x02)
272#define GNRC_RPL_MOP_STORING_MODE_MC (0x03)
273
274/* translate Kconfig options to final value */
275#if IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NO_DOWNWARD_ROUTES)
276#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NO_DOWNWARD_ROUTES
277#elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_NON_STORING_MODE)
278#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_NON_STORING_MODE
279#elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_NO_MC)
280#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
281#elif IS_ACTIVE(CONFIG_GNRC_RPL_MOP_STORING_MODE_MC)
282#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_MC
283#endif
284
286#ifndef GNRC_RPL_DEFAULT_MOP
287#define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
288#endif
298#define GNRC_RPL_COUNTER_MAX (255)
299#define GNRC_RPL_COUNTER_LOWER_REGION (127)
300#define GNRC_RPL_COUNTER_SEQ_WINDOW (16)
301#define GNRC_RPL_COUNTER_INIT (GNRC_RPL_COUNTER_MAX - GNRC_RPL_COUNTER_SEQ_WINDOW + 1)
302
303static inline uint8_t GNRC_RPL_COUNTER_INCREMENT(uint8_t counter)
304{
305 return ((counter > GNRC_RPL_COUNTER_LOWER_REGION) ?
306 ((counter == GNRC_RPL_COUNTER_MAX) ? counter = 0 : ++counter) :
307 ((counter == GNRC_RPL_COUNTER_LOWER_REGION) ? counter = 0 : ++counter));
308}
309
310static inline bool GNRC_RPL_COUNTER_IS_INIT(uint8_t counter)
311{
312 return (counter > GNRC_RPL_COUNTER_LOWER_REGION);
313}
314
315static inline bool GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B)
316{
317 return (((A < B) && (GNRC_RPL_COUNTER_LOWER_REGION + 1 - B + A < GNRC_RPL_COUNTER_SEQ_WINDOW))
318 || ((A > B) && (A - B < GNRC_RPL_COUNTER_SEQ_WINDOW)));
319}
320
321static inline bool GNRC_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
322{
323 return ((A > GNRC_RPL_COUNTER_LOWER_REGION) ? ((B > GNRC_RPL_COUNTER_LOWER_REGION) ?
324 GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) :
325 ((B > GNRC_RPL_COUNTER_LOWER_REGION) ? 1 : GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B)));
326}
336#ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS
337#define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS (20)
338#endif
339
340#ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN
341#define CONFIG_GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN (3)
342#endif
343
344#ifndef CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT
345#define CONFIG_GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT (10)
346#endif
357#ifndef CONFIG_GNRC_RPL_DEFAULT_LIFETIME
358#define CONFIG_GNRC_RPL_DEFAULT_LIFETIME (5)
359#endif
360#ifndef CONFIG_GNRC_RPL_LIFETIME_UNIT
361#define CONFIG_GNRC_RPL_LIFETIME_UNIT (60)
362#endif
368#define GNRC_RPL_DEFAULT_PREFIX_LEN (64)
369
377#define GNRC_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)
378
385#define GNRC_RPL_GROUNDED (1)
386
394#ifndef CONFIG_GNRC_RPL_DAO_SEND_RETRIES
395#define CONFIG_GNRC_RPL_DAO_SEND_RETRIES (4)
396#endif
397#ifndef CONFIG_GNRC_RPL_DAO_ACK_DELAY
398#define CONFIG_GNRC_RPL_DAO_ACK_DELAY (3000UL)
399#endif
400#ifndef CONFIG_GNRC_RPL_DAO_DELAY_LONG
404#define CONFIG_GNRC_RPL_DAO_DELAY_LONG (60000UL)
405#endif
406#ifndef CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT
410#define CONFIG_GNRC_RPL_DAO_DELAY_DEFAULT (1000UL)
411#endif
412#ifndef CONFIG_GNRC_RPL_DAO_DELAY_JITTER
416#define CONFIG_GNRC_RPL_DAO_DELAY_JITTER (1000UL)
417#endif
423#ifndef CONFIG_GNRC_RPL_CLEANUP_TIME
424#define CONFIG_GNRC_RPL_CLEANUP_TIME (5 * MS_PER_SEC)
425#endif
426
431#define GNRC_RPL_NORMAL_NODE (0)
432#define GNRC_RPL_ROOT_NODE (1)
433#define GNRC_RPL_LEAF_NODE (2)
443#define GNRC_RPL_OPT_PAD1 (0)
444#define GNRC_RPL_OPT_PADN (1)
445#define GNRC_RPL_OPT_DAG_METRIC_CONTAINER (2)
446#define GNRC_RPL_OPT_ROUTE_INFO (3)
447#define GNRC_RPL_OPT_DODAG_CONF (4)
448#define GNRC_RPL_OPT_TARGET (5)
449#define GNRC_RPL_OPT_TRANSIT (6)
450#define GNRC_RPL_OPT_SOLICITED_INFO (7)
451#define GNRC_RPL_OPT_PREFIX_INFO (8)
452#define GNRC_RPL_OPT_TARGET_DESC (9)
458#define GNRC_RPL_ROOT_RANK (CONFIG_GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE)
459
466#define GNRC_RPL_ICMPV6_CODE_DIS (0x00)
467
474#define GNRC_RPL_ICMPV6_CODE_DIO (0x01)
475
482#define GNRC_RPL_ICMPV6_CODE_DAO (0x02)
483
490#define GNRC_RPL_ICMPV6_CODE_DAO_ACK (0x03)
491
495#define GNRC_RPL_LIFETIME_UPDATE_STEP (2)
496
503#define DAGRANK(rank,mhri) (rank/mhri)
504
512#define GNRC_RPL_INSTANCE_ID_MSB (1 << 7)
513#define GNRC_RPL_GLOBAL_INSTANCE_MASK (0x7F)
514#define GNRC_RPL_LOCAL_INSTANCE_MASK (0x3F)
515#define GNRC_RPL_INSTANCE_D_FLAG_MASK (1 << 6)
525#define GNRC_RPL_DIS_SOLICITED_INFO_LENGTH (19)
526#define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_V (1 << 7)
527#define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_I (1 << 6)
528#define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_D (1 << 5)
535
540
541#ifdef MODULE_NETSTATS_RPL
555extern netstats_rpl_t gnrc_rpl_netstats;
556#endif
557
561#ifndef CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES
562#define CONFIG_GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES (3)
563#endif
564
568#ifndef CONFIG_GNRC_RPL_DEFAULT_NETIF
569#define CONFIG_GNRC_RPL_DEFAULT_NETIF (KERNEL_PID_UNDEF)
570#endif
571
581
595gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, const ipv6_addr_t *dodag_id,
596 bool gen_inst_id, bool local_inst_id);
597
605
615 gnrc_rpl_internal_opt_t **options, size_t num_opts);
616
624void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime);
625
633void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq);
634
645 ipv6_addr_t *dst, uint16_t len);
646
657 uint16_t len);
658
669 uint16_t len);
670
681 ipv6_addr_t *dst, uint16_t len);
682
689
696
707gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, const ipv6_addr_t *dodag_id,
708 uint8_t mop);
709
720 ipv6_addr_t *dodag_id);
721
730uint8_t gnrc_rpl_gen_instance_id(bool local);
731
740static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
741{
742 if (!IS_ACTIVE(CONFIG_GNRC_RPL_WITHOUT_PIO)) {
743 dodag->dio_opts = (dodag->dio_opts & ~GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO) |
744 (status << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT);
745 }
746}
747
748#if IS_USED(MODULE_GNRC_RPL) || DOXYGEN
756#else
757#define gnrc_rpl_configure_root(netif, dodag_id) ((void)netif)
758#endif
759
760#ifdef __cplusplus
761}
762#endif
763
764#endif /* NET_GNRC_RPL_H */
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:139
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:740
const ipv6_addr_t ipv6_addr_all_rpl_nodes
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:60
Protocol type definitions.
RPL Objective functions manager header.
Definition of RPL related packet statistics.
Representation of a network interface.
Definition netif.h:135
Type to represent parts (either headers or payload) of a packet, called snips.
Definition pkt.h:108
Destination Advertisement Object Acknowledgement.
Definition structs.h:167
Destination Advertisement Object.
Definition structs.h:154
DIO Base Object.
Definition structs.h:90
DODAG Information Solicitation.
Definition structs.h:128
internal unpacked struct type for option insertion
Definition structs.h:357
RPL statistics struct.
RPL data structs.
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition structs.h:235
struct gnrc_rpl_dodag gnrc_rpl_dodag_t
DODAG representation.
Definition structs.h:225
Trickle timer interface definition.
Data type to represent an IPv6 address.
Definition addr.h:72