Contiki 2.5
netflood.h
Go to the documentation of this file.
1 /**
2  * \addtogroup rime
3  * @{
4  */
5 
6 /**
7  * \defgroup rimenetflood Best-effort network flooding
8  * @{
9  *
10  * The netflood module does best-effort flooding.
11  *
12  * The netflood primitive sends a single packet to all nodes in the
13  * network. The netflood primitive uses polite broadcasts at every hop
14  * to reduce the number of redundant transmissions. The netflood
15  * primitive does not perform retransmissions of flooded packets and
16  * packets are not tagged with version numbers. Instead, the netflood
17  * primitive sets the end-to-end sender and end-to-end packet ID
18  * attributes on the packets it sends. A forwarding node saves the
19  * end-to-end sender and packet ID of the last packet it forwards and
20  * does not forward a packet if it has the same end-to-end sender and
21  * packet ID as the last packet. This reduces the risk of routing
22  * loops, but does not eliminate them entirely as the netflood
23  * primitive saves the attributes of the latest packet seen only.
24  * Therefore, the netflood primitive also uses the time to live
25  * attribute, which is decreased by one before forwarding a packet.
26  * If the time to live reaches zero, the primitive does not forward
27  * the packet.
28 *
29  * \section channels Channels
30  *
31  * The netflood module uses 1 channel.
32  *
33  */
34 
35 /*
36  * Copyright (c) 2006, Swedish Institute of Computer Science.
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  * notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  * notice, this list of conditions and the following disclaimer in the
46  * documentation and/or other materials provided with the distribution.
47  * 3. Neither the name of the Institute nor the names of its contributors
48  * may be used to endorse or promote products derived from this software
49  * without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
55  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61  * SUCH DAMAGE.
62  *
63  * This file is part of the Contiki operating system.
64  *
65  * $Id: netflood.h,v 1.7 2010/06/14 19:19:17 adamdunkels Exp $
66  */
67 
68 /**
69  * \file
70  * Header file for the best-effort network flooding (netflood)
71  * \author
72  * Adam Dunkels <adam@sics.se>
73  */
74 
75 #ifndef __NETFLOOD_H__
76 #define __NETFLOOD_H__
77 
78 #include "net/queuebuf.h"
79 #include "net/rime/ipolite.h"
80 
81 struct netflood_conn;
82 
83 #define NETFLOOD_ATTRIBUTES { PACKETBUF_ADDR_ESENDER, PACKETBUF_ADDRSIZE }, \
84  { PACKETBUF_ATTR_HOPS, PACKETBUF_ATTR_BIT * 5 }, \
85  { PACKETBUF_ATTR_EPACKET_ID, PACKETBUF_ATTR_BIT * 4 }, \
86  IPOLITE_ATTRIBUTES
87 
88 struct netflood_callbacks {
89  int (* recv)(struct netflood_conn *c, const rimeaddr_t *from,
90  const rimeaddr_t *originator, uint8_t seqno, uint8_t hops);
91  void (* sent)(struct netflood_conn *c);
92  void (* dropped)(struct netflood_conn *c);
93 };
94 
95 struct netflood_conn {
96  struct ipolite_conn c;
97  const struct netflood_callbacks *u;
98  clock_time_t queue_time;
99  rimeaddr_t last_originator;
100  uint8_t last_originator_seqno;
101 };
102 
103 void netflood_open(struct netflood_conn *c, clock_time_t queue_time,
104  uint16_t channel, const struct netflood_callbacks *u);
105 void netflood_close(struct netflood_conn *c);
106 
107 int netflood_send(struct netflood_conn *c, uint8_t seqno);
108 
109 #endif /* __SIBC_H__ */
110 /** @} */
111 /** @} */