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