Contiki 3.x
ipolite.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 Ipolite best effort local Broadcast (ipolite)
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rime
42  * @{
43  */
44 
45 /**
46  * \defgroup rimeipolite Ipolite best effort local broadcast
47  * @{
48  *
49  * The ipolite module sends one local area broadcast packet within one
50  * time interval. If a packet with the same header is received from a
51  * neighbor within the interval, the packet is not sent.
52  *
53  * The polite primitive is a generalization of the polite gossip
54  * algorithm from Trickle (Levis et al, NSDI 2004). The polite gossip
55  * algorithm is designed to reduce the total amount of packet
56  * transmissions by not repeating a message that other nodes have
57  * already sent. The purpose of the polite broadcast primitive is to
58  * avoid that multiple copies of a specific set of packet attributes
59  * is sent on a specified logical channel in the local neighborhood
60  * during a time interval.
61  *
62  * The polite broadcast primitive is useful for implementing broadcast
63  * protocols that use, e.g., negative acknowledgements. If many nodes
64  * need to send the negative acknowledgement to a sender, it is enough
65  * if only a single message is delivered to the sender.
66  *
67  * The upper layer protocol or application that uses the polite
68  * broadcast primitive provides an interval time, and message along
69  * with a list of packet attributes for which multiple copies should
70  * be avoided. The polite broadcast primitive stores the outgoing
71  * message in a queue buffer, stores the list of packet attributes,
72  * and sets up a timer. The timer is set to a random time during the
73  * second half of the interval time.
74  *
75  * During the first half of the time interval, the sender listens for
76  * other transmissions. If it hears a packet that matches the
77  * attributes provided by the upper layer protocol or application, the
78  * sender drops the packet. The send timer has been set to a random
79  * time some time during the second half of the interval. When the
80  * timer fires, and the sender has not yet heard a transmission of the
81  * same packet attributes, the sender broadcasts its packet to all its
82  * neighbors.
83  *
84  * The polite broadcast module does not add any packet attributes to
85  * outgoing packets apart from those added by the upper layer.
86  *
87  * \section channels Channels
88  *
89  * The ipolite module uses 1 channel.
90  *
91  */
92 
93 #ifndef IPOLITE_H_
94 #define IPOLITE_H_
95 
96 #include "sys/ctimer.h"
97 
98 #include "net/rime/broadcast.h"
99 #include "net/queuebuf.h"
100 
101 struct ipolite_conn;
102 
103 #define IPOLITE_ATTRIBUTES IBC_ATTRIBUTES
104 
105 /**
106  * \brief A structure with callback functions for an ipolite connection.
107  *
108  * This structure holds a list of callback functions used
109  * a an ipolite connection. The functions are called when
110  * events occur on the connection.
111  *
112  */
114  /**
115  * Called when a packet is received on the connection.
116  */
117  void (* recv)(struct ipolite_conn *c, const linkaddr_t *from);
118 
119  /**
120  * Called when a packet is sent on the connection.
121  */
122  void (* sent)(struct ipolite_conn *c);
123 
124  /**
125  * Called when a packet is dropped because a packet was heard from a
126  * neighbor.
127  */
128  void (* dropped)(struct ipolite_conn *c);
129 };
130 
131 /**
132  * An opaque structure with no user-visible elements that holds the
133  * state of an ipolite connection,
134  */
135 struct ipolite_conn {
136  struct broadcast_conn c;
137  const struct ipolite_callbacks *cb;
138  struct ctimer t;
139  struct queuebuf *q;
140  uint8_t hdrsize;
141  uint8_t maxdups;
142  uint8_t dups;
143 };
144 
145 
146 /**
147  * \brief Open an ipolite connection
148  * \param c A pointer to a struct ipolite_conn.
149  * \param channel The channel number to be used for this connection
150  * \param maxdups The number of duplicates that are allowed to be heard before suppressing
151  * \param cb A pointer to the callbacks used for this connection
152  *
153  * This function opens an ipolite connection on the
154  * specified channel. The callbacks are called when a
155  * packet is received, or when another event occurs on the
156  * connection (see \ref "struct ipolite_callbacks").
157  */
158 void ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t maxdups,
159  const struct ipolite_callbacks *cb);
160 
161 /**
162  * \brief Close an ipolite connection
163  * \param c A pointer to a struct ipolite_conn that has previously been opened with ipolite_open().
164  *
165  * This function closes an ipolite connection that has
166  * previously been opened with ipolite_open().
167  */
168 void ipolite_close(struct ipolite_conn *c);
169 
170 /**
171  * \brief Send a packet on an ipolite connection.
172  * \param c A pointer to a struct ipolite_conn that has previously been opened with ipolite_open().
173  * \param interval The timer interval in which the packet should be sent.
174  * \param hdrsize The size of the header that should be unique within the time interval.
175  *
176  * This function sends a packet from the packetbuf on the
177  * ipolite connection. The packet is sent some time during
178  * the time interval, but only if no other packet is
179  * received with the same header.
180  *
181  */
182 int ipolite_send(struct ipolite_conn *c, clock_time_t interval,
183  uint8_t hdrsize);
184 
185 /**
186  * \brief Cancel a pending packet
187  * \param c A pointer to a struct ipolite_conn that has previously been opened with ipolite_open().
188  *
189  * This function cancels a pending transmission that has
190  * previously been started with ipolite_send().
191  */
192 void ipolite_cancel(struct ipolite_conn *c);
193 
194 #endif /* IPOLITE_H_ */
195 
196 /** @} */
197 /** @} */
A structure with callback functions for an ipolite connection.
Definition: ipolite.h:113
void ipolite_cancel(struct ipolite_conn *c)
Cancel a pending packet.
Definition: ipolite.c:181
void(* recv)(struct ipolite_conn *c, const linkaddr_t *from)
Called when a packet is received on the connection.
Definition: ipolite.h:117
void ipolite_close(struct ipolite_conn *c)
Close an ipolite connection.
Definition: ipolite.c:133
void ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t dups, const struct ipolite_callbacks *cb)
Open an ipolite connection.
Definition: ipolite.c:123
void(* dropped)(struct ipolite_conn *c)
Called when a packet is dropped because a packet was heard from a neighbor.
Definition: ipolite.h:128
An opaque structure with no user-visible elements that holds the state of an ipolite connection...
Definition: ipolite.h:135
Header file for the Rime queue buffer management
Header file for the callback timer
Header file for identified best-effort local area broadcast
void(* sent)(struct ipolite_conn *c)
Called when a packet is sent on the connection.
Definition: ipolite.h:122
int ipolite_send(struct ipolite_conn *c, clock_time_t interval, uint8_t hdrsize)
Send a packet on an ipolite connection.
Definition: ipolite.c:144