Contiki 3.x
collect.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007, 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  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Header file for hop-by-hop reliable data collection
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rime
42  * @{
43  */
44 
45 /**
46  * \defgroup rimecollect Tree-based hop-by-hop reliable data collection
47  * @{
48  *
49  * The collect module implements a hop-by-hop reliable data collection
50  * mechanism.
51  *
52  * \section channels Channels
53  *
54  * The collect module uses 2 channels; one for neighbor discovery and one
55  * for data packets.
56  *
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 /** @} */
Linked list manipulation routines.
Header file for the packetqueue module
Neighbor discovery header file
#define LIST_STRUCT(name)
Declare a linked list inside a structure declaraction.
Definition: list.h:108
Header file for the announcement primitive
Reliable unicast header file
Header file for the callback timer
Representation of a packet queue.
Definition: packetqueue.h:70
Header file for the Contiki radio neighborhood management
Representation of an announcement.
Definition: announcement.h:83