Contiki-Inga 3.x
collect.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimecollect Tree-based hop-by-hop reliable data collection
8  * @{
9  *
10  * The collect module implements a hop-by-hop reliable data collection
11  * mechanism.
12  *
13  * \section channels Channels
14  *
15  * The collect module uses 2 channels; one for neighbor discovery and one
16  * for data packets.
17  *
18  */
19 
20 /*
21  * Copyright (c) 2007, Swedish Institute of Computer Science.
22  * All rights reserved.
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  * 1. Redistributions of source code must retain the above copyright
28  * notice, this list of conditions and the following disclaimer.
29  * 2. Redistributions in binary form must reproduce the above copyright
30  * notice, this list of conditions and the following disclaimer in the
31  * documentation and/or other materials provided with the distribution.
32  * 3. Neither the name of the Institute nor the names of its contributors
33  * may be used to endorse or promote products derived from this software
34  * without specific prior written permission.
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
37  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
40  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  *
48  * This file is part of the Contiki operating system.
49  *
50  */
51 
52 /**
53  * \file
54  * Header file for hop-by-hop reliable data collection
55  * \author
56  * Adam Dunkels <adam@sics.se>
57  */
58 
59 #ifndef COLLECT_H_
60 #define COLLECT_H_
61 
62 #include "net/rime/announcement.h"
63 #include "net/rime/runicast.h"
66 #include "net/packetqueue.h"
67 #include "sys/ctimer.h"
68 #include "lib/list.h"
69 
70 #ifdef COLLECT_CONF_PACKET_ID_BITS
71 #define COLLECT_PACKET_ID_BITS COLLECT_CONF_PACKET_ID_BITS
72 #else /* COLLECT_CONF_PACKET_ID_BITS */
73 #define COLLECT_PACKET_ID_BITS 8
74 #endif /* COLLECT_CONF_PACKET_ID_BITS */
75 
76 #ifdef COLLECT_CONF_TTL_BITS
77 #define COLLECT_TTL_BITS COLLECT_CONF_TTL_BITS
78 #else /* COLLECT_CONF_TTL_BITS */
79 #define COLLECT_TTL_BITS 4
80 #endif /* COLLECT_CONF_TTL_BITS */
81 
82 #ifdef COLLECT_CONF_HOPS_BITS
83 #define COLLECT_HOPS_BITS COLLECT_CONF_HOPS_BITS
84 #else /* COLLECT_CONF_HOPS_BITS */
85 #define COLLECT_HOPS_BITS 4
86 #endif /* COLLECT_CONF_HOPS_BITS */
87 
88 #ifdef COLLECT_CONF_MAX_REXMIT_BITS
89 #define COLLECT_MAX_REXMIT_BITS COLLECT_CONF_MAX_REXMIT_BITS
90 #else /* COLLECT_CONF_REXMIT_BITS */
91 #define COLLECT_MAX_REXMIT_BITS 5
92 #endif /* COLLECT_CONF_REXMIT_BITS */
93 
94 #define COLLECT_ATTRIBUTES { PACKETBUF_ADDR_ESENDER, PACKETBUF_ADDRSIZE }, \
95  { PACKETBUF_ATTR_EPACKET_ID, PACKETBUF_ATTR_BIT * COLLECT_PACKET_ID_BITS }, \
96  { PACKETBUF_ATTR_PACKET_ID, PACKETBUF_ATTR_BIT * COLLECT_PACKET_ID_BITS }, \
97  { PACKETBUF_ATTR_TTL, PACKETBUF_ATTR_BIT * COLLECT_TTL_BITS }, \
98  { PACKETBUF_ATTR_HOPS, PACKETBUF_ATTR_BIT * COLLECT_HOPS_BITS }, \
99  { PACKETBUF_ATTR_MAX_REXMIT, PACKETBUF_ATTR_BIT * COLLECT_MAX_REXMIT_BITS }, \
100  { PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_BIT }, \
101  UNICAST_ATTRIBUTES
102 
103 struct collect_callbacks {
104  void (* recv)(const linkaddr_t *originator, uint8_t seqno,
105  uint8_t hops);
106 };
107 
108 /* COLLECT_CONF_ANNOUNCEMENTS defines if the Collect implementation
109  should use Contiki's announcement primitive to announce its routes
110  or if it should use periodic broadcasts. */
111 #ifndef COLLECT_CONF_ANNOUNCEMENTS
112 #define COLLECT_ANNOUNCEMENTS 1
113 #else
114 #define COLLECT_ANNOUNCEMENTS COLLECT_CONF_ANNOUNCEMENTS
115 #endif /* COLLECT_CONF_ANNOUNCEMENTS */
116 
117 struct collect_conn {
118  struct unicast_conn unicast_conn;
119 #if ! COLLECT_ANNOUNCEMENTS
120  struct neighbor_discovery_conn neighbor_discovery_conn;
121 #else /* ! COLLECT_ANNOUNCEMENTS */
122  struct announcement announcement;
123  struct ctimer transmit_after_scan_timer;
124 #endif /* COLLECT_ANNOUNCEMENTS */
125  const struct collect_callbacks *cb;
126  struct ctimer retransmission_timer;
127  LIST_STRUCT(send_queue_list);
128  struct packetqueue send_queue;
129  struct collect_neighbor_list neighbor_list;
130 
131  struct ctimer keepalive_timer;
132  clock_time_t keepalive_period;
133 
134  struct ctimer proactive_probing_timer;
135 
136  linkaddr_t parent, current_parent;
137  uint16_t rtmetric;
138  uint8_t seqno;
139  uint8_t sending, transmissions, max_rexmits;
140  uint8_t eseqno;
141  uint8_t is_router;
142 
143  clock_time_t send_time;
144 };
145 
146 enum {
147  COLLECT_NO_ROUTER,
148  COLLECT_ROUTER,
149 };
150 
151 void collect_open(struct collect_conn *c, uint16_t channels,
152  uint8_t is_router,
153  const struct collect_callbacks *callbacks);
154 void collect_close(struct collect_conn *c);
155 
156 int collect_send(struct collect_conn *c, int rexmits);
157 
158 void collect_set_sink(struct collect_conn *c, int should_be_sink);
159 
160 int collect_depth(struct collect_conn *c);
161 const linkaddr_t *collect_parent(struct collect_conn *c);
162 
163 void collect_set_keepalive(struct collect_conn *c, clock_time_t period);
164 
165 void collect_print_stats(void);
166 
167 #define COLLECT_MAX_DEPTH (COLLECT_LINK_ESTIMATE_UNIT * 64 - 1)
168 
169 #endif /* COLLECT_H_ */
170 /** @} */
171 /** @} */