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