Contiki 3.x
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 uip6
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/ip/uip.h"
44 #include "net/nbr-table.h"
45 #include "sys/stimer.h"
46 #include "lib/list.h"
47 
48 NBR_TABLE_DECLARE(nbr_routes);
49 
50 void uip_ds6_route_init(void);
51 
52 #ifndef UIP_CONF_UIP_DS6_NOTIFICATIONS
53 #define UIP_DS6_NOTIFICATIONS (UIP_CONF_MAX_ROUTES != 0)
54 #else
55 #define UIP_DS6_NOTIFICATIONS UIP_CONF_UIP_DS6_NOTIFICATIONS
56 #endif
57 
58 #if UIP_DS6_NOTIFICATIONS
59 /* Event constants for the uip-ds6 route notification interface. The
60  notification interface allows for a user program to be notified via
61  a callback when a route has been added or removed and when the
62  system has added or removed a default route. */
63 #define UIP_DS6_NOTIFICATION_DEFRT_ADD 0
64 #define UIP_DS6_NOTIFICATION_DEFRT_RM 1
65 #define UIP_DS6_NOTIFICATION_ROUTE_ADD 2
66 #define UIP_DS6_NOTIFICATION_ROUTE_RM 3
67 
68 typedef void (* uip_ds6_notification_callback)(int event,
69  uip_ipaddr_t *route,
70  uip_ipaddr_t *nexthop,
71  int num_routes);
72 struct uip_ds6_notification {
73  struct uip_ds6_notification *next;
74  uip_ds6_notification_callback callback;
75 };
76 
77 void uip_ds6_notification_add(struct uip_ds6_notification *n,
78  uip_ds6_notification_callback c);
79 
80 void uip_ds6_notification_rm(struct uip_ds6_notification *n);
81 /*--------------------------------------------------*/
82 #endif
83 
84 /* Routing table */
85 #ifndef UIP_CONF_MAX_ROUTES
86 #ifdef UIP_CONF_DS6_ROUTE_NBU
87 #define UIP_DS6_ROUTE_NB UIP_CONF_DS6_ROUTE_NBU
88 #else /* UIP_CONF_DS6_ROUTE_NBU */
89 #define UIP_DS6_ROUTE_NB 4
90 #endif /* UIP_CONF_DS6_ROUTE_NBU */
91 #else /* UIP_CONF_MAX_ROUTES */
92 #define UIP_DS6_ROUTE_NB UIP_CONF_MAX_ROUTES
93 #endif /* UIP_CONF_MAX_ROUTES */
94 
95 /** \brief define some additional RPL related route state and
96  * neighbor callback for RPL - if not a DS6_ROUTE_STATE is already set */
97 #ifndef UIP_DS6_ROUTE_STATE_TYPE
98 #define UIP_DS6_ROUTE_STATE_TYPE rpl_route_entry_t
99 /* Needed for the extended route entry state when using ContikiRPL */
100 #define RPL_ROUTE_ENTRY_NOPATH_RECEIVED 0x01
101 #define RPL_ROUTE_ENTRY_DAO_PENDING 0x02
102 #define RPL_ROUTE_ENTRY_DAO_NACK 0x04
103 
104 #define RPL_ROUTE_IS_NOPATH_RECEIVED(route) \
105  (((route)->state.state_flags & RPL_ROUTE_ENTRY_NOPATH_RECEIVED) != 0)
106 #define RPL_ROUTE_SET_NOPATH_RECEIVED(route) do { \
107  (route)->state.state_flags |= RPL_ROUTE_ENTRY_NOPATH_RECEIVED; \
108  } while(0)
109 #define RPL_ROUTE_CLEAR_NOPATH_RECEIVED(route) do { \
110  (route)->state.state_flags &= ~RPL_ROUTE_ENTRY_NOPATH_RECEIVED; \
111  } while(0)
112 
113 #define RPL_ROUTE_IS_DAO_PENDING(route) \
114  ((route->state.state_flags & RPL_ROUTE_ENTRY_DAO_PENDING) != 0)
115 #define RPL_ROUTE_SET_DAO_PENDING(route) do { \
116  (route)->state.state_flags |= RPL_ROUTE_ENTRY_DAO_PENDING; \
117  } while(0)
118 #define RPL_ROUTE_CLEAR_DAO_PENDING(route) do { \
119  (route)->state.state_flags &= ~RPL_ROUTE_ENTRY_DAO_PENDING; \
120  } while(0)
121 
122 #define RPL_ROUTE_IS_DAO_NACKED(route) \
123  ((route->state.state_flags & RPL_ROUTE_ENTRY_DAO_NACK) != 0)
124 #define RPL_ROUTE_SET_DAO_NACKED(route) do { \
125  (route)->state.state_flags |= RPL_ROUTE_ENTRY_DAO_NACK; \
126  } while(0)
127 #define RPL_ROUTE_CLEAR_DAO_NACKED(route) do { \
128  (route)->state.state_flags &= ~RPL_ROUTE_ENTRY_DAO_NACK; \
129  } while(0)
130 
131 #define RPL_ROUTE_CLEAR_DAO(route) do { \
132  (route)->state.state_flags &= ~(RPL_ROUTE_ENTRY_DAO_NACK|RPL_ROUTE_ENTRY_DAO_PENDING); \
133  } while(0)
134 
135 struct rpl_dag;
136 typedef struct rpl_route_entry {
137  uint32_t lifetime;
138  struct rpl_dag *dag;
139  uint8_t dao_seqno_out;
140  uint8_t dao_seqno_in;
141  uint8_t state_flags;
142 } rpl_route_entry_t;
143 #endif /* UIP_DS6_ROUTE_STATE_TYPE */
144 
145 /** \brief The neighbor routes hold a list of routing table entries
146  that are attached to a specific neihbor. */
148  LIST_STRUCT(route_list);
149 };
150 
151 /** \brief An entry in the routing table */
152 typedef struct uip_ds6_route {
153  struct uip_ds6_route *next;
154  /* Each route entry belongs to a specific neighbor. That neighbor
155  holds a list of all routing entries that go through it. The
156  routes field point to the uip_ds6_route_neighbor_routes that
157  belong to the neighbor table entry that this routing table entry
158  uses. */
159  struct uip_ds6_route_neighbor_routes *neighbor_routes;
160  uip_ipaddr_t ipaddr;
161 #ifdef UIP_DS6_ROUTE_STATE_TYPE
163 #endif
164  uint8_t length;
166 
167 /** \brief A neighbor route list entry, used on the
168  uip_ds6_route->neighbor_routes->route_list list. */
170  struct uip_ds6_route_neighbor_route *next;
171  struct uip_ds6_route *route;
172 };
173 
174 /** \brief An entry in the default router list */
175 typedef struct uip_ds6_defrt {
176  struct uip_ds6_defrt *next;
177  uip_ipaddr_t ipaddr;
178  struct stimer lifetime;
179  uint8_t isinfinite;
181 
182 /** \name Default router list basic routines */
183 /** @{ */
184 uip_ds6_defrt_t *uip_ds6_defrt_add(uip_ipaddr_t *ipaddr,
185  unsigned long interval);
186 void uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt);
187 uip_ds6_defrt_t *uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr);
188 uip_ipaddr_t *uip_ds6_defrt_choose(void);
189 
190 void uip_ds6_defrt_periodic(void);
191 /** @} */
192 
193 
194 /** \name Routing Table basic routines */
195 /** @{ */
196 uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
197 uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
198  uip_ipaddr_t *next_hop);
199 void uip_ds6_route_rm(uip_ds6_route_t *route);
200 void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);
201 
202 uip_ipaddr_t *uip_ds6_route_nexthop(uip_ds6_route_t *);
203 int uip_ds6_route_num_routes(void);
204 uip_ds6_route_t *uip_ds6_route_head(void);
205 uip_ds6_route_t *uip_ds6_route_next(uip_ds6_route_t *);
206 int uip_ds6_route_is_nexthop(const uip_ipaddr_t *ipaddr);
207 /** @} */
208 
209 #endif /* UIP_DS6_ROUTE_H */
210 /** @} */
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition: uip-nd6.c:129
A neighbor route list entry, used on the uip_ds6_route->neighbor_routes->route_list 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...
Definition: uip-ds6-route.h:98
An entry in the default router list.
static uip_ds6_defrt_t * defrt
Pointer to a nbr cache entry.
Definition: uip-nd6.c:123
static uip_ds6_route_t * route
The next route to use.
Definition: res_routes.c:31
Second timer library header file.
struct uip_ds6_route uip_ds6_route_t
An entry in the routing table.
Linked list manipulation routines.
Header file for the uIP TCP/IP stack.
A timer.
Definition: stimer.h:81
struct uip_ds6_defrt uip_ds6_defrt_t
An entry in the default router list.
The neighbor routes hold a list of routing table entries that are attached to a specific neihbor...
An entry in the routing table.