Contiki-NG
link-stats.h
1 /*
2  * Copyright (c) 2015, SICS Swedish ICT.
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  *
30  * Authors: Simon Duquennoy <simonduq@sics.se>
31  */
32 
33 #ifndef LINK_STATS_H_
34 #define LINK_STATS_H_
35 
36 #include "net/linkaddr.h"
37 
38 /* ETX fixed point divisor. 128 is the value used by RPL (RFC 6551 and RFC 6719) */
39 #ifdef LINK_STATS_CONF_ETX_DIVISOR
40 #define LINK_STATS_ETX_DIVISOR LINK_STATS_CONF_ETX_DIVISOR
41 #else /* LINK_STATS_CONF_ETX_DIVISOR */
42 #define LINK_STATS_ETX_DIVISOR 128
43 #endif /* LINK_STATS_CONF_ETX_DIVISOR */
44 
45 /* Option to infer the initial ETX from the RSSI of previously received packets. */
46 #ifdef LINK_STATS_CONF_INIT_ETX_FROM_RSSI
47 #define LINK_STATS_INIT_ETX_FROM_RSSI LINK_STATS_CONF_INIT_ETX_FROM_RSSI
48 #else /* LINK_STATS_CONF_INIT_ETX_FROM_RSSI */
49 #define LINK_STATS_INIT_ETX_FROM_RSSI 1
50 #endif /* LINK_STATS_CONF_INIT_ETX_FROM_RSSI */
51 
52 /* Option to use packet and ACK count for ETX estimation, instead of EWMA */
53 #ifdef LINK_STATS_CONF_ETX_FROM_PACKET_COUNT
54 #define LINK_STATS_ETX_FROM_PACKET_COUNT LINK_STATS_CONF_ETX_FROM_PACKET_COUNT
55 #else /* LINK_STATS_CONF_ETX_FROM_PACKET_COUNT */
56 #define LINK_STATS_ETX_FROM_PACKET_COUNT 0
57 #endif /* LINK_STATS_ETX_FROM_PACKET_COUNT */
58 
59 /* All statistics of a given link */
60 struct link_stats {
61  clock_time_t last_tx_time; /* Last Tx timestamp */
62  uint16_t etx; /* ETX using ETX_DIVISOR as fixed point divisor */
63  int16_t rssi; /* RSSI (received signal strength) */
64  uint8_t freshness; /* Freshness of the statistics */
65 #if LINK_STATS_ETX_FROM_PACKET_COUNT
66  uint8_t tx_count; /* Tx count, used for ETX calculation */
67  uint8_t ack_count; /* ACK count, used for ETX calculation */
68 #endif /* LINK_STATS_ETX_FROM_PACKET_COUNT */
69 };
70 
71 /* Returns the neighbor's link statistics */
72 const struct link_stats *link_stats_from_lladdr(const linkaddr_t *lladdr);
73 /* Are the statistics fresh? */
74 int link_stats_is_fresh(const struct link_stats *stats);
75 /* Resets link-stats module */
76 void link_stats_reset(void);
77 /* Initializes link-stats module */
78 void link_stats_init(void);
79 /* Packet sent callback. Updates statistics for transmissions on a given link */
80 void link_stats_packet_sent(const linkaddr_t *lladdr, int status, int numtx);
81 /* Packet input callback. Updates statistics for receptions on a given link */
82 void link_stats_input_callback(const linkaddr_t *lladdr);
83 
84 #endif /* LINK_STATS_H_ */
Header file for the link-layer address representation