Contiki-NG
rpl-types.h
Go to the documentation of this file.
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 * This file is part of the Contiki operating system.
30 *
31 */
32
33 /**
34 * \addtogroup rpl-lite
35 * @{
36 *
37 * \file
38 * RPL types and macros
39 * \author
40 * Joakim Eriksson <joakime@sics.se> & Nicolas Tsiftes <nvt@sics.se>
41 * Simon Duquennoy <simon.duquennoy@inria.fr>
42 *
43 */
44
45#ifndef RPL_TYPES_H
46#define RPL_TYPES_H
47
48 /********** Macros **********/
49
50/* Multicast address: create and compare */
51
52/** \brief Set IP address addr to the link-local, all-rpl-nodes
53 multicast address. */
54#define uip_create_linklocal_rplnodes_mcast(addr) \
55 uip_ip6addr((addr), 0xff02, 0, 0, 0, 0, 0, 0, 0x001a)
56
57/** \brief Is IPv6 address addr the link-local, all-RPL-nodes
58 multicast address? */
59#define uip_is_addr_linklocal_rplnodes_mcast(addr) \
60 ((addr)->u8[0] == 0xff) && \
61 ((addr)->u8[1] == 0x02) && \
62 ((addr)->u16[1] == 0) && \
63 ((addr)->u16[2] == 0) && \
64 ((addr)->u16[3] == 0) && \
65 ((addr)->u16[4] == 0) && \
66 ((addr)->u16[5] == 0) && \
67 ((addr)->u16[6] == 0) && \
68 ((addr)->u8[14] == 0) && \
69 ((addr)->u8[15] == 0x1a))
70
71/** \brief Compute lifetime, accounting for the lifetime unit */
72#define RPL_LIFETIME(lifetime) \
73 (((lifetime) == RPL_INFINITE_LIFETIME) ? \
74 RPL_ROUTE_INFINITE_LIFETIME : \
75 (unsigned long)curr_instance.lifetime_unit * (lifetime))
76
77/** \brief Rank of a root node. */
78#define ROOT_RANK curr_instance.min_hoprankinc
79
80/** \brief Return DAG RANK as per RFC 6550 (rank divided by min_hoprankinc) */
81#define DAG_RANK(fixpt_rank) ((fixpt_rank) / curr_instance.min_hoprankinc)
82
83#define RPL_LOLLIPOP_MAX_VALUE 255
84#define RPL_LOLLIPOP_CIRCULAR_REGION 127
85#define RPL_LOLLIPOP_SEQUENCE_WINDOWS 16
86#define RPL_LOLLIPOP_INIT (RPL_LOLLIPOP_MAX_VALUE - RPL_LOLLIPOP_SEQUENCE_WINDOWS + 1)
87#define RPL_LOLLIPOP_INCREMENT(counter) \
88 do { \
89 if((counter) > RPL_LOLLIPOP_CIRCULAR_REGION) { \
90 (counter) = ((counter) + 1) & RPL_LOLLIPOP_MAX_VALUE; \
91 } else { \
92 (counter) = ((counter) + 1) & RPL_LOLLIPOP_CIRCULAR_REGION; \
93 } \
94 } while(0)
95
96#define RPL_LOLLIPOP_IS_INIT(counter) \
97 ((counter) > RPL_LOLLIPOP_CIRCULAR_REGION)
98
99
100/********** Data structures and types **********/
101
102typedef uint16_t rpl_rank_t;
103typedef uint16_t rpl_ocp_t;
104
105/*---------------------------------------------------------------------------*/
106/** \brief Structure for RPL energy metric. */
108 uint8_t flags;
109 uint8_t energy_est;
110};
111
112/** \brief Logical representation of a DAG Metric Container. */
114 uint8_t type;
115 uint8_t flags;
116 uint8_t aggr;
117 uint8_t prec;
118 uint8_t length;
119 union metric_object {
120 struct rpl_metric_object_energy energy;
121 uint16_t etx;
122 } obj;
123};
125
126/** \brief RPL prefix information */
127struct rpl_prefix {
128 uip_ipaddr_t prefix;
129 uint32_t lifetime;
130 uint8_t length;
131 uint8_t flags;
132 };
133typedef struct rpl_prefix rpl_prefix_t;
134
135/** \brief All information related to a RPL neighbor */
136struct rpl_nbr {
137 clock_time_t better_parent_since; /* The neighbor has been a possible
138 replacement for our preferred parent consistently since 'parent_since'.
139 Currently used by MRHOF only. */
140#if RPL_WITH_MC
142#endif /* RPL_WITH_MC */
143 rpl_rank_t rank;
144 uint8_t dtsn;
145};
146typedef struct rpl_nbr rpl_nbr_t;
147
148/*---------------------------------------------------------------------------*/
149 /**
150 * \brief API for RPL objective functions (OF)
151 *
152 * - reset(dag) Resets the objective function state for a specific DAG. This function is
153 * called when doing a global repair on the DAG.
154 * - nbr_link_metric(n) Returns the link metric of a neighbor
155 * - nbr_has_usable_link(n) Returns 1 iff the neighbor has a usable link as defined by the OF
156 * - nbr_is_acceptable_parent(n) Returns 1 iff the neighbor has a usable rank/link as defined by the OF
157 * - nbr_path_cost(n) Returns the path cost of a neighbor
158 * - rank_via_nbr(n) Returns our rank if we select a given neighbor as preferred parent
159 * - best_parent(n1, n2) Compares two neighbors and returns the best one, according to the OF.
160 * - update_metric_container() Updated the DAG metric container from the current OF state
161 */
162 struct rpl_of {
163 void (*reset)(void);
164 uint16_t (*nbr_link_metric)(rpl_nbr_t *);
165 int (*nbr_has_usable_link)(rpl_nbr_t *);
166 int (*nbr_is_acceptable_parent)(rpl_nbr_t *);
167 uint16_t (*nbr_path_cost)(rpl_nbr_t *);
168 rpl_rank_t (*rank_via_nbr)(rpl_nbr_t *);
169 rpl_nbr_t *(*best_parent)(rpl_nbr_t *, rpl_nbr_t *);
170 void (*update_metric_container)(void);
171 rpl_ocp_t ocp;
172 };
173 typedef struct rpl_of rpl_of_t;
174
175/*---------------------------------------------------------------------------*/
176/** \brief RPL DAG states*/
178 DAG_INITIALIZED,
179 DAG_JOINED,
180 DAG_REACHABLE,
181 DAG_POISONING
182};
183
184/** \brief RPL DAG structure */
185struct rpl_dag {
186 uip_ipaddr_t dag_id;
187 rpl_prefix_t prefix_info;
188 rpl_nbr_t *preferred_parent;
189 rpl_rank_t lowest_rank; /* The lowest rank seen in the current version */
190 rpl_rank_t rank; /* The current rank */
191 rpl_rank_t last_advertised_rank; /* The last rank advertised in a multicast-DIO */
192 uint32_t lifetime;
193 uint8_t version;
194 uint8_t grounded;
195 uint8_t preference;
196 uint8_t dio_intcurrent; /* Current DIO interval */
197 uint8_t dio_send; /* internal trickle timer state: do we need to send a DIO at the next wakeup? */
198 uint8_t dio_counter; /* internal trickle timer state: redundancy counter */
199 uint8_t dao_last_seqno; /* the node's last sent DAO seqno */
200 uint8_t dao_last_acked_seqno; /* the last seqno we got an ACK for */
201 uint8_t dao_transmissions; /* the number of transmissions for the current DAO */
202 bool unprocessed_parent_switch;
203 enum rpl_dag_state state;
204
205 /* Timers */
206 clock_time_t dio_next_delay; /* delay for completion of dio interval */
207 struct ctimer state_update;
208 struct ctimer leave;
209 struct ctimer dio_timer;
210 struct ctimer unicast_dio_timer;
211 struct ctimer dao_timer;
212 rpl_nbr_t *unicast_dio_target;
213#if RPL_WITH_PROBING
214 struct ctimer probing_timer;
215 rpl_nbr_t *urgent_probing_target;
216#endif /* RPL_WITH_PROBING */
217#if RPL_WITH_DAO_ACK
218 uip_ipaddr_t dao_ack_target;
219 uint16_t dao_ack_sequence;
220 struct ctimer dao_ack_timer;
221#endif /* RPL_WITH_DAO_ACK */
222};
223typedef struct rpl_dag rpl_dag_t;
224
225/*---------------------------------------------------------------------------*/
226/** \brief RPL instance structure */
227struct rpl_instance {
228 rpl_metric_container_t mc; /* Metric container. Set to MC_NONE when no mc is used */
229 rpl_of_t *of; /* The objective function */
230 uint8_t used;
231 uint8_t instance_id;
232 uint8_t mop; /* Mode of operation */
233 uint8_t dtsn_out;
234 uint8_t dio_intdoubl;
235 uint8_t dio_intmin;
236 uint8_t dio_redundancy;
237 rpl_rank_t max_rankinc;
238 rpl_rank_t min_hoprankinc;
239 uint8_t default_lifetime;
240 uint16_t lifetime_unit; /* lifetime in seconds = lifetime_unit * default_lifetime */
241 rpl_dag_t dag; /* We support only one dag */
242};
243typedef struct rpl_instance rpl_instance_t;
244
245 /** @} */
246
247#endif /* RPL_TYPES_H */
rpl_dag_state
RPL DAG states.
Definition: rpl-types.h:177
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
All information related to a RPL neighbor.
Definition: rpl-types.h:136
API for RPL objective functions (OF)
Definition: rpl.h:204
RPL prefix information.
Definition: rpl.h:128