Contiki 3.x
collect-link-estimate.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 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  * Implementation of Collect link estimate based on ETX
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /**
41  * \addtogroup rimelinkestimate
42  * @{
43  */
44 
45 #include "net/rime/collect.h"
47 
48 #define INITIAL_LINK_ESTIMATE 16
49 
50 #define COLLECT_LINK_ESTIMATE_ALPHA ((3 * (COLLECT_LINK_ESTIMATE_UNIT)) / 8)
51 
52 #define MAX_ESTIMATES 255
53 
54 #define DEBUG 0
55 #if DEBUG
56 #include <stdio.h>
57 #define PRINTF(...) printf(__VA_ARGS__)
58 #else
59 #define PRINTF(...)
60 #endif
61 
62 /*---------------------------------------------------------------------------*/
63 void
65 {
66  if(le == NULL) {
67  return;
68  }
69  le->num_estimates = 0;
70  le->etx_accumulator = COLLECT_LINK_ESTIMATE_UNIT;
71 }
72 /*---------------------------------------------------------------------------*/
73 void
75 {
76  if(le == NULL) {
77  return;
78  }
79  if(tx == 0) {
80  /* printf("ERROR tx == 0\n");*/
81  return;
82  }
83  if(le != NULL) {
84  if(le->num_estimates == 0) {
85  le->etx_accumulator = tx * COLLECT_LINK_ESTIMATE_UNIT;
86  }
87 
88  if(le->num_estimates < MAX_ESTIMATES) {
89  le->num_estimates++;
90  }
91 
92  le->etx_accumulator = (((uint32_t)tx * COLLECT_LINK_ESTIMATE_UNIT) *
93  COLLECT_LINK_ESTIMATE_ALPHA +
94  le->etx_accumulator * (COLLECT_LINK_ESTIMATE_UNIT -
95  COLLECT_LINK_ESTIMATE_ALPHA)) /
96  COLLECT_LINK_ESTIMATE_UNIT;
97 
98  }
99 }
100 /*---------------------------------------------------------------------------*/
101 void
103  uint8_t tx)
104 {
105  if(le == NULL) {
106  return;
107  }
109 }
110 /*---------------------------------------------------------------------------*/
111 void
113 {
114 
115 }
116 /*---------------------------------------------------------------------------*/
117 uint16_t
119 {
120  if(le == NULL) {
121  return 0;
122  }
123  if(le->num_estimates == 0) {
124  return INITIAL_LINK_ESTIMATE * COLLECT_LINK_ESTIMATE_UNIT;
125  }
126 
127  return le->etx_accumulator;
128 }
129 /*---------------------------------------------------------------------------*/
130 int
131 collect_link_estimate_num_estimates(struct collect_link_estimate *le)
132 {
133  if(le != NULL) {
134  return le->num_estimates;
135  }
136  return 0;
137 }
138 /*---------------------------------------------------------------------------*/
139 /** @} */
void collect_link_estimate_update_tx(struct collect_link_estimate *le, uint8_t tx)
Update a link estimate when a packet has been sent.
Header file for hop-by-hop reliable data collection
#define NULL
The null pointer.
Header file for the Collect link estimate
void collect_link_estimate_new(struct collect_link_estimate *le)
Initialize a new link estimate.
void collect_link_estimate_update_rx(struct collect_link_estimate *n)
Update a link estimate when a packet has been received.
uint16_t collect_link_estimate(struct collect_link_estimate *le)
Compute the link estimate metric for a link estimate.
void collect_link_estimate_update_tx_fail(struct collect_link_estimate *le, uint8_t tx)
Update a link estimate when a packet has failed to be sent.