Contiki-NG
uip-ds6-route.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012, Thingsquare, http://www.thingsquare.com/.
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 *
14 * 3. Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32/**
33 * \addtogroup uip
34 * @{
35 */
36/**
37 * \file
38 * Header file for routing table manipulation
39 */
40#ifndef UIP_DS6_ROUTE_H
41#define UIP_DS6_ROUTE_H
42
43#include "net/ipv6/uip.h"
44#include "net/nbr-table.h"
45#include "sys/stimer.h"
46#include "lib/list.h"
47
48#ifdef UIP_CONF_MAX_ROUTES
49
50#define UIP_MAX_ROUTES UIP_CONF_MAX_ROUTES
51
52#else /* UIP_CONF_MAX_ROUTES */
53
54#if ROUTING_CONF_RPL_LITE
55#define UIP_MAX_ROUTES 0 /* RPL Lite only supports non-storing, no routes */
56#elif ROUTING_CONF_RPL_CLASSIC
57
58#include "net/routing/rpl-classic/rpl-conf.h"
59#if RPL_WITH_STORING
60#define UIP_MAX_ROUTES NETSTACK_MAX_ROUTE_ENTRIES
61#else /* RPL_WITH_STORING */
62#define UIP_MAX_ROUTES 0 /* No storing mode, no need for routes */
63#endif /* RPL_WITH_STORING */
64
65#else /* Not RPL Lite nor RPL Classic */
66#define UIP_MAX_ROUTES NETSTACK_MAX_ROUTE_ENTRIES
67#endif
68
69#endif /* UIP_CONF_MAX_ROUTES */
70
71NBR_TABLE_DECLARE(nbr_routes);
72
73void uip_ds6_route_init(void);
74
75#ifndef UIP_CONF_UIP_DS6_NOTIFICATIONS
76#define UIP_DS6_NOTIFICATIONS (UIP_MAX_ROUTES != 0)
77#else
78#define UIP_DS6_NOTIFICATIONS UIP_CONF_UIP_DS6_NOTIFICATIONS
79#endif
80
81#if UIP_DS6_NOTIFICATIONS
82/* Event constants for the uip-ds6 route notification interface. The
83 notification interface allows for a user program to be notified via
84 a callback when a route has been added or removed and when the
85 system has added or removed a default route. */
86#define UIP_DS6_NOTIFICATION_DEFRT_ADD 0
87#define UIP_DS6_NOTIFICATION_DEFRT_RM 1
88#define UIP_DS6_NOTIFICATION_ROUTE_ADD 2
89#define UIP_DS6_NOTIFICATION_ROUTE_RM 3
90
91typedef void (* uip_ds6_notification_callback)(int event,
92 const uip_ipaddr_t *route,
93 const uip_ipaddr_t *nexthop,
94 int num_routes);
95struct uip_ds6_notification {
96 struct uip_ds6_notification *next;
97 uip_ds6_notification_callback callback;
98};
99
100void uip_ds6_notification_add(struct uip_ds6_notification *n,
101 uip_ds6_notification_callback c);
102
103void uip_ds6_notification_rm(struct uip_ds6_notification *n);
104/*--------------------------------------------------*/
105#endif
106
107/* Routing table */
108#ifdef UIP_MAX_ROUTES
109#define UIP_DS6_ROUTE_NB UIP_MAX_ROUTES
110#else /* UIP_MAX_ROUTES */
111#define UIP_DS6_ROUTE_NB 4
112#endif /* UIP_MAX_ROUTES */
113
114/** \brief define some additional RPL related route state and
115 * neighbor callback for RPL - if not a DS6_ROUTE_STATE is already set */
116#ifndef UIP_DS6_ROUTE_STATE_TYPE
117#define UIP_DS6_ROUTE_STATE_TYPE rpl_route_entry_t
118/* Needed for the extended route entry state when using ContikiRPL */
119#define RPL_ROUTE_ENTRY_NOPATH_RECEIVED 0x01
120#define RPL_ROUTE_ENTRY_DAO_PENDING 0x02
121#define RPL_ROUTE_ENTRY_DAO_NACK 0x04
122
123#define RPL_ROUTE_IS_NOPATH_RECEIVED(route) \
124 (((route)->state.state_flags & RPL_ROUTE_ENTRY_NOPATH_RECEIVED) != 0)
125#define RPL_ROUTE_SET_NOPATH_RECEIVED(route) do { \
126 (route)->state.state_flags |= RPL_ROUTE_ENTRY_NOPATH_RECEIVED; \
127 } while(0)
128#define RPL_ROUTE_CLEAR_NOPATH_RECEIVED(route) do { \
129 (route)->state.state_flags &= ~RPL_ROUTE_ENTRY_NOPATH_RECEIVED; \
130 } while(0)
131
132#define RPL_ROUTE_IS_DAO_PENDING(route) \
133 ((route->state.state_flags & RPL_ROUTE_ENTRY_DAO_PENDING) != 0)
134#define RPL_ROUTE_SET_DAO_PENDING(route) do { \
135 (route)->state.state_flags |= RPL_ROUTE_ENTRY_DAO_PENDING; \
136 } while(0)
137#define RPL_ROUTE_CLEAR_DAO_PENDING(route) do { \
138 (route)->state.state_flags &= ~RPL_ROUTE_ENTRY_DAO_PENDING; \
139 } while(0)
140
141#define RPL_ROUTE_IS_DAO_NACKED(route) \
142 ((route->state.state_flags & RPL_ROUTE_ENTRY_DAO_NACK) != 0)
143#define RPL_ROUTE_SET_DAO_NACKED(route) do { \
144 (route)->state.state_flags |= RPL_ROUTE_ENTRY_DAO_NACK; \
145 } while(0)
146#define RPL_ROUTE_CLEAR_DAO_NACKED(route) do { \
147 (route)->state.state_flags &= ~RPL_ROUTE_ENTRY_DAO_NACK; \
148 } while(0)
149
150#define RPL_ROUTE_CLEAR_DAO(route) do { \
151 (route)->state.state_flags &= ~(RPL_ROUTE_ENTRY_DAO_NACK|RPL_ROUTE_ENTRY_DAO_PENDING); \
152 } while(0)
153
154struct rpl_dag;
155typedef struct rpl_route_entry {
156 uint32_t lifetime;
157 struct rpl_dag *dag;
158 uint8_t dao_seqno_out;
159 uint8_t dao_seqno_in;
160 uint8_t state_flags;
161} rpl_route_entry_t;
162#endif /* UIP_DS6_ROUTE_STATE_TYPE */
163
164/** \brief The neighbor routes hold a list of routing table entries
165 that are attached to a specific neihbor. */
167 LIST_STRUCT(route_list);
168};
169
170/** \brief An entry in the routing table */
171typedef struct uip_ds6_route {
172 struct uip_ds6_route *next;
173 /* Each route entry belongs to a specific neighbor. That neighbor
174 holds a list of all routing entries that go through it. The
175 routes field point to the uip_ds6_route_neighbor_routes that
176 belong to the neighbor table entry that this routing table entry
177 uses. */
178 struct uip_ds6_route_neighbor_routes *neighbor_routes;
179 uip_ipaddr_t ipaddr;
180#ifdef UIP_DS6_ROUTE_STATE_TYPE
182#endif
183 uint8_t length;
185
186/** \brief A neighbor route list entry, used on the
187 uip_ds6_route->neighbor_routes->route_list list. */
189 struct uip_ds6_route_neighbor_route *next;
190 struct uip_ds6_route *route;
191};
192
193/** \brief An entry in the default router list */
194typedef struct uip_ds6_defrt {
195 struct uip_ds6_defrt *next;
196 uip_ipaddr_t ipaddr;
197 struct stimer lifetime;
198 uint8_t isinfinite;
200
201/** \name Default router list basic routines */
202/** @{ */
203uip_ds6_defrt_t *uip_ds6_defrt_head(void);
204uip_ds6_defrt_t *uip_ds6_defrt_add(const uip_ipaddr_t *ipaddr,
205 unsigned long interval);
206void uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt);
207uip_ds6_defrt_t *uip_ds6_defrt_lookup(const uip_ipaddr_t *ipaddr);
208const uip_ipaddr_t *uip_ds6_defrt_choose(void);
209
210void uip_ds6_defrt_periodic(void);
211/** @} */
212
213
214/** \name Routing Table basic routines */
215/** @{ */
216uip_ds6_route_t *uip_ds6_route_lookup(const uip_ipaddr_t *destipaddr);
217uip_ds6_route_t *uip_ds6_route_add(const uip_ipaddr_t *ipaddr, uint8_t length,
218 const uip_ipaddr_t *next_hop);
219void uip_ds6_route_rm(uip_ds6_route_t *route);
220void uip_ds6_route_rm_by_nexthop(const uip_ipaddr_t *nexthop);
221
222const uip_ipaddr_t *uip_ds6_route_nexthop(uip_ds6_route_t *);
223int uip_ds6_route_num_routes(void);
224uip_ds6_route_t *uip_ds6_route_head(void);
225uip_ds6_route_t *uip_ds6_route_next(uip_ds6_route_t *);
226int uip_ds6_route_is_nexthop(const uip_ipaddr_t *ipaddr);
227int uip_ds6_route_count_nexthop_neighbors(void);
228/** @} */
229
230#endif /* UIP_DS6_ROUTE_H */
231/** @} */
struct uip_ds6_route uip_ds6_route_t
An entry in the routing table.
struct uip_ds6_defrt uip_ds6_defrt_t
An entry in the default router list.
#define UIP_DS6_ROUTE_STATE_TYPE
define some additional RPL related route state and neighbor callback for RPL - if not a DS6_ROUTE_STA...
Linked list manipulation routines.
Second timer library header file.
RPL DAG structure.
Definition: rpl.h:138
A timer.
Definition: stimer.h:81
An entry in the default router list.
A neighbor route list entry, used on the uip_ds6_route->neighbor_routes->route_list list.
The neighbor routes hold a list of routing table entries that are attached to a specific neihbor.
An entry in the routing table.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition: uip-nd6.c:116
static uip_ds6_defrt_t * defrt
Pointer to an interface address.
Definition: uip-nd6.c:111
Header file for the uIP TCP/IP stack.