Contiki 2.5
ipolite.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimeipolite Ipolite best effort local broadcast
8  * @{
9  *
10  * The ipolite module sends one local area broadcast packet within one
11  * time interval. If a packet with the same header is received from a
12  * neighbor within the interval, the packet is not sent.
13  *
14  * The polite primitive is a generalization of the polite gossip
15  * algorithm from Trickle (Levis et al, NSDI 2004). The polite gossip
16  * algorithm is designed to reduce the total amount of packet
17  * transmissions by not repeating a message that other nodes have
18  * already sent. The purpose of the polite broadcast primitive is to
19  * avoid that multiple copies of a specific set of packet attributes
20  * is sent on a specified logical channel in the local neighborhood
21  * during a time interval.
22  *
23  * The polite broadcast primitive is useful for implementing broadcast
24  * protocols that use, e.g., negative acknowledgements. If many nodes
25  * need to send the negative acknowledgement to a sender, it is enough
26  * if only a single message is delivered to the sender.
27  *
28  * The upper layer protocol or application that uses the polite
29  * broadcast primitive provides an interval time, and message along
30  * with a list of packet attributes for which multiple copies should
31  * be avoided. The polite broadcast primitive stores the outgoing
32  * message in a queue buffer, stores the list of packet attributes,
33  * and sets up a timer. The timer is set to a random time during the
34  * second half of the interval time.
35  *
36  * During the first half of the time interval, the sender listens for
37  * other transmissions. If it hears a packet that matches the
38  * attributes provided by the upper layer protocol or application, the
39  * sender drops the packet. The send timer has been set to a random
40  * time some time during the second half of the interval. When the
41  * timer fires, and the sender has not yet heard a transmission of the
42  * same packet attributes, the sender broadcasts its packet to all its
43  * neighbors.
44  *
45  * The polite broadcast module does not add any packet attributes to
46  * outgoing packets apart from those added by the upper layer.
47  *
48  * \section channels Channels
49  *
50  * The ipolite module uses 1 channel.
51  *
52  */
53 
54 /*
55  * Copyright (c) 2007, Swedish Institute of Computer Science.
56  * All rights reserved.
57  *
58  * Redistribution and use in source and binary forms, with or without
59  * modification, are permitted provided that the following conditions
60  * are met:
61  * 1. Redistributions of source code must retain the above copyright
62  * notice, this list of conditions and the following disclaimer.
63  * 2. Redistributions in binary form must reproduce the above copyright
64  * notice, this list of conditions and the following disclaimer in the
65  * documentation and/or other materials provided with the distribution.
66  * 3. Neither the name of the Institute nor the names of its contributors
67  * may be used to endorse or promote products derived from this software
68  * without specific prior written permission.
69  *
70  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
71  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
74  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
75  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
76  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
77  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
78  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
79  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80  * SUCH DAMAGE.
81  *
82  * This file is part of the Contiki operating system.
83  *
84  * $Id: ipolite.h,v 1.12 2010/06/14 19:19:17 adamdunkels Exp $
85  */
86 
87 /**
88  * \file
89  * Header file for Ipolite best effort local Broadcast (ipolite)
90  * \author
91  * Adam Dunkels <adam@sics.se>
92  */
93 
94 #ifndef __IPOLITE_H__
95 #define __IPOLITE_H__
96 
97 #include "sys/ctimer.h"
98 
99 #include "net/rime/broadcast.h"
100 #include "net/queuebuf.h"
101 
102 struct ipolite_conn;
103 
104 #define IPOLITE_ATTRIBUTES IBC_ATTRIBUTES
105 
106 /**
107  * \brief A structure with callback functions for an ipolite connection.
108  *
109  * This structure holds a list of callback functions used
110  * a an ipolite connection. The functions are called when
111  * events occur on the connection.
112  *
113  */
115  /**
116  * Called when a packet is received on the connection.
117  */
118  void (* recv)(struct ipolite_conn *c, const rimeaddr_t *from);
119 
120  /**
121  * Called when a packet is sent on the connection.
122  */
123  void (* sent)(struct ipolite_conn *c);
124 
125  /**
126  * Called when a packet is dropped because a packet was heard from a
127  * neighbor.
128  */
129  void (* dropped)(struct ipolite_conn *c);
130 };
131 
132 /**
133  * An opaque structure with no user-visible elements that holds the
134  * state of an ipolite connection,
135  */
136 struct ipolite_conn {
137  struct broadcast_conn c;
138  const struct ipolite_callbacks *cb;
139  struct ctimer t;
140  struct queuebuf *q;
141  uint8_t hdrsize;
142  uint8_t maxdups;
143  uint8_t dups;
144 };
145 
146 
147 /**
148  * \brief Open an ipolite connection
149  * \param c A pointer to a struct ipolite_conn.
150  * \param channel The channel number to be used for this connection
151  * \param maxdups The number of duplicates that are allowed to be heard before suppressing
152  * \param cb A pointer to the callbacks used for this connection
153  *
154  * This function opens an ipolite connection on the
155  * specified channel. The callbacks are called when a
156  * packet is received, or when another event occurs on the
157  * connection (see \ref "struct ipolite_callbacks").
158  */
159 void ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t maxdups,
160  const struct ipolite_callbacks *cb);
161 
162 /**
163  * \brief Close an ipolite connection
164  * \param c A pointer to a struct ipolite_conn that has previously been opened with ipolite_open().
165  *
166  * This function closes an ipolite connection that has
167  * previously been opened with ipolite_open().
168  */
169 void ipolite_close(struct ipolite_conn *c);
170 
171 /**
172  * \brief Send a packet on an ipolite connection.
173  * \param c A pointer to a struct ipolite_conn that has previously been opened with ipolite_open().
174  * \param interval The timer interval in which the packet should be sent.
175  * \param hdrsize The size of the header that should be unique within the time interval.
176  *
177  * This function sends a packet from the packetbuf on the
178  * ipolite connection. The packet is sent some time during
179  * the time interval, but only if no other packet is
180  * received with the same header.
181  *
182  */
183 int ipolite_send(struct ipolite_conn *c, clock_time_t interval,
184  uint8_t hdrsize);
185 
186 /**
187  * \brief Cancel a pending packet
188  * \param c A pointer to a struct ipolite_conn that has previously been opened with ipolite_open().
189  *
190  * This function cancels a pending transmission that has
191  * previously been started with ipolite_send().
192  */
193 void ipolite_cancel(struct ipolite_conn *c);
194 
195 #endif /* __IPOLITE_H__ */
196 
197 /** @} */
198 /** @} */