Contiki 2.6
|
00001 /** 00002 * \addtogroup rime 00003 * @{ 00004 */ 00005 00006 /** 00007 * \defgroup rimecollect Tree-based hop-by-hop reliable data collection 00008 * @{ 00009 * 00010 * The collect module implements a hop-by-hop reliable data collection 00011 * mechanism. 00012 * 00013 * \section channels Channels 00014 * 00015 * The collect module uses 2 channels; one for neighbor discovery and one 00016 * for data packets. 00017 * 00018 */ 00019 00020 /* 00021 * Copyright (c) 2007, Swedish Institute of Computer Science. 00022 * All rights reserved. 00023 * 00024 * Redistribution and use in source and binary forms, with or without 00025 * modification, are permitted provided that the following conditions 00026 * are met: 00027 * 1. Redistributions of source code must retain the above copyright 00028 * notice, this list of conditions and the following disclaimer. 00029 * 2. Redistributions in binary form must reproduce the above copyright 00030 * notice, this list of conditions and the following disclaimer in the 00031 * documentation and/or other materials provided with the distribution. 00032 * 3. Neither the name of the Institute nor the names of its contributors 00033 * may be used to endorse or promote products derived from this software 00034 * without specific prior written permission. 00035 * 00036 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00037 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00038 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00039 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00040 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00041 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00042 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00043 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00044 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00045 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00046 * SUCH DAMAGE. 00047 * 00048 * This file is part of the Contiki operating system. 00049 * 00050 * $Id: collect.h,v 1.26 2011/01/09 23:48:33 adamdunkels Exp $ 00051 */ 00052 00053 /** 00054 * \file 00055 * Header file for hop-by-hop reliable data collection 00056 * \author 00057 * Adam Dunkels <adam@sics.se> 00058 */ 00059 00060 #ifndef __COLLECT_H__ 00061 #define __COLLECT_H__ 00062 00063 #include "net/rime/announcement.h" 00064 #include "net/rime/runicast.h" 00065 #include "net/rime/neighbor-discovery.h" 00066 #include "net/rime/collect-neighbor.h" 00067 #include "net/packetqueue.h" 00068 #include "sys/ctimer.h" 00069 #include "lib/list.h" 00070 00071 #define COLLECT_PACKET_ID_BITS 8 00072 00073 #define COLLECT_ATTRIBUTES { PACKETBUF_ADDR_ESENDER, PACKETBUF_ADDRSIZE }, \ 00074 { PACKETBUF_ATTR_EPACKET_ID, PACKETBUF_ATTR_BIT * COLLECT_PACKET_ID_BITS }, \ 00075 { PACKETBUF_ATTR_PACKET_ID, PACKETBUF_ATTR_BIT * COLLECT_PACKET_ID_BITS }, \ 00076 { PACKETBUF_ATTR_TTL, PACKETBUF_ATTR_BIT * 4 }, \ 00077 { PACKETBUF_ATTR_HOPS, PACKETBUF_ATTR_BIT * 4 }, \ 00078 { PACKETBUF_ATTR_MAX_REXMIT, PACKETBUF_ATTR_BIT * 5 }, \ 00079 { PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_BIT }, \ 00080 UNICAST_ATTRIBUTES 00081 00082 struct collect_callbacks { 00083 void (* recv)(const rimeaddr_t *originator, uint8_t seqno, 00084 uint8_t hops); 00085 }; 00086 00087 /* COLLECT_CONF_ANNOUNCEMENTS defines if the Collect implementation 00088 should use Contiki's announcement primitive to announce its routes 00089 or if it should use periodic broadcasts. */ 00090 #ifndef COLLECT_CONF_ANNOUNCEMENTS 00091 #define COLLECT_ANNOUNCEMENTS 1 00092 #else 00093 #define COLLECT_ANNOUNCEMENTS COLLECT_CONF_ANNOUNCEMENTS 00094 #endif /* COLLECT_CONF_ANNOUNCEMENTS */ 00095 00096 struct collect_conn { 00097 struct unicast_conn unicast_conn; 00098 #if ! COLLECT_ANNOUNCEMENTS 00099 struct neighbor_discovery_conn neighbor_discovery_conn; 00100 #else /* ! COLLECT_ANNOUNCEMENTS */ 00101 struct announcement announcement; 00102 struct ctimer transmit_after_scan_timer; 00103 #endif /* COLLECT_ANNOUNCEMENTS */ 00104 const struct collect_callbacks *cb; 00105 struct ctimer retransmission_timer; 00106 LIST_STRUCT(send_queue_list); 00107 struct packetqueue send_queue; 00108 struct collect_neighbor_list neighbor_list; 00109 00110 struct ctimer keepalive_timer; 00111 clock_time_t keepalive_period; 00112 00113 struct ctimer proactive_probing_timer; 00114 00115 rimeaddr_t parent, current_parent; 00116 uint16_t rtmetric; 00117 uint8_t seqno; 00118 uint8_t sending, transmissions, max_rexmits; 00119 uint8_t eseqno; 00120 uint8_t is_router; 00121 00122 clock_time_t send_time; 00123 }; 00124 00125 enum { 00126 COLLECT_NO_ROUTER, 00127 COLLECT_ROUTER, 00128 }; 00129 00130 void collect_open(struct collect_conn *c, uint16_t channels, 00131 uint8_t is_router, 00132 const struct collect_callbacks *callbacks); 00133 void collect_close(struct collect_conn *c); 00134 00135 int collect_send(struct collect_conn *c, int rexmits); 00136 00137 void collect_set_sink(struct collect_conn *c, int should_be_sink); 00138 00139 int collect_depth(struct collect_conn *c); 00140 const rimeaddr_t *collect_parent(struct collect_conn *c); 00141 00142 void collect_set_keepalive(struct collect_conn *c, clock_time_t period); 00143 00144 void collect_print_stats(void); 00145 00146 #define COLLECT_MAX_DEPTH (COLLECT_LINK_ESTIMATE_UNIT * 64 - 1) 00147 00148 #endif /* __COLLECT_H__ */ 00149 /** @} */ 00150 /** @} */