Contiki-NG
rpl-neighbor.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  * Header file for rpl-neighbor module
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_NEIGHBOR_H
46 #define RPL_NEIGHBOR_H
47 
48 /********** Includes **********/
49 
50 #include "net/routing/rpl-lite/rpl.h"
51 #include "lib/list.h"
52 #include "net/ipv6/uip.h"
53 #include "net/ipv6/uip-ds6.h"
54 #include "sys/ctimer.h"
55 
56 /********** Public symbols **********/
57 
58 /* Per-neighbor RPL information. According to RFC 6550, there exist three
59  * types of neighbors:
60  * - Candidate neighbor set: any neighbor, selected in an implementation
61  * and OF-specific way. The nodes in rpl_neighbors constitute the candidate neighbor set.
62  * - Parent set: the subset of the candidate neighbor set with rank below our rank
63  * - Preferred parent: one node of the parent set
64  */
65 NBR_TABLE_DECLARE(rpl_neighbors);
66 
67 /********** Public functions **********/
68 
69 /**
70  * Initialize rpl-dag-neighbor module
71 */
72 void rpl_neighbor_init(void);
73 
74 /**
75  * Tells whether a neighbor is in the parent set.
76  *
77  * \param nbr The neighbor to be tested
78  * \return 1 if nbr is in the parent set, 0 otherwise
79  */
81 
82 /**
83  * Set current RPL preferred parent and update DS6 default route accordingly
84  *
85  * \param nbr The new preferred parent
86 */
88 
89 /**
90  * Tells wether we have fresh link information towards a given neighbor
91  *
92  * \param nbr The neighbor
93  * \return 1 if we have fresh link information, 0 otherwise
94 */
96 
97 /**
98  * Tells wether we a given neighbor is reachable
99  *
100  * \param nbr The neighbor
101  * \return 1 if the parent is reachable, 0 otherwise
102 */
104 
105 /**
106  * Tells whether a nbr is acceptable as per the OF's definition
107  *
108  * \param nbr The neighbor
109  * \return 1 if acceptable, 0 otherwise
110 */
112 
113 /**
114  * Returns a neighbor's link metric
115  *
116  * \param nbr The neighbor
117  * \return The link metric if any, 0xffff otherwise
118 */
120 
121 /**
122  * Returns our rank if selecting a given parent as preferred parent
123  *
124  * \param nbr The neighbor
125  * \return The resulting rank if any, RPL_INFINITE_RANK otherwise
126 */
128 
129 /**
130  * Returns a neighbors's link-layer address
131  *
132  * \param nbr The neighbor
133  * \return The link-layer address if any, NULL otherwise
134 */
135 const linkaddr_t *rpl_neighbor_get_lladdr(rpl_nbr_t *nbr);
136 
137 /**
138  * Returns a neighbor's link statistics
139  *
140  * \param nbr The neighbor
141  * \return The link_stats structure address if any, NULL otherwise
142 */
143 const struct link_stats *rpl_neighbor_get_link_stats(rpl_nbr_t *nbr);
144 
145 /**
146  * Returns a neighbor's (link-local) IPv6 address
147  *
148  * \param nbr The neighbor
149  * \return The link-local IPv6 address if any, NULL otherwise
150 */
151 uip_ipaddr_t *rpl_neighbor_get_ipaddr(rpl_nbr_t *nbr);
152 
153 /**
154  * Returns a neighbor from its link-layer address
155  *
156  * \param addr The link-layer address
157  * \return The neighbor if found, NULL otherwise
158 */
160 
161 /**
162  * Returns a neighbor from its link-local IPv6 address
163  *
164  * \param addr The link-local IPv6 address
165  * \return The neighbor if found, NULL otherwise
166 */
168 
169 /**
170  * Returns the number of nodes in the RPL neighbor table
171  *
172  * \return the neighbor count
173 */
174 int rpl_neighbor_count(void);
175 
176 /**
177  * Prints a summary of all RPL neighbors and their properties
178  *
179  * \param str A descriptive text on the caller
180 */
181 void rpl_neighbor_print_list(const char *str);
182 
183 /**
184  * Empty the RPL neighbor table
185 */
186 void rpl_neighbor_remove_all(void);
187 
188 /**
189  * Returns the best candidate for preferred parent
190  *
191  * \return The best candidate, NULL if no usable parent is found
192 */
194 
195 /**
196 * Print a textual description of RPL neighbor into a string
197 *
198 * \param buf The buffer where to write content
199 * \param buflen The buffer len
200 * \param nbr A pointer to a RPL neighbor that will be written to the buffer
201 * \return Identical to snprintf: number of bytes written excluding ending null
202 * byte. A value >= buflen if the buffer was too small.
203 */
204 int rpl_neighbor_snprint(char *buf, int buflen, rpl_nbr_t *nbr);
205 
206 typedef rpl_nbr_t rpl_parent_t;
207 #define rpl_parent_get_from_ipaddr(addr) rpl_neighbor_get_from_ipaddr(addr)
208 #define rpl_parent_get_ipaddr(nbr) rpl_neighbor_get_ipaddr(nbr)
209  /** @} */
210 
211 #endif /* RPL_NEIGHBOR_H */
const linkaddr_t * rpl_neighbor_get_lladdr(rpl_nbr_t *nbr)
Returns a neighbors&#39;s link-layer address.
Definition: rpl-neighbor.c:246
uip_ipaddr_t * rpl_neighbor_get_ipaddr(rpl_nbr_t *nbr)
Returns a neighbor&#39;s (link-local) IPv6 address.
Definition: rpl-neighbor.c:252
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
Definition: uip-nd6.c:106
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107
void rpl_neighbor_remove_all(void)
Empty the RPL neighbor table.
Definition: rpl-neighbor.c:326
rpl_nbr_t * rpl_neighbor_get_from_ipaddr(uip_ipaddr_t *addr)
Returns a neighbor from its link-local IPv6 address.
Definition: rpl-neighbor.c:349
int rpl_neighbor_is_fresh(rpl_nbr_t *nbr)
Tells wether we have fresh link information towards a given neighbor.
Definition: rpl-neighbor.c:266
uint16_t rpl_neighbor_get_link_metric(rpl_nbr_t *nbr)
Returns a neighbor&#39;s link metric.
Definition: rpl-neighbor.c:228
int rpl_neighbor_is_parent(rpl_nbr_t *nbr)
Tells whether a neighbor is in the parent set.
Definition: rpl-neighbor.c:290
int rpl_neighbor_count(void)
Returns the number of nodes in the RPL neighbor table.
Definition: rpl-neighbor.c:168
Header file for IPv6-related data structures.
void rpl_neighbor_init(void)
Initialize rpl-dag-neighbor module.
Definition: rpl-neighbor.c:462
Header file for the callback timer
Linked list manipulation routines.
const struct link_stats * rpl_neighbor_get_link_stats(rpl_nbr_t *nbr)
Returns a neighbor&#39;s link statistics.
Definition: rpl-neighbor.c:259
All information related to a RPL neighbor.
Definition: rpl-types.h:136
void rpl_neighbor_print_list(const char *str)
Prints a summary of all RPL neighbors and their properties.
Definition: rpl-neighbor.c:143
Header file for the uIP TCP/IP stack.
int rpl_neighbor_is_acceptable_parent(rpl_nbr_t *nbr)
Tells whether a nbr is acceptable as per the OF&#39;s definition.
Definition: rpl-neighbor.c:219
rpl_rank_t rpl_neighbor_rank_via_nbr(rpl_nbr_t *nbr)
Returns our rank if selecting a given parent as preferred parent.
Definition: rpl-neighbor.c:237
void rpl_neighbor_set_preferred_parent(rpl_nbr_t *nbr)
Set current RPL preferred parent and update DS6 default route accordingly.
Definition: rpl-neighbor.c:296
rpl_nbr_t * rpl_neighbor_select_best(void)
Returns the best candidate for preferred parent.
Definition: rpl-neighbor.c:398
int rpl_neighbor_snprint(char *buf, int buflen, rpl_nbr_t *nbr)
Print a textual description of RPL neighbor into a string.
Definition: rpl-neighbor.c:90
rpl_nbr_t * rpl_neighbor_get_from_lladdr(uip_lladdr_t *addr)
Returns a neighbor from its link-layer address.
Definition: rpl-neighbor.c:213
int rpl_neighbor_is_reachable(rpl_nbr_t *nbr)
Tells wether we a given neighbor is reachable.
Definition: rpl-neighbor.c:273