Contiki-Inga 3.x
uip-ds6-route.h
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 /**
34  * \addtogroup uip6
35  * @{
36  */
37 
38 /**
39  * @defgroup uip_ds6_routing Routing
40  *
41  * @{ */
42 
43 #ifndef UIP_DS6_ROUTE_H
44 #define UIP_DS6_ROUTE_H
45 
46 #include "sys/stimer.h"
47 #include "lib/list.h"
48 
49 /** Initialize routing. */
50 void uip_ds6_route_init(void);
51 
52 #ifndef UIP_CONF_UIP_DS6_NOTIFICATIONS
53 #define UIP_DS6_NOTIFICATIONS 1
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 typedef struct rpl_route_entry {
101  uint32_t lifetime;
102  void *dag;
103  uint8_t learned_from;
104  uint8_t nopath_received;
105 } rpl_route_entry_t;
106 #endif /* UIP_DS6_ROUTE_STATE_TYPE */
107 
108 /** \brief The neighbor routes hold a list of routing table entries
109  that are attached to a specific neihbor. */
111  LIST_STRUCT(route_list);
112 };
113 
114 /** \brief An entry in the routing table */
115 typedef struct uip_ds6_route {
116  struct uip_ds6_route *next;
117  /* Each route entry belongs to a specific neighbor. That neighbor
118  holds a list of all routing entries that go through it. The
119  routes field point to the uip_ds6_route_neighbor_routes that
120  belong to the neighbor table entry that this routing table entry
121  uses. */
122  struct uip_ds6_route_neighbor_routes *neighbor_routes;
123  uip_ipaddr_t ipaddr;
124 #ifdef UIP_DS6_ROUTE_STATE_TYPE
126 #endif
127  uint8_t length;
129 
130 /** \brief A neighbor route list entry, used on the
131  uip_ds6_route->neighbor_routes->route_list list. */
133  struct uip_ds6_route_neighbor_route *next;
134  struct uip_ds6_route *route;
135 };
136 
137 /** \brief An entry in the default router list */
138 typedef struct uip_ds6_defrt {
139  struct uip_ds6_defrt *next;
140  uip_ipaddr_t ipaddr;
141  struct stimer lifetime;
142  uint8_t isinfinite;
144 
145 /** \name Default router list basic routines */
146 /** @{ */
147 /** Add default router. */
148 uip_ds6_defrt_t *uip_ds6_defrt_add(uip_ipaddr_t *ipaddr,
149  unsigned long interval);
150 /** Remove default router. */
151 void uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt);
152 /** Lookup default router for address. */
153 uip_ds6_defrt_t *uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr);
154 /** ? */
155 uip_ipaddr_t *uip_ds6_defrt_choose(void);
156 /** ? */
157 void uip_ds6_defrt_periodic(void);
158 /** @} */
159 
160 
161 /** \name Routing Table basic routines */
162 /** @{ */
163 /** Lookup route for address. */
164 uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
165 /** Add route for address. */
166 uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
167  uip_ipaddr_t *next_hop);
168 /** Remove route. */
169 void uip_ds6_route_rm(uip_ds6_route_t *route);
170 /** */
171 void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);
172 /** */
173 uip_ipaddr_t *uip_ds6_route_nexthop(uip_ds6_route_t *);
174 /** Number of routes? */
175 int uip_ds6_route_num_routes(void);
176 /** First route? */
178 /** Next route? */
180 
181 /** @} */
182 
183 /** @} */
184 /** @} */
185 
186 #endif /* UIP_DS6_ROUTE_H */
187