Contiki-Inga 3.x
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  */
66 
67 /**
68  * \file
69  * Header file for the best-effort network flooding (netflood)
70  * \author
71  * Adam Dunkels <adam@sics.se>
72  */
73 
74 #ifndef NETFLOOD_H_
75 #define NETFLOOD_H_
76 
77 #include "net/queuebuf.h"
78 #include "net/rime/ipolite.h"
79 
80 struct netflood_conn;
81 
82 #define NETFLOOD_ATTRIBUTES { PACKETBUF_ADDR_ESENDER, PACKETBUF_ADDRSIZE }, \
83  { PACKETBUF_ATTR_HOPS, PACKETBUF_ATTR_BIT * 5 }, \
84  { PACKETBUF_ATTR_EPACKET_ID, PACKETBUF_ATTR_BIT * 4 }, \
85  IPOLITE_ATTRIBUTES
86 
87 struct netflood_callbacks {
88  int (* recv)(struct netflood_conn *c, const linkaddr_t *from,
89  const linkaddr_t *originator, uint8_t seqno, uint8_t hops);
90  void (* sent)(struct netflood_conn *c);
91  void (* dropped)(struct netflood_conn *c);
92 };
93 
94 struct netflood_conn {
95  struct ipolite_conn c;
96  const struct netflood_callbacks *u;
97  clock_time_t queue_time;
98  linkaddr_t last_originator;
99  uint8_t last_originator_seqno;
100 };
101 
102 void netflood_open(struct netflood_conn *c, clock_time_t queue_time,
103  uint16_t channel, const struct netflood_callbacks *u);
104 void netflood_close(struct netflood_conn *c);
105 
106 int netflood_send(struct netflood_conn *c, uint8_t seqno);
107 
108 #endif /* SIBC_H_ */
109 /** @} */
110 /** @} */