|
|
| 33 |
#include "ns3/integer.h" |
33 |
#include "ns3/integer.h" |
| 34 |
#include "ns3/uinteger.h" |
34 |
#include "ns3/uinteger.h" |
| 35 |
#include "ns3/log.h" |
35 |
#include "ns3/log.h" |
|
|
36 |
#include "ns3/packet.h" |
| 37 |
#include "ns3/tcp-header.h" |
| 38 |
#include "tcp-option-ts.h" |
| 36 |
|
39 |
|
| 37 |
namespace ns3 { |
40 |
namespace ns3 { |
| 38 |
|
41 |
|
|
Lines 107-113
RttHistory::RttHistory (const RttHistory& h)
|
Link Here
|
|---|
|
| 107 |
RttEstimator::RttEstimator () |
110 |
RttEstimator::RttEstimator () |
| 108 |
: m_next (1), m_history (), |
111 |
: m_next (1), m_history (), |
| 109 |
m_nSamples (0), |
112 |
m_nSamples (0), |
| 110 |
m_multiplier (1) |
113 |
m_multiplier (1), |
|
|
114 |
m_timestampEnabled (false) |
| 111 |
{ |
115 |
{ |
| 112 |
NS_LOG_FUNCTION (this); |
116 |
NS_LOG_FUNCTION (this); |
| 113 |
//note next=1 everywhere since first segment will have sequence 1 |
117 |
//note next=1 everywhere since first segment will have sequence 1 |
|
Lines 124-130
RttEstimator::RttEstimator (const RttEstimator& c)
|
Link Here
|
|---|
|
| 124 |
m_maxMultiplier (c.m_maxMultiplier), |
128 |
m_maxMultiplier (c.m_maxMultiplier), |
| 125 |
m_initialEstimatedRtt (c.m_initialEstimatedRtt), |
129 |
m_initialEstimatedRtt (c.m_initialEstimatedRtt), |
| 126 |
m_currentEstimatedRtt (c.m_currentEstimatedRtt), m_minRto (c.m_minRto), |
130 |
m_currentEstimatedRtt (c.m_currentEstimatedRtt), m_minRto (c.m_minRto), |
| 127 |
m_nSamples (c.m_nSamples), m_multiplier (c.m_multiplier) |
131 |
m_nSamples (c.m_nSamples), m_multiplier (c.m_multiplier), |
|
|
132 |
m_timestampEnabled (c.m_timestampEnabled) |
| 128 |
{ |
133 |
{ |
| 129 |
NS_LOG_FUNCTION (this); |
134 |
NS_LOG_FUNCTION (this); |
| 130 |
} |
135 |
} |
|
Lines 140-148
RttEstimator::GetInstanceTypeId (void) const
|
Link Here
|
|---|
|
| 140 |
return GetTypeId (); |
145 |
return GetTypeId (); |
| 141 |
} |
146 |
} |
| 142 |
|
147 |
|
| 143 |
void RttEstimator::SentSeq (SequenceNumber32 seq, uint32_t size) |
148 |
void RttEstimator::SentPkt (const TcpHeader &tcpHeader, uint32_t size) |
| 144 |
{ |
149 |
{ |
| 145 |
NS_LOG_FUNCTION (this << seq << size); |
150 |
NS_LOG_FUNCTION (this << tcpHeader); |
|
|
151 |
|
| 152 |
SequenceNumber32 seq = tcpHeader.GetSequenceNumber(); |
| 153 |
|
| 146 |
// Note that a particular sequence has been sent |
154 |
// Note that a particular sequence has been sent |
| 147 |
if (seq == m_next) |
155 |
if (seq == m_next) |
| 148 |
{ // This is the next expected one, just log at end |
156 |
{ // This is the next expected one, just log at end |
|
Lines 168-188
void RttEstimator::SentSeq (SequenceNumber32 seq, uint32_t size)
|
Link Here
|
|---|
|
| 168 |
} |
176 |
} |
| 169 |
} |
177 |
} |
| 170 |
|
178 |
|
| 171 |
Time RttEstimator::EstimateRttFromSeq (SequenceNumber32 ackSeq) |
179 |
Time |
|
|
180 |
RttEstimator::GetRttFor(const TcpHeader &tcpHeader) |
| 172 |
{ |
181 |
{ |
| 173 |
NS_LOG_FUNCTION (this << ackSeq); |
182 |
NS_LOG_FUNCTION (this << tcpHeader); |
| 174 |
// An ack has been received, calculate rtt and log this measurement |
183 |
|
| 175 |
// Note we use a linear search (O(n)) for this since for the common |
184 |
SequenceNumber32 ackSeq = tcpHeader.GetAckNumber(); |
| 176 |
// case the ack'ed packet will be at the head of the list |
185 |
|
| 177 |
Time m = Seconds (0.0); |
186 |
Time m = Time (0.0); |
| 178 |
if (m_history.size () == 0) return (m); // No pending history, just exit |
187 |
|
| 179 |
RttHistory& h = m_history.front (); |
188 |
if (m_timestampEnabled && tcpHeader.HasOption (TcpOption::TS)) |
| 180 |
if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count))) |
189 |
{ |
| 181 |
{ // Ok to use this sample |
190 |
Ptr<TcpOptionTS> ts; |
| 182 |
m = Simulator::Now () - h.time; // Elapsed time |
191 |
ts = DynamicCast<TcpOptionTS> (tcpHeader.GetOption (TcpOption::TS)); |
| 183 |
Measurement (m); // Log the measurement |
192 |
m = TcpOptionTS::ElapsedTimeFromTsValue (ts->GetEcho ()); |
| 184 |
ResetMultiplier (); // Reset multiplier on valid measurement |
|
|
| 185 |
} |
193 |
} |
|
|
194 |
else |
| 195 |
{ |
| 196 |
// An ack has been received, calculate rtt and log this measurement |
| 197 |
// Note we use a linear search (O(n)) for this since for the common |
| 198 |
// case the ack'ed packet will be at the head of the list |
| 199 |
if (m_history.size () == 0) return (m); // No pending history, just exit |
| 200 |
RttHistory& h = m_history.front (); |
| 201 |
if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count))) |
| 202 |
{ // Ok to use this sample |
| 203 |
m = Simulator::Now () - h.time; // Elapsed time |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 186 |
// Now delete all ack history with seq <= ack |
207 |
// Now delete all ack history with seq <= ack |
| 187 |
while(m_history.size () > 0) |
208 |
while(m_history.size () > 0) |
| 188 |
{ |
209 |
{ |
|
Lines 190-196
Time RttEstimator::EstimateRttFromSeq (SequenceNumber32 ackSeq)
|
Link Here
|
|---|
|
| 190 |
if ((h.seq + SequenceNumber32 (h.count)) > ackSeq) break; // Done removing |
211 |
if ((h.seq + SequenceNumber32 (h.count)) > ackSeq) break; // Done removing |
| 191 |
m_history.pop_front (); // Remove |
212 |
m_history.pop_front (); // Remove |
| 192 |
} |
213 |
} |
| 193 |
return m; |
214 |
|
|
|
215 |
if (! m.IsZero()) |
| 216 |
{ |
| 217 |
Measurement (m); // Log the measurement |
| 218 |
ResetMultiplier (); // Reset multiplier on valid measurement |
| 219 |
return m; |
| 220 |
} |
| 221 |
else |
| 222 |
{ |
| 223 |
return m_currentEstimatedRtt; |
| 224 |
} |
| 194 |
} |
225 |
} |
| 195 |
|
226 |
|
| 196 |
void RttEstimator::ClearSent () |
227 |
void RttEstimator::ClearSent () |
|
Lines 225-231
void RttEstimator::Reset ()
|
Link Here
|
|---|
|
| 225 |
ResetMultiplier (); |
256 |
ResetMultiplier (); |
| 226 |
} |
257 |
} |
| 227 |
|
258 |
|
| 228 |
|
259 |
void |
|
|
260 |
RttEstimator::SetTimestampEnabled (bool enabled) |
| 261 |
{ |
| 262 |
m_timestampEnabled = enabled; |
| 263 |
} |
| 229 |
|
264 |
|
| 230 |
//----------------------------------------------------------------------------- |
265 |
//----------------------------------------------------------------------------- |
| 231 |
//----------------------------------------------------------------------------- |
266 |
//----------------------------------------------------------------------------- |