Contiki-NG
Loading...
Searching...
No Matches
rpl.h
1/*
2 * Copyright (c) 2010, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/*
31 * \file
32 * Public API declarations for ContikiRPL.
33 * \author
34 * Joakim Eriksson <joakime@sics.se> & Nicolas Tsiftes <nvt@sics.se>
35 */
36
37#ifndef RPL_H
38#define RPL_H
39
40#include "net/routing/rpl-classic/rpl-conf.h"
41
42#include "lib/list.h"
43#include "net/ipv6/uip.h"
44#include "net/ipv6/uip-ds6.h"
45#include "sys/ctimer.h"
46
47/*---------------------------------------------------------------------------*/
48typedef uint16_t rpl_rank_t;
49typedef uint16_t rpl_ocp_t;
50/*---------------------------------------------------------------------------*/
51/* IANA Routing Metric/Constraint Type as defined in RFC6551. */
52#define RPL_DAG_MC_NONE 0 /* Local identifier for empty MC */
53#define RPL_DAG_MC_NSA 1 /* Node State and Attributes */
54#define RPL_DAG_MC_ENERGY 2 /* Node Energy */
55#define RPL_DAG_MC_HOPCOUNT 3 /* Hop Count */
56#define RPL_DAG_MC_THROUGHPUT 4 /* Throughput */
57#define RPL_DAG_MC_LATENCY 5 /* Latency */
58#define RPL_DAG_MC_LQL 6 /* Link Quality Level */
59#define RPL_DAG_MC_ETX 7 /* Expected Transmission Count */
60#define RPL_DAG_MC_LC 8 /* Link Color */
61
62/* IANA Routing Metric/Constraint Common Header Flag field as defined
63 in RFC6551. (bit indexes) */
64#define RPL_DAG_MC_FLAG_P 5
65#define RPL_DAG_MC_FLAG_C 6
66#define RPL_DAG_MC_FLAG_O 7
67#define RPL_DAG_MC_FLAG_R 8
68
69/* IANA Routing Metric/Constraint Common Header A Field as defined in
70 RFC6551. */
71#define RPL_DAG_MC_AGGR_ADDITIVE 0
72#define RPL_DAG_MC_AGGR_MAXIMUM 1
73#define RPL_DAG_MC_AGGR_MINIMUM 2
74#define RPL_DAG_MC_AGGR_MULTIPLICATIVE 3
75
76/* The bit index within the flags field of the
77 rpl_metric_object_energy structure. */
78#define RPL_DAG_MC_ENERGY_INCLUDED 3
79#define RPL_DAG_MC_ENERGY_TYPE 1
80#define RPL_DAG_MC_ENERGY_ESTIMATION 0
81
82/* IANA Node Type Field as defined in RFC6551. */
83#define RPL_DAG_MC_ENERGY_TYPE_MAINS 0
84#define RPL_DAG_MC_ENERGY_TYPE_BATTERY 1
85#define RPL_DAG_MC_ENERGY_TYPE_SCAVENGING 2
86
87/* IANA Objective Code Point as defined in RFC6550. */
88#define RPL_OCP_OF0 0
89#define RPL_OCP_MRHOF 1
90
92 uint8_t flags;
93 uint8_t energy_est;
94};
95
96/* Logical representation of a DAG Metric Container. */
98 uint8_t type;
99 uint8_t flags;
100 uint8_t aggr;
101 uint8_t prec;
102 uint8_t length;
103 union metric_object {
104 struct rpl_metric_object_energy energy;
105 uint16_t etx;
106 } obj;
107};
109/*---------------------------------------------------------------------------*/
110struct rpl_instance;
111struct rpl_dag;
112/*---------------------------------------------------------------------------*/
113#define RPL_PARENT_FLAG_UPDATED 0x1
114#define RPL_PARENT_FLAG_LINK_METRIC_VALID 0x2
115
116struct rpl_parent {
117 struct rpl_dag *dag;
118#if RPL_WITH_MC
120#endif /* RPL_WITH_MC */
121 rpl_rank_t rank;
122 uint8_t dtsn;
123 uint8_t flags;
124};
125typedef struct rpl_parent rpl_parent_t;
126/*---------------------------------------------------------------------------*/
127/* RPL DIO prefix suboption. */
129 uip_ipaddr_t prefix;
130 uint32_t lifetime;
131 uint8_t length;
132 uint8_t flags;
133};
134typedef struct rpl_prefix rpl_prefix_t;
135/*---------------------------------------------------------------------------*/
136/* Destination-Oriented Directed Acyclic Graph (DODAG). This name is
137 typically shortened to "DAG" within the ContikiRPL implementation. */
138struct rpl_dag {
139 uip_ipaddr_t dag_id;
140 rpl_rank_t min_rank; /* should be reset per DAG iteration! */
141 uint8_t version;
142 uint8_t grounded;
143 uint8_t preference;
144 uint8_t used;
145 /* live data for the DAG */
146 uint8_t joined;
147 rpl_parent_t *preferred_parent;
148 rpl_rank_t rank;
149 struct rpl_instance *instance;
150 rpl_prefix_t prefix_info;
151 uint32_t lifetime;
152};
153typedef struct rpl_dag rpl_dag_t;
154typedef struct rpl_instance rpl_instance_t;
155/*---------------------------------------------------------------------------*/
156/*
157 * API for RPL objective functions (OF)
158 *
159 * reset(dag)
160 *
161 * Resets the objective function state for a specific DAG. This function is
162 * called when doing a global repair on the DAG.
163 *
164 * parent_link_metric(parent)
165 *
166 * Returns the link metric of a parent.
167 *
168 * parent_has_usable_link(parent)
169 *
170 * Returns 1 iff we have a usable link to this parent.
171 *
172 * parent_path_cost(parent)
173 *
174 * Returns the path cost of a parent.
175 *
176 * rank_via_parent(parent)
177 *
178 * Returns our rank if we select a given parent as preferred parent.
179 *
180 * parent_is_acceptable
181 *
182 * Returns 1 if a parent is usable as preferred parent, 0 otherwise.
183 *
184 * best_parent(parent1, parent2)
185 *
186 * Compares two parents and returns the best one, according to the OF.
187 *
188 * best_dag(dag1, dag2)
189 *
190 * Compares two DAGs and returns the best one, according to the OF.
191 *
192 * update_metric_container(dag)
193 *
194 * Updates the metric container for outgoing DIOs in a certain DAG.
195 * If the objective function of the DAG does not use metric containers,
196 * the function should set the object type to RPL_DAG_MC_NONE.
197 *
198 * dao_ack_callback(parent, status)
199 *
200 * A callback on the result of the DAO ACK. Similar to the neighbor link
201 * callback. A failed DAO_ACK (NACK) can be used for switching to another
202 * parent via changed link metric or other mechanisms.
203 */
204struct rpl_of {
205 void (*reset)(struct rpl_dag *);
206#if RPL_WITH_DAO_ACK
207 void (*dao_ack_callback)(rpl_parent_t *, int status);
208#endif
209 uint16_t (*parent_link_metric)(rpl_parent_t *);
210 int (*parent_has_usable_link)(rpl_parent_t *);
211 uint16_t (*parent_path_cost)(rpl_parent_t *);
212 rpl_rank_t (*rank_via_parent)(rpl_parent_t *);
213 rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *);
214 rpl_dag_t *(*best_dag)(rpl_dag_t *, rpl_dag_t *);
215 void (*update_metric_container)( rpl_instance_t *);
216 rpl_ocp_t ocp;
217};
218typedef struct rpl_of rpl_of_t;
219
220/*---------------------------------------------------------------------------*/
221/* RPL Instance. */
223 /* DAG configuration. */
224 rpl_metric_container_t mc;
225 rpl_of_t *of;
226 rpl_dag_t *current_dag;
227 rpl_dag_t dag_table[RPL_MAX_DAG_PER_INSTANCE];
228 /* The current default router -- used for routing "upwards". */
229 uip_ds6_defrt_t *def_route;
230 uint8_t instance_id;
231 uint8_t used;
232 uint8_t dtsn_out;
233 uint8_t mop;
234 uint8_t dio_intdoubl;
235 uint8_t dio_intmin;
236 uint8_t dio_redundancy;
237 uint8_t default_lifetime;
238 uint8_t dio_intcurrent;
239 uint8_t dio_send; /* For keeping track of which mode the timer is in. */
240 uint8_t dio_counter;
241 /* My last registered DAO that I might be waiting for an ACK on. */
242 uint8_t my_dao_seqno;
243 uint8_t my_dao_transmissions;
244 /* this is intended to keep track if this instance have a route downward */
245 uint8_t has_downward_route;
246 rpl_rank_t max_rankinc;
247 rpl_rank_t min_hoprankinc;
248 uint16_t lifetime_unit; /* Lifetime in seconds = l_u * d_l. */
249#if RPL_CONF_STATS
250 uint16_t dio_totint;
251 uint16_t dio_totsend;
252 uint16_t dio_totrecv;
253#endif /* RPL_CONF_STATS */
254 clock_time_t dio_next_delay; /* Delay for completion of the DIO interval. */
255#if RPL_WITH_PROBING
256 struct ctimer probing_timer;
257 rpl_parent_t *urgent_probing_target;
258 int last_dag;
259#endif /* RPL_WITH_PROBING */
260 struct ctimer dio_timer;
261 struct ctimer dao_timer;
262 struct ctimer dao_lifetime_timer;
263 struct ctimer unicast_dio_timer;
264 rpl_parent_t *unicast_dio_target;
265#if RPL_WITH_DAO_ACK
266 struct ctimer dao_retransmit_timer;
267#endif /* RPL_WITH_DAO_ACK */
268};
269
270/*---------------------------------------------------------------------------*/
271/* Public RPL functions. */
272void uip_rpl_input(void);
273rpl_dag_t *rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id);
274int rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len);
275int rpl_repair_root(uint8_t instance_id);
276int rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from);
277rpl_dag_t *rpl_get_dag(const uip_ipaddr_t *addr);
279rpl_instance_t *rpl_get_instance(uint8_t instance_id);
280int rpl_ext_header_update(void);
281int rpl_ext_header_hbh_update(uint8_t *, int);
282void rpl_insert_header(void);
283bool rpl_ext_header_remove(void);
284const struct link_stats *rpl_get_parent_link_stats(rpl_parent_t *p);
285int rpl_parent_is_fresh(rpl_parent_t *p);
286int rpl_parent_is_reachable(rpl_parent_t *p);
287uint16_t rpl_get_parent_link_metric(rpl_parent_t *p);
288rpl_rank_t rpl_rank_via_parent(rpl_parent_t *p);
289const linkaddr_t *rpl_get_parent_lladdr(rpl_parent_t *p);
290uip_ipaddr_t *rpl_parent_get_ipaddr(rpl_parent_t *nbr);
291rpl_parent_t *rpl_get_parent(const uip_lladdr_t *addr);
292rpl_rank_t rpl_get_parent_rank(uip_lladdr_t *addr);
293void rpl_dag_init(void);
294uip_ds6_nbr_t *rpl_get_nbr(rpl_parent_t *parent);
295void rpl_print_neighbor_list(void);
297int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr);
298void rpl_link_callback(const linkaddr_t *addr, int status, int numtx);
299/* Per-parent RPL information */
300NBR_TABLE_DECLARE(rpl_parents);
301
302/**
303 * RPL modes
304 *
305 * The RPL module can be in either of three modes: mesh mode
306 * (RPL_MODE_MESH), feater mode (RPL_MODE_FEATHER), and leaf mode
307 * (RPL_MODE_LEAF). In mesh mode, nodes forward data for other nodes,
308 * and are reachable by others. In feather mode, nodes can forward
309 * data for other nodes, but are not reachable themselves. In leaf
310 * mode, nodes do not forward data for others, but are reachable by
311 * others. */
312enum rpl_mode {
313 RPL_MODE_MESH = 0,
314 RPL_MODE_FEATHER = 1,
315 RPL_MODE_LEAF = 2,
316};
317
318/**
319 * Set the RPL mode.
320 *
321 * \param mode The new RPL mode.
322 * \retval The previous RPL mode.
323 */
324enum rpl_mode rpl_set_mode(enum rpl_mode mode);
325
326/**
327 * Get the RPL mode.
328 *
329 * \retval The RPL mode.
330 */
331enum rpl_mode rpl_get_mode(void);
332
333/**
334 * Tells whether the node has joined a network or not.
335 *
336 * \retval 1 if we have joined a network, 0 if not.
337 */
338int rpl_has_joined(void);
339
340/**
341 * Get the RPL's best guess on if we have downward route or not.
342 *
343 * \retval 1 if we have a downward route from RPL Root, 0 if not.
344 */
345int rpl_has_downward_route(void);
346
347/**
348 * Tells whether the protocol is in leaf mode.
349 *
350 * \retval 1 if the protocol is in leaf mode, 0 if not.
351 */
352uint8_t rpl_is_in_leaf_mode(void);
353
354/*---------------------------------------------------------------------------*/
355#endif /* RPL_H */
Header file for the callback timer.
int rpl_has_downward_route(void)
Get the RPL's best guess on if we have downward route or not.
Definition rpl-dag.c:1058
enum rpl_mode rpl_set_mode(enum rpl_mode mode)
Set the RPL mode.
Definition rpl.c:74
int rpl_has_joined(void)
Tells whether the node has joined a network or not.
Definition rpl-dag.c:1049
rpl_dag_t * rpl_get_any_dag(void)
Returns pointer to any DAG (for compatibility with legagy RPL code)
Definition rpl-dag.c:1090
int rpl_ext_header_update(void)
Adds/updates all RPL extension headers to current uIP packet.
void rpl_dag_init(void)
Initializes rpl-dag module.
Definition rpl-dag.c:140
uint8_t rpl_is_in_leaf_mode(void)
Tells whether the protocol is in leaf mode.
Definition rpl.c:436
int rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
Look for next hop from SRH of current uIP packet.
enum rpl_mode rpl_get_mode(void)
Get the RPL mode.
Definition rpl.c:68
int rpl_ext_header_srh_update(void)
Process and update SRH in-place, i.e.
bool rpl_ext_header_remove(void)
Removes all RPL extension headers.
int rpl_ext_header_hbh_update(uint8_t *, int)
Process and update the RPL hop-by-hop extension headers of the current uIP packet.
void rpl_link_callback(const linkaddr_t *addr, int status, int numtx)
Called by lower layers after every packet transmission.
Definition rpl.c:265
Linked list manipulation routines.
RPL DAG structure.
Definition rpl.h:138
RPL instance structure.
Definition rpl.h:222
Logical representation of a DAG Metric Container.
Definition rpl.h:97
Structure for RPL energy metric.
Definition rpl.h:91
API for RPL objective functions (OF)
Definition rpl.h:204
RPL prefix information.
Definition rpl.h:128
An entry in the default router list.
The default nbr_table entry (when UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr cach...
Header file for IPv6-related data structures.
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
Definition uip-nd6.c:106
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition uip-nd6.c:116
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition uip-nd6.c:107
Header file for the uIP TCP/IP stack.