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 
98 #ifndef NET_GNRC_RPL_H
99 #define NET_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_MSG (0x0901)
162 
166 #define GNRC_RPL_MSG_TYPE_DAO_HANDLE (0x0903)
167 
174 #define GNRC_RPL_INFINITE_RANK (0xFFFF)
175 
182 #ifndef GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE
183 #define GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE (256)
184 #endif
185 
189 #ifndef GNRC_RPL_DEFAULT_MAX_RANK_INCREASE
190 #define GNRC_RPL_DEFAULT_MAX_RANK_INCREASE (0)
191 #endif
192 
196 #define GNRC_RPL_IMPLEMENTED_OFS_NUMOF (1)
197 
201 #define GNRC_RPL_DEFAULT_OCP (0)
202 
206 #ifndef GNRC_RPL_DEFAULT_INSTANCE
207 #define GNRC_RPL_DEFAULT_INSTANCE (0)
208 #endif
209 
214 #define GNRC_RPL_MOP_NO_DOWNWARD_ROUTES (0x00)
215 #define GNRC_RPL_MOP_NON_STORING_MODE (0x01)
216 #define GNRC_RPL_MOP_STORING_MODE_NO_MC (0x02)
217 #define GNRC_RPL_MOP_STORING_MODE_MC (0x03)
218 
220 #ifndef GNRC_RPL_DEFAULT_MOP
221 #define GNRC_RPL_DEFAULT_MOP GNRC_RPL_MOP_STORING_MODE_NO_MC
222 #endif
223 
232 #define GNRC_RPL_COUNTER_MAX (255)
233 #define GNRC_RPL_COUNTER_LOWER_REGION (127)
234 #define GNRC_RPL_COUNTER_SEQ_WINDOW (16)
235 #define GNRC_RPL_COUNTER_INIT (GNRC_RPL_COUNTER_MAX - GNRC_RPL_COUNTER_SEQ_WINDOW + 1)
236 
237 static inline uint8_t GNRC_RPL_COUNTER_INCREMENT(uint8_t counter)
238 {
239  return ((counter > GNRC_RPL_COUNTER_LOWER_REGION) ?
240  ((counter == GNRC_RPL_COUNTER_MAX) ? counter = 0 : ++counter) :
241  ((counter == GNRC_RPL_COUNTER_LOWER_REGION) ? counter = 0 : ++counter));
242 }
243 
244 static inline bool GNRC_RPL_COUNTER_IS_INIT(uint8_t counter)
245 {
246  return (counter > GNRC_RPL_COUNTER_LOWER_REGION);
247 }
248 
249 static inline bool GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(uint8_t A, uint8_t B)
250 {
251  return (((A < B) && (GNRC_RPL_COUNTER_LOWER_REGION + 1 - B + A < GNRC_RPL_COUNTER_SEQ_WINDOW))
252  || ((A > B) && (A - B < GNRC_RPL_COUNTER_SEQ_WINDOW)));
253 }
254 
255 static inline bool GNRC_RPL_COUNTER_GREATER_THAN(uint8_t A, uint8_t B)
256 {
257  return ((A > GNRC_RPL_COUNTER_LOWER_REGION) ? ((B > GNRC_RPL_COUNTER_LOWER_REGION) ?
258  GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B) : 0) :
259  ((B > GNRC_RPL_COUNTER_LOWER_REGION) ? 1 : GNRC_RPL_COUNTER_GREATER_THAN_LOCAL(A, B)));
260 }
270 #ifndef GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS
271 #define GNRC_RPL_DEFAULT_DIO_INTERVAL_DOUBLINGS (20)
272 #endif
273 
274 #ifndef GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN
275 #define GNRC_RPL_DEFAULT_DIO_INTERVAL_MIN (3)
276 #endif
277 
278 #ifndef GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT
279 #define GNRC_RPL_DEFAULT_DIO_REDUNDANCY_CONSTANT (10)
280 #endif
281 
291 #ifndef GNRC_RPL_DEFAULT_LIFETIME
292 #define GNRC_RPL_DEFAULT_LIFETIME (5)
293 #endif
294 #ifndef GNRC_RPL_LIFETIME_UNIT
295 #define GNRC_RPL_LIFETIME_UNIT (60)
296 #endif
297 
302 #define GNRC_RPL_DEFAULT_PREFIX_LEN (64)
303 
311 #define GNRC_RPL_DEFAULT_PREFIX_LIFETIME (0xFFFFFFFF)
312 
319 #define GNRC_RPL_GROUNDED (1)
320 
328 #ifndef GNRC_RPL_DAO_SEND_RETRIES
329 #define GNRC_RPL_DAO_SEND_RETRIES (4)
330 #endif
331 #ifndef GNRC_RPL_DAO_ACK_DELAY
332 #define GNRC_RPL_DAO_ACK_DELAY (3000UL)
333 #endif
334 #ifndef GNRC_RPL_DAO_DELAY_LONG
335 
338 #define GNRC_RPL_DAO_DELAY_LONG (60000UL)
339 #endif
340 #ifndef GNRC_RPL_DAO_DELAY_DEFAULT
341 
344 #define GNRC_RPL_DAO_DELAY_DEFAULT (1000UL)
345 #endif
346 #ifndef GNRC_RPL_DAO_DELAY_JITTER
347 
350 #define GNRC_RPL_DAO_DELAY_JITTER (1000UL)
351 #endif
352 
357 #ifndef GNRC_RPL_CLEANUP_TIME
358 #define GNRC_RPL_CLEANUP_TIME (5 * MS_PER_SEC)
359 #endif
360 
365 #define GNRC_RPL_NORMAL_NODE (0)
366 #define GNRC_RPL_ROOT_NODE (1)
367 #define GNRC_RPL_LEAF_NODE (2)
368 
378 #define GNRC_RPL_OPT_PAD1 (0)
379 #define GNRC_RPL_OPT_PADN (1)
380 #define GNRC_RPL_OPT_DAG_METRIC_CONTAINER (2)
381 #define GNRC_RPL_OPT_ROUTE_INFO (3)
382 #define GNRC_RPL_OPT_DODAG_CONF (4)
383 #define GNRC_RPL_OPT_TARGET (5)
384 #define GNRC_RPL_OPT_TRANSIT (6)
385 #define GNRC_RPL_OPT_SOLICITED_INFO (7)
386 #define GNRC_RPL_OPT_PREFIX_INFO (8)
387 #define GNRC_RPL_OPT_TARGET_DESC (9)
388 
393 #define GNRC_RPL_ROOT_RANK (GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE)
394 
401 #define GNRC_RPL_ICMPV6_CODE_DIS (0x00)
402 
409 #define GNRC_RPL_ICMPV6_CODE_DIO (0x01)
410 
417 #define GNRC_RPL_ICMPV6_CODE_DAO (0x02)
418 
425 #define GNRC_RPL_ICMPV6_CODE_DAO_ACK (0x03)
426 
430 #define GNRC_RPL_LIFETIME_UPDATE_STEP (2)
431 
438 #define DAGRANK(rank,mhri) (rank/mhri)
439 
447 #define GNRC_RPL_INSTANCE_ID_MSB (1 << 7)
448 #define GNRC_RPL_GLOBAL_INSTANCE_MASK (0x7F)
449 #define GNRC_RPL_LOCAL_INSTANCE_MASK (0x3F)
450 #define GNRC_RPL_INSTANCE_D_FLAG_MASK (1 << 6)
451 
460 #define GNRC_RPL_DIS_SOLICITED_INFO_LENGTH (19)
461 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_V (1 << 7)
462 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_I (1 << 6)
463 #define GNRC_RPL_DIS_SOLICITED_INFO_FLAG_D (1 << 5)
464 
470 
475 
476 #ifdef MODULE_NETSTATS_RPL
477 
480 extern netstats_rpl_t gnrc_rpl_netstats;
481 #endif
482 
486 #ifndef GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES
487 #define GNRC_RPL_PARENT_TIMEOUT_DIS_RETRIES (3)
488 #endif
489 
499 
513 gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
514  bool gen_inst_id, bool local_inst_id);
515 
522 void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination);
523 
532 void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination,
533  gnrc_rpl_internal_opt_t **options, size_t num_opts);
534 
542 void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime);
543 
551 void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq);
552 
563  ipv6_addr_t *dst, uint16_t len);
564 
575  uint16_t len);
576 
587  uint16_t len);
588 
599  ipv6_addr_t *dst, uint16_t len);
600 
607 
614 
625 gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
626  uint8_t mop);
627 
638  ipv6_addr_t *dodag_id);
639 
648 uint8_t gnrc_rpl_gen_instance_id(bool local);
649 
650 #ifndef GNRC_RPL_WITHOUT_PIO
651 
658 static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
659 {
660  dodag->dio_opts = (dodag->dio_opts & ~GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO) |
661  (status << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT);
662 }
663 #endif
664 
665 #ifdef __cplusplus
666 }
667 #endif
668 
669 #endif /* NET_GNRC_RPL_H */
670 
Trickle timer interface definition.
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.
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 instace to the destination.
RPL Objective functions manager header.
DIO Base Object.
Definition: structs.h:90
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.
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition: structs.h:235
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&#39;s IPv6 implementation.
DODAG-related functions for RPL.
xtimer interface definitions
Destination Advertisement Object.
Definition: structs.h:154
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:658
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:128
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.
internal unpacked struct type for option insertion
Definition: structs.h:336
const ipv6_addr_t ipv6_addr_all_rpl_nodes
Destination Advertisement Object Acknowledgement.
Definition: structs.h:167
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:225
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.