Contiki 2.5
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  * $Id: collect.h,v 1.26 2011/01/09 23:48:33 adamdunkels Exp $
51  */
52 
53 /**
54  * \file
55  * Header file for hop-by-hop reliable data collection
56  * \author
57  * Adam Dunkels <adam@sics.se>
58  */
59 
60 #ifndef __COLLECT_H__
61 #define __COLLECT_H__
62 
63 #include "net/rime/announcement.h"
64 #include "net/rime/runicast.h"
67 #include "net/packetqueue.h"
68 #include "sys/ctimer.h"
69 #include "lib/list.h"
70 
71 #define COLLECT_PACKET_ID_BITS 8
72 
73 #define COLLECT_ATTRIBUTES { PACKETBUF_ADDR_ESENDER, PACKETBUF_ADDRSIZE }, \
74  { PACKETBUF_ATTR_EPACKET_ID, PACKETBUF_ATTR_BIT * COLLECT_PACKET_ID_BITS }, \
75  { PACKETBUF_ATTR_PACKET_ID, PACKETBUF_ATTR_BIT * COLLECT_PACKET_ID_BITS }, \
76  { PACKETBUF_ATTR_TTL, PACKETBUF_ATTR_BIT * 4 }, \
77  { PACKETBUF_ATTR_HOPS, PACKETBUF_ATTR_BIT * 4 }, \
78  { PACKETBUF_ATTR_MAX_REXMIT, PACKETBUF_ATTR_BIT * 5 }, \
79  { PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_BIT }, \
80  UNICAST_ATTRIBUTES
81 
82 struct collect_callbacks {
83  void (* recv)(const rimeaddr_t *originator, uint8_t seqno,
84  uint8_t hops);
85 };
86 
87 /* COLLECT_CONF_ANNOUNCEMENTS defines if the Collect implementation
88  should use Contiki's announcement primitive to announce its routes
89  or if it should use periodic broadcasts. */
90 #ifndef COLLECT_CONF_ANNOUNCEMENTS
91 #define COLLECT_ANNOUNCEMENTS 1
92 #else
93 #define COLLECT_ANNOUNCEMENTS COLLECT_CONF_ANNOUNCEMENTS
94 #endif /* COLLECT_CONF_ANNOUNCEMENTS */
95 
96 struct collect_conn {
97  struct unicast_conn unicast_conn;
98 #if ! COLLECT_ANNOUNCEMENTS
99  struct neighbor_discovery_conn neighbor_discovery_conn;
100 #else /* ! COLLECT_ANNOUNCEMENTS */
101  struct announcement announcement;
102  struct ctimer transmit_after_scan_timer;
103 #endif /* COLLECT_ANNOUNCEMENTS */
104  const struct collect_callbacks *cb;
105  struct ctimer retransmission_timer;
106  LIST_STRUCT(send_queue_list);
107  struct packetqueue send_queue;
108  struct collect_neighbor_list neighbor_list;
109 
110  struct ctimer keepalive_timer;
111  clock_time_t keepalive_period;
112 
113  struct ctimer proactive_probing_timer;
114 
115  rimeaddr_t parent, current_parent;
116  uint16_t rtmetric;
117  uint8_t seqno;
118  uint8_t sending, transmissions, max_rexmits;
119  uint8_t eseqno;
120  uint8_t is_router;
121 
122  clock_time_t send_time;
123 };
124 
125 enum {
126  COLLECT_NO_ROUTER,
127  COLLECT_ROUTER,
128 };
129 
130 void collect_open(struct collect_conn *c, uint16_t channels,
131  uint8_t is_router,
132  const struct collect_callbacks *callbacks);
133 void collect_close(struct collect_conn *c);
134 
135 int collect_send(struct collect_conn *c, int rexmits);
136 
137 void collect_set_sink(struct collect_conn *c, int should_be_sink);
138 
139 int collect_depth(struct collect_conn *c);
140 const rimeaddr_t *collect_parent(struct collect_conn *c);
141 
142 void collect_set_keepalive(struct collect_conn *c, clock_time_t period);
143 
144 void collect_print_stats(void);
145 
146 #define COLLECT_MAX_DEPTH (COLLECT_LINK_ESTIMATE_UNIT * 64 - 1)
147 
148 #endif /* __COLLECT_H__ */
149 /** @} */
150 /** @} */