Contiki-NG
uip-sr.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Inria.
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  * \addtogroup uip
34  * @{
35  *
36  * \file
37  * Source routing support
38  *
39  * \author Simon Duquennoy <simon.duquennoy@inria.fr>
40  */
41 
42 
43 #ifndef UIP_SR_H
44 #define UIP_SR_H
45 
46 /********** Includes **********/
47 
48 #include "contiki.h"
49 #include "net/ipv6/uip.h"
50 
51 /********** Configuration **********/
52 
53 /* The number of source routing nodes, i.e. the maximum netwrok size at the root */
54 #ifdef UIP_SR_CONF_LINK_NUM
55 
56 #define UIP_SR_LINK_NUM UIP_SR_CONF_LINK_NUM
57 
58 #else /* UIP_SR_CONF_LINK_NUM */
59 
60 #if ROUTING_CONF_RPL_LITE
61 #define UIP_SR_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES
62 #elif ROUTING_CONF_RPL_CLASSIC
63 
64 #include "net/routing/rpl-classic/rpl-conf.h"
65 #if RPL_WITH_NON_STORING
66 #define UIP_SR_LINK_NUM NETSTACK_MAX_ROUTE_ENTRIES
67 #else /* RPL_WITH_NON_STORING */
68 #define UIP_SR_LINK_NUM 0
69 #endif /* RPL_WITH_NON_STORING */
70 
71 #else
72 
73 #define UIP_SR_LINK_NUM 0
74 
75 #endif
76 
77 #endif /* UIP_SR_CONF_LINK_NUM */
78 
79 /* Delay between between expiration order and actual node removal */
80 #ifdef UIP_SR_CONF_REMOVAL_DELAY
81 #define UIP_SR_REMOVAL_DELAY UIP_SR_CONF_REMOVAL_DELAY
82 #else /* UIP_SR_CONF_REMOVAL_DELAY */
83 #define UIP_SR_REMOVAL_DELAY 60
84 #endif /* UIP_SR_CONF_REMOVAL_DELAY */
85 
86 #define UIP_SR_INFINITE_LIFETIME 0xFFFFFFFF
87 
88 /********** Data Structures **********/
89 
90 /** \brief A node in a source routing graph, stored at the root and representing
91  * all child-parent relationship. Used to build source routes */
92 typedef struct uip_sr_node {
93  struct uip_sr_node *next;
94  uint32_t lifetime;
95  /* Protocol-specific graph structure */
96  void *graph;
97  /* Store only IPv6 link identifiers, the routing protocol will provide
98  us with the prefix */
99  unsigned char link_identifier[8];
100  struct uip_sr_node *parent;
101 } uip_sr_node_t;
102 
103 /********** Public functions **********/
104 
105 /**
106  * Tells how many nodes are currently stored in the graph
107  *
108  * \return The number of nodes
109 */
110 int uip_sr_num_nodes(void);
111 
112 /**
113  * Expires a given child-parent link
114  *
115  * \param graph The graph the link belongs to
116  * \param child The IPv6 address of the child
117  * \param parent The IPv6 address of the parent
118 */
119 void uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent);
120 
121 /**
122  * Updates a child-parent link
123  *
124  * \param graph The graph the link belongs to
125  * \param child The IPv6 address of the child
126  * \param parent The IPv6 address of the parent
127  * \param lifetime The link lifetime in seconds
128 */
129 uip_sr_node_t *uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime);
130 
131 /**
132  * Returns the head of the non-storing node list
133  *
134  * \return The head of the list
135 */
137 
138 /**
139  * Returns the next element of the non-storing node list
140  *
141  * \param item The current element in the list
142  * \return The next element of the list
143 */
145 
146 /**
147  * Looks up for a source routing node from its IPv6 global address
148  *
149  * \param graph The graph where to look up for the node
150  * \param addr The target address
151  * \return A pointer to the node
152 */
153 uip_sr_node_t *uip_sr_get_node(void *graph, const uip_ipaddr_t *addr);
154 
155 /**
156  * Telle whether an address is reachable, i.e. if there exists a path from
157  * the root to the node in the current source routing graph
158  *
159  * \param graph The graph where to look up for the node
160  * \param addr The target IPv6 global address
161  * \return 1 if the node is reachable, 0 otherwise
162 */
163 int uip_sr_is_addr_reachable(void *graph, const uip_ipaddr_t *addr);
164 
165 /**
166  * A function called periodically. Used to age the links (decrease lifetime
167  * and expire links accordingly)
168  *
169  * \param seconds The number of seconds elapsted since last call
170 */
171 void uip_sr_periodic(unsigned seconds);
172 
173 /**
174  * Initialize this module
175 */
176 void uip_sr_init(void);
177 
178 /**
179  * Deallocate all neighbors
180 */
181 void uip_sr_free_all(void);
182 
183 /**
184 * Print a textual description of a source routing link
185 *
186 * \param buf The buffer where to write content
187 * \param buflen The buffer len
188 * \param link A pointer to the source routing link
189 * \return Identical to snprintf: number of bytes written excluding ending null
190 * byte. A value >= buflen if the buffer was too small.
191 */
192 int uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link);
193 
194  /** @} */
195 
196 #endif /* UIP_SR_H */
int uip_sr_num_nodes(void)
Tells how many nodes are currently stored in the graph.
Definition: uip-sr.c:63
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107
void uip_sr_free_all(void)
Deallocate all neighbors.
Definition: uip-sr.c:239
void uip_sr_init(void)
Initialize this module.
Definition: uip-sr.c:186
void uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
Expires a given child-parent link.
Definition: uip-sr.c:113
uip_sr_node_t * uip_sr_node_next(uip_sr_node_t *item)
Returns the next element of the non-storing node list.
Definition: uip-sr.c:200
void uip_sr_periodic(unsigned seconds)
A function called periodically.
Definition: uip-sr.c:206
uip_sr_node_t * uip_sr_node_head(void)
Returns the head of the non-storing node list.
Definition: uip-sr.c:194
uip_sr_node_t * uip_sr_get_node(void *graph, const uip_ipaddr_t *addr)
Looks up for a source routing node from its IPv6 global address.
Definition: uip-sr.c:81
int uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link)
Print a textual description of a source routing link.
Definition: uip-sr.c:252
Header file for the uIP TCP/IP stack.
uip_sr_node_t * uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime)
Updates a child-parent link.
Definition: uip-sr.c:123
int uip_sr_is_addr_reachable(void *graph, const uip_ipaddr_t *addr)
Telle whether an address is reachable, i.e.
Definition: uip-sr.c:94
A node in a source routing graph, stored at the root and representing all child-parent relationship...
Definition: uip-sr.h:92
struct uip_sr_node uip_sr_node_t
A node in a source routing graph, stored at the root and representing all child-parent relationship...