rtt.h revision 1.1.1.2 1 1.1 christos /*
2 1.1 christos * util/rtt.h - UDP round trip time estimator for resend timeouts.
3 1.1 christos *
4 1.1 christos * Copyright (c) 2007, NLnet Labs. All rights reserved.
5 1.1 christos *
6 1.1 christos * This software is open source.
7 1.1 christos *
8 1.1 christos * Redistribution and use in source and binary forms, with or without
9 1.1 christos * modification, are permitted provided that the following conditions
10 1.1 christos * are met:
11 1.1 christos *
12 1.1 christos * Redistributions of source code must retain the above copyright notice,
13 1.1 christos * this list of conditions and the following disclaimer.
14 1.1 christos *
15 1.1 christos * Redistributions in binary form must reproduce the above copyright notice,
16 1.1 christos * this list of conditions and the following disclaimer in the documentation
17 1.1 christos * and/or other materials provided with the distribution.
18 1.1 christos *
19 1.1 christos * Neither the name of the NLNET LABS nor the names of its contributors may
20 1.1 christos * be used to endorse or promote products derived from this software without
21 1.1 christos * specific prior written permission.
22 1.1 christos *
23 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 1.1 christos * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 1.1 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 1.1 christos * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 1.1 christos * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 1.1 christos * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 1.1 christos * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 1.1 christos * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1 christos */
35 1.1 christos
36 1.1 christos /**
37 1.1 christos * \file
38 1.1 christos *
39 1.1 christos * This file contains a data type and functions to help estimate good
40 1.1 christos * round trip times for UDP resend timeout values.
41 1.1 christos */
42 1.1 christos
43 1.1 christos #ifndef UTIL_RTT_H
44 1.1 christos #define UTIL_RTT_H
45 1.1 christos
46 1.1 christos /**
47 1.1 christos * RTT information. Keeps packet Round Trip Time.
48 1.1 christos */
49 1.1 christos struct rtt_info {
50 1.1 christos /** smoothed rtt estimator, in milliseconds */
51 1.1 christos int srtt;
52 1.1 christos /** smoothed mean deviation, in milliseconds */
53 1.1 christos int rttvar;
54 1.1 christos /** current RTO in use, in milliseconds */
55 1.1 christos int rto;
56 1.1 christos };
57 1.1 christos
58 1.1 christos /** min retransmit timeout value, in milliseconds */
59 1.1 christos extern int RTT_MIN_TIMEOUT;
60 1.1 christos /** max retransmit timeout value, in milliseconds */
61 1.1.1.2 christos extern int RTT_MAX_TIMEOUT;
62 1.1 christos
63 1.1 christos /**
64 1.1 christos * Initialize RTT estimators.
65 1.1 christos * @param rtt: The structure. Caller is responsible for allocation of it.
66 1.1 christos */
67 1.1 christos void rtt_init(struct rtt_info* rtt);
68 1.1 christos
69 1.1 christos /**
70 1.1 christos * Get timeout to use for sending a UDP packet.
71 1.1 christos * @param rtt: round trip statistics structure.
72 1.1 christos * @return: timeout to use in milliseconds. Relative time value.
73 1.1 christos */
74 1.1 christos int rtt_timeout(const struct rtt_info* rtt);
75 1.1 christos
76 1.1 christos /**
77 1.1 christos * Get unclamped timeout to use for server selection.
78 1.1 christos * Recent timeouts are reflected in the returned value.
79 1.1 christos * @param rtt: round trip statistics structure.
80 1.1 christos * @return: value to use in milliseconds.
81 1.1 christos */
82 1.1 christos int rtt_unclamped(const struct rtt_info* rtt);
83 1.1 christos
84 1.1 christos /**
85 1.1 christos * RTT for valid responses. Without timeouts.
86 1.1 christos * @param rtt: round trip statistics structure.
87 1.1 christos * @return: value in msec.
88 1.1 christos */
89 1.1 christos int rtt_notimeout(const struct rtt_info* rtt);
90 1.1 christos
91 1.1 christos /**
92 1.1 christos * Update the statistics with a new roundtrip estimate observation.
93 1.1 christos * @param rtt: round trip statistics structure.
94 1.1 christos * @param ms: estimate of roundtrip time in milliseconds.
95 1.1 christos */
96 1.1 christos void rtt_update(struct rtt_info* rtt, int ms);
97 1.1 christos
98 1.1 christos /**
99 1.1 christos * Update the statistics with a new timeout expired observation.
100 1.1 christos * @param rtt: round trip statistics structure.
101 1.1 christos * @param orig: original rtt time given for the query that timed out.
102 1.1 christos * Used to calculate the maximum responsible backed off time that
103 1.1 christos * can reasonably be applied.
104 1.1 christos */
105 1.1 christos void rtt_lost(struct rtt_info* rtt, int orig);
106 1.1 christos
107 1.1 christos #endif /* UTIL_RTT_H */
108