1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 // 3 // Copyright (c) 2006 Georgia Tech Research Corporation 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License version 2 as 7 // published by the Free Software Foundation; 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 // 18 // Author: Rajib Bhattacharjea<raj.b@gatech.edu> 19 // 20 21 // Georgia Tech Network Simulator - Round Trip Time Estimation Class 22 // George F. Riley. Georgia Tech, Spring 2002 23 24 25 #ifndef RTT_ESTIMATOR_H 26 #define RTT_ESTIMATOR_H 27 28 #include "ns3/nstime.h" 29 #include "ns3/object.h" 30 31 namespace ns3 { 32 33 /** 34 * \ingroup tcp 35 * 36 * \brief Base class for all RTT Estimators 37 * 38 * The RTT Estimator class computes an estimate of the round trip time 39 * observed in a series of Time measurements. The estimate is provided in 40 * the form of an estimate and a sample variation. Subclasses can implement 41 * different algorithms to provide values for the estimate and variation. 42 */ 43 class RttEstimator : public Object { 44 public: 45 /** 46 * \brief Get the type ID. 47 * \return the object TypeId 48 */ 49 static TypeId GetTypeId (void); 50 51 RttEstimator(); 52 /** 53 * \brief Copy constructor 54 * \param r the object to copy 55 */ 56 RttEstimator (const RttEstimator& r); 57 58 virtual ~RttEstimator(); 59 60 virtual TypeId GetInstanceTypeId (void) const; 61 62 /** 63 * \brief Add a new measurement to the estimator. Pure virtual function. 64 * \param t the new RTT measure. 65 */ 66 virtual void Measurement (Time t) = 0; 67 68 /** 69 * \brief Copy object (including current internal state) 70 * \returns a copy of itself 71 */ 72 virtual Ptr<RttEstimator> Copy () const = 0; 73 74 /** 75 * \brief Resets the estimation to its initial state. 76 */ 77 virtual void Reset (); 78 79 /** 80 * \brief gets the RTT estimate. 81 * \return The RTT estimate. 82 */ 83 Time GetEstimate (void) const; 84 85 /** 86 * Note that this is not a formal statistical variance; it has the 87 * the same units as the estimate. Mean deviation or standard deviation 88 * are example quantities that could be provided here. 89 * 90 * \brief gets the RTT estimate variation. 91 * \return The RTT estimate variation. 92 */ 93 Time GetVariation (void) const; 94 95 /** 96 * \brief gets the number of samples used in the estimates 97 * \return the number of samples used in the estimates 98 */ 99 uint32_t GetNSamples (void) const; 100 101 private: 102 Time m_initialEstimatedRtt; //!< Initial RTT estimation 103 104 protected: 105 Time m_estimatedRtt; //!< Current estimate 106 Time m_estimatedVariation; //!< Current estimate variation 107 uint32_t m_nSamples; //!< Number of samples 108 }; 109 110 /** 111 * \ingroup tcp 112 * 113 * \brief The "Mean--Deviation" RTT estimator, as discussed by Van Jacobson 114 * 115 * This class implements the "Mean--Deviation" RTT estimator, as discussed 116 * by Van Jacobson and Michael J. Karels, in 117 * "Congestion Avoidance and Control", SIGCOMM 88, Appendix A 118 * 119 * The default values for the gain (alpha and beta) are set as documented 120 * in RFC 6298. 121 * 122 */ 123 class RttMeanDeviation : public RttEstimator { 124 public: 125 /** 126 * \brief Get the type ID. 127 * \return the object TypeId 128 */ 129 static TypeId GetTypeId (void); 130 131 RttMeanDeviation (); 132 133 /** 134 * \brief Copy constructor 135 * \param r the object to copy 136 */ 137 RttMeanDeviation (const RttMeanDeviation& r); 138 139 virtual TypeId GetInstanceTypeId (void) const; 140 141 /** 142 * \brief Add a new measurement to the estimator. 143 * \param measure the new RTT measure. 144 */ 145 void Measurement (Time measure); 146 147 Ptr<RttEstimator> Copy () const; 148 149 /** 150 * \brief Resets the estimator. 151 */ 152 void Reset (); 153 154 private: 155 /** 156 * Utility function to check for possible conversion 157 * of a double value (0 < value < 1) to a reciprocal power of two 158 * 159 * Values of 1/32, 1/16, 1/8, 1/4, and 1/2 (i.e., within the possible 160 * range of experimentation for this estimator) are supported. 161 * 162 * \param val value to check 163 * \return log base 2 (1/val) if reciprocal power of 2, or zero if not 164 */ 165 uint32_t CheckForReciprocalPowerOfTwo (double val) const; 166 /** 167 * Method to update the rtt and variation estimates using integer 168 * arithmetic, used when the values of Alpha and Beta support the 169 * integer conversion. 170 * 171 * \param m time measurement 172 * \param rttShift value corresponding to log base 2 (1/alpha) 173 * \param variationShift value corresponding to log base 2 (1/beta) 174 */ 175 void IntegerUpdate (Time m, uint32_t rttShift, uint32_t variationShift); 176 /** 177 * Method to update the rtt and variation estimates using floating 178 * point arithmetic, used when the values of Alpha and Beta are not 179 * both a reciprocal power of two. 180 * 181 * \param m time measurement 182 */ 183 void FloatingPointUpdate (Time m); 184 double m_alpha; //!< Filter gain for average 185 double m_beta; //!< Filter gain for variation 186 187 }; 188 189 } // namespace ns3 190 191 #endif /* RTT_ESTIMATOR_H */ 192