Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 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 | // THIS IS A COPY OF rtt-estimator.h from internet module with minor modifications |
| 25 | |
| 26 | #ifndef NDN_RTT_ESTIMATOR_H |
| 27 | #define NDN_RTT_ESTIMATOR_H |
| 28 | |
| 29 | #include <deque> |
| 30 | #include "ns3/sequence-number.h" |
| 31 | #include "ns3/nstime.h" |
| 32 | #include "ns3/object.h" |
| 33 | |
| 34 | namespace ns3 { |
| 35 | |
| 36 | namespace ndn { |
| 37 | |
| 38 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 39 | * \ingroup ndn-apps |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 40 | * |
| 41 | * \brief Helper class to store RTT measurements |
| 42 | */ |
| 43 | class RttHistory { |
| 44 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | RttHistory(SequenceNumber32 s, uint32_t c, Time t); |
| 46 | RttHistory(const RttHistory& h); // Copy constructor |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 47 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 48 | SequenceNumber32 seq; // First sequence number in packet sent |
| 49 | uint32_t count; // Number of bytes sent |
| 50 | Time time; // Time this one was sent |
| 51 | bool retx; // True if this has been retransmitted |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | typedef std::deque<RttHistory> RttHistory_t; |
| 55 | |
| 56 | /** |
| 57 | * \ingroup tcp |
| 58 | * |
| 59 | * \brief Base class for all RTT Estimators |
| 60 | */ |
| 61 | class RttEstimator : public Object { |
| 62 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 63 | static TypeId |
| 64 | GetTypeId(void); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 65 | |
| 66 | RttEstimator(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | RttEstimator(const RttEstimator&); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 68 | |
| 69 | virtual ~RttEstimator(); |
| 70 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | virtual TypeId |
| 72 | GetInstanceTypeId(void) const; |
Yaogong Wang | 87cd065 | 2013-05-28 11:00:45 -0400 | [diff] [blame] | 73 | |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 74 | /** |
| 75 | * \brief Note that a particular sequence has been sent |
| 76 | * \param seq the packet sequence number. |
| 77 | * \param size the packet size. |
| 78 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | virtual void |
| 80 | SentSeq(SequenceNumber32 seq, uint32_t size); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * \brief Note that a particular ack sequence has been received |
| 84 | * \param ackSeq the ack sequence number. |
| 85 | * \return The measured RTT for this ack. |
| 86 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | virtual Time |
| 88 | AckSeq(SequenceNumber32 ackSeq); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * \brief Clear all history entries |
| 92 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 93 | virtual void |
| 94 | ClearSent(); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * \brief Add a new measurement to the estimator. Pure virtual function. |
| 98 | * \param t the new RTT measure. |
| 99 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | virtual void |
| 101 | Measurement(Time t) = 0; |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * \brief Returns the estimated RTO. Pure virtual function. |
| 105 | * \return the estimated RTO. |
| 106 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | virtual Time |
| 108 | RetransmitTimeout() = 0; |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 109 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | virtual Ptr<RttEstimator> |
| 111 | Copy() const = 0; |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * \brief Increase the estimation multiplier up to MaxMultiplier. |
| 115 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 116 | virtual void |
| 117 | IncreaseMultiplier(); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * \brief Resets the estimation multiplier to 1. |
| 121 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 122 | virtual void |
| 123 | ResetMultiplier(); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * \brief Resets the estimation to its initial state. |
| 127 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | virtual void |
| 129 | Reset(); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * \brief Sets the Minimum RTO. |
| 133 | * \param minRto The minimum RTO returned by the estimator. |
| 134 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 135 | void |
| 136 | SetMinRto(Time minRto); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * \brief Get the Minimum RTO. |
| 140 | * \return The minimum RTO returned by the estimator. |
| 141 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 142 | Time |
| 143 | GetMinRto(void) const; |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * \brief Sets the Maximum RTO. |
| 147 | * \param minRto The maximum RTO returned by the estimator. |
| 148 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 149 | void |
| 150 | SetMaxRto(Time maxRto); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * \brief Get the Maximum RTO. |
| 154 | * \return The maximum RTO returned by the estimator. |
| 155 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 156 | Time |
| 157 | GetMaxRto(void) const; |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * \brief Sets the current RTT estimate (forcefully). |
| 161 | * \param estimate The current RTT estimate. |
| 162 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 163 | void |
| 164 | SetCurrentEstimate(Time estimate); |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * \brief gets the current RTT estimate. |
| 168 | * \return The current RTT estimate. |
| 169 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 170 | Time |
| 171 | GetCurrentEstimate(void) const; |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 172 | |
| 173 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 174 | SequenceNumber32 m_next; // Next expected sequence to be sent |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 175 | uint16_t m_maxMultiplier; |
| 176 | Time m_initialEstimatedRtt; |
| 177 | |
| 178 | protected: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 179 | Time m_currentEstimatedRtt; // Current estimate |
| 180 | Time m_minRto; // minimum value of the timeout |
| 181 | Time m_maxRto; // maximum value of the timeout |
| 182 | uint32_t m_nSamples; // Number of samples |
| 183 | uint16_t m_multiplier; // RTO Multiplier |
Alexander Afanasyev | d9a7f19 | 2013-03-07 13:58:14 -0800 | [diff] [blame] | 184 | RttHistory_t m_history; // List of sent packet |
| 185 | }; |
| 186 | |
| 187 | } // namespace ndn |
| 188 | |
| 189 | } // namespace ns3 |
| 190 | |
| 191 | #endif /* RTT_ESTIMATOR_H */ |