blob: 287452e43ba84d52698dc31892418690767741a6 [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/**
39 * \ingroup tcp
40 *
41 * \brief Helper class to store RTT measurements
42 */
43class RttHistory {
44public:
45 RttHistory (SequenceNumber32 s, uint32_t c, Time t);
46 RttHistory (const RttHistory& h); // Copy constructor
47public:
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
52};
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:
63 static TypeId GetTypeId (void);
64
65 RttEstimator();
66 RttEstimator (const RttEstimator&);
67
68 virtual ~RttEstimator();
69
Yaogong Wang87cd0652013-05-28 11:00:45 -040070 virtual TypeId GetInstanceTypeId (void) const;
71
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080072 /**
73 * \brief Note that a particular sequence has been sent
74 * \param seq the packet sequence number.
75 * \param size the packet size.
76 */
77 virtual void SentSeq (SequenceNumber32 seq, uint32_t size);
78
79 /**
80 * \brief Note that a particular ack sequence has been received
81 * \param ackSeq the ack sequence number.
82 * \return The measured RTT for this ack.
83 */
84 virtual Time AckSeq (SequenceNumber32 ackSeq);
85
86 /**
87 * \brief Clear all history entries
88 */
89 virtual void ClearSent ();
90
91 /**
92 * \brief Add a new measurement to the estimator. Pure virtual function.
93 * \param t the new RTT measure.
94 */
95 virtual void Measurement (Time t) = 0;
96
97 /**
98 * \brief Returns the estimated RTO. Pure virtual function.
99 * \return the estimated RTO.
100 */
101 virtual Time RetransmitTimeout () = 0;
102
103 virtual Ptr<RttEstimator> Copy () const = 0;
104
105 /**
106 * \brief Increase the estimation multiplier up to MaxMultiplier.
107 */
108 virtual void IncreaseMultiplier ();
109
110 /**
111 * \brief Resets the estimation multiplier to 1.
112 */
113 virtual void ResetMultiplier ();
114
115 /**
116 * \brief Resets the estimation to its initial state.
117 */
118 virtual void Reset ();
119
120 /**
121 * \brief Sets the Minimum RTO.
122 * \param minRto The minimum RTO returned by the estimator.
123 */
124 void SetMinRto (Time minRto);
125
126 /**
127 * \brief Get the Minimum RTO.
128 * \return The minimum RTO returned by the estimator.
129 */
130 Time GetMinRto (void) const;
131
132 /**
133 * \brief Sets the Maximum RTO.
134 * \param minRto The maximum RTO returned by the estimator.
135 */
136 void SetMaxRto (Time maxRto);
137
138 /**
139 * \brief Get the Maximum RTO.
140 * \return The maximum RTO returned by the estimator.
141 */
142 Time GetMaxRto (void) const;
143
144 /**
145 * \brief Sets the current RTT estimate (forcefully).
146 * \param estimate The current RTT estimate.
147 */
148 void SetCurrentEstimate (Time estimate);
149
150 /**
151 * \brief gets the current RTT estimate.
152 * \return The current RTT estimate.
153 */
154 Time GetCurrentEstimate (void) const;
155
156private:
157 SequenceNumber32 m_next; // Next expected sequence to be sent
158 uint16_t m_maxMultiplier;
159 Time m_initialEstimatedRtt;
160
161protected:
162 Time m_currentEstimatedRtt; // Current estimate
163 Time m_minRto; // minimum value of the timeout
164 Time m_maxRto; // maximum value of the timeout
165 uint32_t m_nSamples; // Number of samples
166 uint16_t m_multiplier; // RTO Multiplier
167 RttHistory_t m_history; // List of sent packet
168};
169
170} // namespace ndn
171
172} // namespace ns3
173
174#endif /* RTT_ESTIMATOR_H */