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(const void *graph, const uip_ipaddr_t *child,
120  const uip_ipaddr_t *parent);
121 
122 /**
123  * Updates a child-parent link
124  *
125  * \param graph The graph the link belongs to
126  * \param child The IPv6 address of the child
127  * \param parent The IPv6 address of the parent
128  * \param lifetime The link lifetime in seconds
129 */
130 uip_sr_node_t *uip_sr_update_node(void *graph, const uip_ipaddr_t *child,
131  const uip_ipaddr_t *parent,
132  uint32_t lifetime);
133 
134 /**
135  * Returns the head of the non-storing node list
136  *
137  * \return The head of the list
138 */
140 
141 /**
142  * Returns the next element of the non-storing node list
143  *
144  * \param item The current element in the list
145  * \return The next element of the list
146 */
148 
149 /**
150  * Looks up for a source routing node from its IPv6 global address
151  *
152  * \param graph The graph where to look up for the node
153  * \param addr The target address
154  * \return A pointer to the node
155 */
156 uip_sr_node_t *uip_sr_get_node(const void *graph, const uip_ipaddr_t *addr);
157 
158 /**
159  * Telle whether an address is reachable, i.e. if there exists a path from
160  * the root to the node in the current source routing graph
161  *
162  * \param graph The graph where to look up for the node
163  * \param addr The target IPv6 global address
164  * \return 1 if the node is reachable, 0 otherwise
165 */
166 int uip_sr_is_addr_reachable(const void *graph, const uip_ipaddr_t *addr);
167 
168 /**
169  * A function called periodically. Used to age the links (decrease lifetime
170  * and expire links accordingly)
171  *
172  * \param seconds The number of seconds elapsted since last call
173 */
174 void uip_sr_periodic(unsigned seconds);
175 
176 /**
177  * Initialize this module
178 */
179 void uip_sr_init(void);
180 
181 /**
182  * Deallocate all neighbors
183 */
184 void uip_sr_free_all(void);
185 
186 /**
187 * Print a textual description of a source routing link
188 *
189 * \param buf The buffer where to write content
190 * \param buflen The buffer len
191 * \param link A pointer to the source routing link
192 * \return Identical to snprintf: number of bytes written excluding ending null
193 * byte. A value >= buflen if the buffer was too small.
194 */
195 int uip_sr_link_snprint(char *buf, int buflen, const uip_sr_node_t *link);
196 
197  /** @} */
198 
199 #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
uip_sr_node_t * uip_sr_node_next(const uip_sr_node_t *item)
Returns the next element of the non-storing node list.
Definition: uip-sr.c:205
void uip_sr_free_all(void)
Deallocate all neighbors.
Definition: uip-sr.c:248
void uip_sr_init(void)
Initialize this module.
Definition: uip-sr.c:191
uip_sr_node_t * uip_sr_get_node(const void *graph, const uip_ipaddr_t *addr)
Looks up for a source routing node from its IPv6 global address.
Definition: uip-sr.c:82
int uip_sr_is_addr_reachable(const void *graph, const uip_ipaddr_t *addr)
Telle whether an address is reachable, i.e.
Definition: uip-sr.c:95
int uip_sr_link_snprint(char *buf, int buflen, const uip_sr_node_t *link)
Print a textual description of a source routing link.
Definition: uip-sr.c:261
void uip_sr_periodic(unsigned seconds)
A function called periodically.
Definition: uip-sr.c:211
uip_sr_node_t * uip_sr_node_head(void)
Returns the head of the non-storing node list.
Definition: uip-sr.c:199
void uip_sr_expire_parent(const void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
Expires a given child-parent link.
Definition: uip-sr.c:114
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:127
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...