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 Cenk Gündoğan <cnkgndgn@gmail.com>
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_DEFAULT_WAIT_FOR_DAO_ACK
332 #define GNRC_RPL_DEFAULT_WAIT_FOR_DAO_ACK (3)
333 #endif
334 #ifndef GNRC_RPL_REGULAR_DAO_INTERVAL
335 #define GNRC_RPL_REGULAR_DAO_INTERVAL (60)
336 #endif
337 #ifndef GNRC_RPL_DEFAULT_DAO_DELAY
338 #define GNRC_RPL_DEFAULT_DAO_DELAY (1)
339 #endif
340 
345 #define GNRC_RPL_CLEANUP_TIME (5)
346 
351 #define GNRC_RPL_NORMAL_NODE (0)
352 #define GNRC_RPL_ROOT_NODE (1)
353 #define GNRC_RPL_LEAF_NODE (2)
354 
364 #define GNRC_RPL_OPT_PAD1 (0)
365 #define GNRC_RPL_OPT_PADN (1)
366 #define GNRC_RPL_OPT_DAG_METRIC_CONTAINER (2)
367 #define GNRC_RPL_OPT_ROUTE_INFO (3)
368 #define GNRC_RPL_OPT_DODAG_CONF (4)
369 #define GNRC_RPL_OPT_TARGET (5)
370 #define GNRC_RPL_OPT_TRANSIT (6)
371 #define GNRC_RPL_OPT_SOLICITED_INFO (7)
372 #define GNRC_RPL_OPT_PREFIX_INFO (8)
373 #define GNRC_RPL_OPT_TARGET_DESC (9)
374 
379 #define GNRC_RPL_ROOT_RANK (GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE)
380 
387 #define GNRC_RPL_ICMPV6_CODE_DIS (0x00)
388 
395 #define GNRC_RPL_ICMPV6_CODE_DIO (0x01)
396 
403 #define GNRC_RPL_ICMPV6_CODE_DAO (0x02)
404 
411 #define GNRC_RPL_ICMPV6_CODE_DAO_ACK (0x03)
412 
416 #define GNRC_RPL_LIFETIME_UPDATE_STEP (2)
417 
424 #define DAGRANK(rank,mhri) (rank/mhri)
425 
433 #define GNRC_RPL_INSTANCE_ID_MSB (1 << 7)
434 #define GNRC_RPL_GLOBAL_INSTANCE_MASK (0x7F)
435 #define GNRC_RPL_LOCAL_INSTANCE_MASK (0x3F)
436 #define GNRC_RPL_INSTANCE_D_FLAG_MASK (1 << 6)
437 
443 
448 
449 #ifdef MODULE_NETSTATS_RPL
450 
453 extern netstats_rpl_t gnrc_rpl_netstats;
454 #endif
455 
465 
479 gnrc_rpl_instance_t *gnrc_rpl_root_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
480  bool gen_inst_id, bool local_inst_id);
481 
488 void gnrc_rpl_send_DIO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination);
489 
496 void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination);
497 
505 void gnrc_rpl_send_DAO(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t lifetime);
506 
514 void gnrc_rpl_send_DAO_ACK(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination, uint8_t seq);
515 
526  ipv6_addr_t *dst, uint16_t len);
527 
538  uint16_t len);
539 
550  uint16_t len);
551 
562  ipv6_addr_t *dst, uint16_t len);
563 
570 
577 
588 gnrc_rpl_instance_t *gnrc_rpl_root_instance_init(uint8_t instance_id, ipv6_addr_t *dodag_id,
589  uint8_t mop);
590 
601  ipv6_addr_t *dodag_id);
602 
611 uint8_t gnrc_rpl_gen_instance_id(bool local);
612 
613 #ifndef GNRC_RPL_WITHOUT_PIO
614 
621 static inline void gnrc_rpl_config_pio(gnrc_rpl_dodag_t *dodag, bool status)
622 {
623  dodag->dio_opts = (dodag->dio_opts & ~GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO) |
624  (status << GNRC_RPL_REQ_DIO_OPT_PREFIX_INFO_SHIFT);
625 }
626 #endif
627 
628 #ifdef __cplusplus
629 }
630 #endif
631 
632 #endif /* NET_GNRC_RPL_H */
633 
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.
RPL Objective functions manager header.
DIO Base Object.
Definition: structs.h:88
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.
void gnrc_rpl_send_DIS(gnrc_rpl_instance_t *instance, ipv6_addr_t *destination)
Send a DIS of the instace to the destination.
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition: structs.h:218
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:137
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:621
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:126
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.
const ipv6_addr_t ipv6_addr_all_rpl_nodes
Destination Advertisement Object Acknowledgement.
Definition: structs.h:150
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:208
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.