Contiki-Inga 3.x
uip-ds6-nbr.h
1 /*
2  * Copyright (c) 2013, Swedish Institute of Computer Science.
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  *
30  */
31 
32 /**
33  * \file IPv6 Neighbor cache (link-layer/IPv6 address mapping)
34  *
35  * \author Mathilde Durvy <mdurvy@cisco.com>
36  * \author Julien Abeille <jabeille@cisco.com>
37  * \author Simon Duquennoy <simonduq@sics.se>
38  */
39 
40 /**
41  * \addtogroup uip6
42  * @{
43  */
44 
45 /** @defgroup uip_ds6_nbr IPv6 Neighbor cache (link-layer/IPv6 address mapping)
46  *
47  * Data structure and methods for IPv6 Neighbor Cache (RFC 4861, section 5.1)
48  *
49  * \author Mathilde Durvy <mdurvy@cisco.com>
50  * \author Julien Abeille <jabeille@cisco.com>
51  * \author Simon Duquennoy <simonduq@sics.se>
52  * @{ */
53 
54 #ifndef UIP_DS6_NEIGHBOR_H_
55 #define UIP_DS6_NEIGHBOR_H_
56 
57 #include "net/ip/uip.h"
58 #include "net/nbr-table.h"
59 #include "sys/stimer.h"
60 #include "net/ipv6/uip-ds6.h"
61 #include "net/nbr-table.h"
62 
63 #if UIP_CONF_IPV6_QUEUE_PKT
64 #include "net/ip/uip-packetqueue.h"
65 #endif /* UIP_CONF_IPV6_QUEUE_PKT */
66 
67 /*--------------------------------------------------*/
68 /** \name Possible states for the nbr cache entries
69  * @{ */
70 #define NBR_INCOMPLETE 0
71 #define NBR_REACHABLE 1
72 #define NBR_STALE 2
73 #define NBR_DELAY 3
74 #define NBR_PROBE 4
75 /** @} */
76 
77 NBR_TABLE_DECLARE(ds6_neighbors);
78 
79 /** \brief An entry in the nbr cache */
80 typedef struct uip_ds6_nbr {
81  uip_ipaddr_t ipaddr;
82  struct stimer reachable;
83  struct stimer sendns;
84  uint8_t nscount;
85  uint8_t isrouter;
86  uint8_t state;
87 #if UIP_CONF_IPV6_QUEUE_PKT
88  struct uip_packetqueue_handle packethandle;
89 #define UIP_DS6_NBR_PACKET_LIFETIME CLOCK_SECOND * 4
90 #endif /* UIP_CONF_IPV6_QUEUE_PKT */
92 
93 /** Initialize neighbor cache. */
94 void uip_ds6_neighbors_init(void);
95 
96 /** \name Neighbor Cache basic routines
97  *
98  * @{ */
99 /** Adds a neighbor to the neighbor cache.
100  *
101  * @param ipaddr IP address of the neighbor to add.
102  * @param lladdr Link-local address of the neighbor (may be unknown when added),
103  * NULL if not known (requires state to be set to NBR_INCOMPLETE)
104  * @param isrouter Set to 1 if neighbor is a router,
105  * to 0 if host or unknown
106  * @param state State of this entry.
107  * Possible values are:
108  * \ref NBR_INCOMPLETE,
109  * \ref NBR_REACHABLE,
110  * \ref NBR_STALE,
111  * \ref NBR_DELAY,
112  * \ref NBR_PROBE
113  */
114 uip_ds6_nbr_t *uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr,
115  uint8_t isrouter, uint8_t state);
116 /** Removes entry from neighbor cache.
117  */
118 void uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr);
119 /** Returns link-local address of neighbor.
120  */
122 /** Returns IP address of neighbor.
123  */
124 const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr);
125 /** Lookup if a neighbor cache entry for given IP address exists.
126  *
127  * @param ipaddr IP address to look up
128  * @return NULL if no entry was found,
129  * otherwise a pointer to that entry
130  */
131 uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr);
132 /** Lookup if a neighbor cache entry for given link-layer address exists.
133  *
134  * @param llpaddr link-layer address to look up
135  * @return NULL if no entry was found,
136  * otherwise a pointer to that entry
137  */
139 /** Returns IP address associated with link-local address, based on neighbor cache entry. */
140 uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr);
141 /** Returns link-layer address associated with IP address, based on neighbor cache entry. */
142 const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr);
143 /** ? */
144 void uip_ds6_link_neighbor_callback(int status, int numtx);
145 /** ? */
146 void uip_ds6_neighbor_periodic(void);
147 /** ? */
148 int uip_ds6_nbr_num(void);
149 
150 /**
151  * \brief
152  * This searches inside the neighbor table for the neighbor that is about to
153  * expire the next.
154  *
155  * @return
156  * A reference to the neighbor about to expire the next or NULL if
157  * table is empty.
158  */
160 /** @} */
161 
162 /** @} */
163 
164 #endif /* UIP_DS6_NEIGHBOR_H_ */