Contiki 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 #ifndef UIP_DS6_ROUTE_H
33 #define UIP_DS6_ROUTE_H
34 
35 #include "sys/stimer.h"
36 #include "lib/list.h"
37 
38 void uip_ds6_route_init(void);
39 
40 #ifndef UIP_CONF_UIP_DS6_NOTIFICATIONS
41 #define UIP_DS6_NOTIFICATIONS 1
42 #else
43 #define UIP_DS6_NOTIFICATIONS UIP_CONF_UIP_DS6_NOTIFICATIONS
44 #endif
45 
46 #if UIP_DS6_NOTIFICATIONS
47 /* Event constants for the uip-ds6 route notification interface. The
48  notification interface allows for a user program to be notified via
49  a callback when a route has been added or removed and when the
50  system has added or removed a default route. */
51 #define UIP_DS6_NOTIFICATION_DEFRT_ADD 0
52 #define UIP_DS6_NOTIFICATION_DEFRT_RM 1
53 #define UIP_DS6_NOTIFICATION_ROUTE_ADD 2
54 #define UIP_DS6_NOTIFICATION_ROUTE_RM 3
55 
56 typedef void (* uip_ds6_notification_callback)(int event,
57  uip_ipaddr_t *route,
58  uip_ipaddr_t *nexthop,
59  int num_routes);
60 struct uip_ds6_notification {
61  struct uip_ds6_notification *next;
62  uip_ds6_notification_callback callback;
63 };
64 
65 void uip_ds6_notification_add(struct uip_ds6_notification *n,
66  uip_ds6_notification_callback c);
67 
68 void uip_ds6_notification_rm(struct uip_ds6_notification *n);
69 /*--------------------------------------------------*/
70 #endif
71 
72 /* Routing table */
73 #ifndef UIP_CONF_MAX_ROUTES
74 #ifdef UIP_CONF_DS6_ROUTE_NBU
75 #define UIP_DS6_ROUTE_NB UIP_CONF_DS6_ROUTE_NBU
76 #else /* UIP_CONF_DS6_ROUTE_NBU */
77 #define UIP_DS6_ROUTE_NB 4
78 #endif /* UIP_CONF_DS6_ROUTE_NBU */
79 #else /* UIP_CONF_MAX_ROUTES */
80 #define UIP_DS6_ROUTE_NB UIP_CONF_MAX_ROUTES
81 #endif /* UIP_CONF_MAX_ROUTES */
82 
83 /** \brief define some additional RPL related route state and
84  * neighbor callback for RPL - if not a DS6_ROUTE_STATE is already set */
85 #ifndef UIP_DS6_ROUTE_STATE_TYPE
86 #define UIP_DS6_ROUTE_STATE_TYPE rpl_route_entry_t
87 /* Needed for the extended route entry state when using ContikiRPL */
88 typedef struct rpl_route_entry {
89  uint32_t lifetime;
90  void *dag;
91  uint8_t learned_from;
92  uint8_t nopath_received;
93 } rpl_route_entry_t;
94 #endif /* UIP_DS6_ROUTE_STATE_TYPE */
95 
96 /** \brief The neighbor routes hold a list of routing table entries
97  that are attached to a specific neihbor. */
99  LIST_STRUCT(route_list);
100 };
101 
102 /** \brief An entry in the routing table */
103 typedef struct uip_ds6_route {
104  struct uip_ds6_route *next;
105  /* Each route entry belongs to a specific neighbor. That neighbor
106  holds a list of all routing entries that go through it. The
107  routes field point to the uip_ds6_route_neighbor_routes that
108  belong to the neighbor table entry that this routing table entry
109  uses. */
110  struct uip_ds6_route_neighbor_routes *neighbor_routes;
111  uip_ipaddr_t ipaddr;
112 #ifdef UIP_DS6_ROUTE_STATE_TYPE
113  UIP_DS6_ROUTE_STATE_TYPE state;
114 #endif
115  uint8_t length;
117 
118 /** \brief A neighbor route list entry, used on the
119  uip_ds6_route->neighbor_routes->route_list list. */
121  struct uip_ds6_route_neighbor_route *next;
122  struct uip_ds6_route *route;
123 };
124 
125 /** \brief An entry in the default router list */
126 typedef struct uip_ds6_defrt {
127  struct uip_ds6_defrt *next;
128  uip_ipaddr_t ipaddr;
129  struct stimer lifetime;
130  uint8_t isinfinite;
132 
133 /** \name Default router list basic routines */
134 /** @{ */
135 uip_ds6_defrt_t *uip_ds6_defrt_add(uip_ipaddr_t *ipaddr,
136  unsigned long interval);
137 void uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt);
138 uip_ds6_defrt_t *uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr);
139 uip_ipaddr_t *uip_ds6_defrt_choose(void);
140 
141 void uip_ds6_defrt_periodic(void);
142 /** @} */
143 
144 
145 /** \name Routing Table basic routines */
146 /** @{ */
147 uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
148 uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
149  uip_ipaddr_t *next_hop);
150 void uip_ds6_route_rm(uip_ds6_route_t *route);
151 void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);
152 
153 uip_ipaddr_t *uip_ds6_route_nexthop(uip_ds6_route_t *);
154 int uip_ds6_route_num_routes(void);
155 uip_ds6_route_t *uip_ds6_route_head(void);
156 uip_ds6_route_t *uip_ds6_route_next(uip_ds6_route_t *);
157 
158 /** @} */
159 
160 #endif /* UIP_DS6_ROUTE_H */
Second timer library header file.
Linked list manipulation routines.
An entry in the routing table.
The neighbor routes hold a list of routing table entries that are attached to a specific neihbor...
Definition: uip-ds6-route.h:98
A neighbor route list entry, used on the uip_ds6_route->neighbor_routes->route_list list...
A timer.
Definition: stimer.h:81
An entry in the default router list.