blob: 58cc754d00de9e21a11a505f39f1e2ec06fead88 [file] [log] [blame]
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -08001/* -*- 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
34namespace ns3 {
35
36namespace ndn {
37
38/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070039 * \ingroup ndn-apps
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080040 *
41 * \brief Helper class to store RTT measurements
42 */
43class RttHistory {
44public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 RttHistory(SequenceNumber32 s, uint32_t c, Time t);
46 RttHistory(const RttHistory& h); // Copy constructor
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080047public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048 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 Afanasyevd9a7f192013-03-07 13:58:14 -080052};
53
54typedef std::deque<RttHistory> RttHistory_t;
55
56/**
57 * \ingroup tcp
58 *
59 * \brief Base class for all RTT Estimators
60 */
61class RttEstimator : public Object {
62public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 static TypeId
64 GetTypeId(void);
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080065
66 RttEstimator();
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 RttEstimator(const RttEstimator&);
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080068
69 virtual ~RttEstimator();
70
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 virtual TypeId
72 GetInstanceTypeId(void) const;
Yaogong Wang87cd0652013-05-28 11:00:45 -040073
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080074 /**
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 Afanasyevbe55cf62014-12-20 17:51:09 -080079 virtual void
80 SentSeq(SequenceNumber32 seq, uint32_t size);
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080081
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 Afanasyevbe55cf62014-12-20 17:51:09 -080087 virtual Time
88 AckSeq(SequenceNumber32 ackSeq);
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080089
90 /**
91 * \brief Clear all history entries
92 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 virtual void
94 ClearSent();
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080095
96 /**
97 * \brief Add a new measurement to the estimator. Pure virtual function.
98 * \param t the new RTT measure.
99 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 virtual void
101 Measurement(Time t) = 0;
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800102
103 /**
104 * \brief Returns the estimated RTO. Pure virtual function.
105 * \return the estimated RTO.
106 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 virtual Time
108 RetransmitTimeout() = 0;
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800109
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 virtual Ptr<RttEstimator>
111 Copy() const = 0;
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800112
113 /**
114 * \brief Increase the estimation multiplier up to MaxMultiplier.
115 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 virtual void
117 IncreaseMultiplier();
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800118
119 /**
120 * \brief Resets the estimation multiplier to 1.
121 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 virtual void
123 ResetMultiplier();
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800124
125 /**
126 * \brief Resets the estimation to its initial state.
127 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 virtual void
129 Reset();
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800130
131 /**
132 * \brief Sets the Minimum RTO.
133 * \param minRto The minimum RTO returned by the estimator.
134 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135 void
136 SetMinRto(Time minRto);
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800137
138 /**
139 * \brief Get the Minimum RTO.
140 * \return The minimum RTO returned by the estimator.
141 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800142 Time
143 GetMinRto(void) const;
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800144
145 /**
146 * \brief Sets the Maximum RTO.
147 * \param minRto The maximum RTO returned by the estimator.
148 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800149 void
150 SetMaxRto(Time maxRto);
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800151
152 /**
153 * \brief Get the Maximum RTO.
154 * \return The maximum RTO returned by the estimator.
155 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800156 Time
157 GetMaxRto(void) const;
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800158
159 /**
160 * \brief Sets the current RTT estimate (forcefully).
161 * \param estimate The current RTT estimate.
162 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800163 void
164 SetCurrentEstimate(Time estimate);
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800165
166 /**
167 * \brief gets the current RTT estimate.
168 * \return The current RTT estimate.
169 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800170 Time
171 GetCurrentEstimate(void) const;
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800172
173private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800174 SequenceNumber32 m_next; // Next expected sequence to be sent
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -0800175 uint16_t m_maxMultiplier;
176 Time m_initialEstimatedRtt;
177
178protected:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800179 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 Afanasyevd9a7f192013-03-07 13:58:14 -0800184 RttHistory_t m_history; // List of sent packet
185};
186
187} // namespace ndn
188
189} // namespace ns3
190
191#endif /* RTT_ESTIMATOR_H */