View | Details | Raw Unified | Return to bug 2041
Collapse All | Expand All

(-)i/src/internet/model/rtt-estimator.cc (-19 / +54 lines)
 Lines 33-38    Link Here 
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
//-----------------------------------------------------------------------------
(-)i/src/internet/model/rtt-estimator.h (-2 / +10 lines)
 Lines 61-66   public: Link Here 
61
/// Container for RttHistory objects
61
/// Container for RttHistory objects
62
typedef std::deque<RttHistory> RttHistory_t;
62
typedef std::deque<RttHistory> RttHistory_t;
63
63
64
class Packet;
65
class TcpHeader;
66
64
/**
67
/**
65
 * \ingroup tcp
68
 * \ingroup tcp
66
 *
69
 *
 Lines 90-103   public: Link Here 
90
   * \param seq the packet sequence number.
93
   * \param seq the packet sequence number.
91
   * \param size the packet size.
94
   * \param size the packet size.
92
   */
95
   */
93
  virtual void SentSeq (SequenceNumber32 seq, uint32_t size);
96
  virtual void SentPkt (const TcpHeader &tcpHeader, uint32_t size);
94
97
95
  /**
98
  /**
96
   * \brief Note that a particular ack sequence has been received
99
   * \brief Note that a particular ack sequence has been received
97
   * \param ackSeq the ack sequence number.
100
   * \param ackSeq the ack sequence number.
98
   * \return The measured RTT for this ack.
101
   * \return The measured RTT for this ack.
99
   */
102
   */
100
  virtual Time EstimateRttFromSeq (SequenceNumber32 ackSeq);
103
  virtual Time GetRttFor (const TcpHeader &tcpHeader);
101
104
102
  /**
105
  /**
103
   * \brief Clear all history entries
106
   * \brief Clear all history entries
 Lines 161-166   public: Link Here 
161
   */
164
   */
162
  Time GetCurrentEstimate (void) const;
165
  Time GetCurrentEstimate (void) const;
163
166
167
  void SetTimestampEnabled (bool enabled);
168
164
private:
169
private:
165
  SequenceNumber32 m_next;    //!< Next expected sequence to be sent
170
  SequenceNumber32 m_next;    //!< Next expected sequence to be sent
166
  RttHistory_t m_history;     //!< List of sent packet
171
  RttHistory_t m_history;     //!< List of sent packet
 Lines 172-177   protected: Link Here 
172
  Time         m_minRto;                  //!< minimum value of the timeout
177
  Time         m_minRto;                  //!< minimum value of the timeout
173
  uint32_t     m_nSamples;                //!< Number of samples
178
  uint32_t     m_nSamples;                //!< Number of samples
174
  uint16_t     m_multiplier;              //!< RTO Multiplier
179
  uint16_t     m_multiplier;              //!< RTO Multiplier
180
181
private:
182
  bool m_timestampEnabled;
175
};
183
};
176
184
177
/**
185
/**
(-)i/src/internet/model/tcp-socket-base.cc (-17 / +10 lines)
 Lines 148-155   TcpSocketBase::TcpSocketBase (void) Link Here 
148
    m_sndScaleFactor (0),
148
    m_sndScaleFactor (0),
149
    m_rcvScaleFactor (0),
149
    m_rcvScaleFactor (0),
150
    m_timestampEnabled (true),
150
    m_timestampEnabled (true),
151
    m_timestampToEcho (0),
151
    m_timestampToEcho (0)
152
    m_lastEchoedTime (0)
153
152
154
{
153
{
155
  NS_LOG_FUNCTION (this);
154
  NS_LOG_FUNCTION (this);
 Lines 190-197   TcpSocketBase::TcpSocketBase (const TcpSocketBase& sock) Link Here 
190
    m_sndScaleFactor (sock.m_sndScaleFactor),
189
    m_sndScaleFactor (sock.m_sndScaleFactor),
191
    m_rcvScaleFactor (sock.m_rcvScaleFactor),
190
    m_rcvScaleFactor (sock.m_rcvScaleFactor),
192
    m_timestampEnabled (sock.m_timestampEnabled),
191
    m_timestampEnabled (sock.m_timestampEnabled),
193
    m_timestampToEcho (sock.m_timestampToEcho),
192
    m_timestampToEcho (sock.m_timestampToEcho)
194
    m_lastEchoedTime (sock.m_lastEchoedTime)
195
193
196
{
194
{
197
  NS_LOG_FUNCTION (this);
195
  NS_LOG_FUNCTION (this);
 Lines 1979-1985   TcpSocketBase::SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool with Link Here 
1979
      m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
1977
      m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
1980
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
1978
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
1981
    }
1979
    }
1982
  m_rtt->SentSeq (seq, sz);       // notify the RTT
1980
  m_rtt->SentPkt (header, sz);       // notify the RTT
1983
  // Notify the application of the data being sent unless this is a retransmit
1981
  // Notify the application of the data being sent unless this is a retransmit
1984
  if (seq == m_nextTxSequence)
1982
  if (seq == m_nextTxSequence)
1985
    {
1983
    {
 Lines 2157-2172   TcpSocketBase::EstimateRtt (const TcpHeader& tcpHeader) Link Here 
2157
{
2155
{
2158
  Time nextRtt;
2156
  Time nextRtt;
2159
2157
2160
  if (m_timestampEnabled)
2158
  // Use m_rtt for the estimation. Note, RTT of duplicated acknowledgement
2161
    {
2159
  // (which should be ignored) is handled by m_rtt.
2162
      nextRtt = TcpOptionTS::ElapsedTimeFromTsValue (m_lastEchoedTime);
2160
  nextRtt =  m_rtt->GetRttFor (tcpHeader);
2163
    }
2164
  else
2165
    {
2166
      // Use m_rtt for the estimation. Note, RTT of duplicated acknowledgement
2167
      // (which should be ignored) is handled by m_rtt.
2168
      nextRtt =  m_rtt->EstimateRttFromSeq (tcpHeader.GetAckNumber () );
2169
    }
2170
2161
2171
  //nextRtt will be zero for dup acks.  Don't want to update lastRtt in that case
2162
  //nextRtt will be zero for dup acks.  Don't want to update lastRtt in that case
2172
  //but still needed to do list clearing that is done in EstimateRttFromSeq.
2163
  //but still needed to do list clearing that is done in EstimateRttFromSeq.
 Lines 2526-2534   TcpSocketBase::ReadOptions (const TcpHeader& header) Link Here 
2526
    }
2517
    }
2527
2518
2528
  m_timestampEnabled = false;
2519
  m_timestampEnabled = false;
2520
  m_rtt->SetTimestampEnabled (false);
2521
2529
  if (header.HasOption (TcpOption::TS))
2522
  if (header.HasOption (TcpOption::TS))
2530
    {
2523
    {
2531
      m_timestampEnabled = true;
2524
      m_timestampEnabled = true;
2525
      m_rtt->SetTimestampEnabled (true);
2532
      ProcessOptionTimestamp (header.GetOption (TcpOption::TS));
2526
      ProcessOptionTimestamp (header.GetOption (TcpOption::TS));
2533
    }
2527
    }
2534
}
2528
}
 Lines 2622-2631   TcpSocketBase::ProcessOptionTimestamp (const Ptr<const TcpOption> option) Link Here 
2622
2616
2623
  Ptr<const TcpOptionTS> ts = DynamicCast<const TcpOptionTS> (option);
2617
  Ptr<const TcpOptionTS> ts = DynamicCast<const TcpOptionTS> (option);
2624
  m_timestampToEcho = ts->GetTimestamp ();
2618
  m_timestampToEcho = ts->GetTimestamp ();
2625
  m_lastEchoedTime = ts->GetEcho ();
2626
2619
2627
  NS_LOG_INFO (m_node->GetId () << " Got timestamp=" <<
2620
  NS_LOG_INFO (m_node->GetId () << " Got timestamp=" <<
2628
               m_timestampToEcho << " and Echo="     << m_lastEchoedTime);
2621
               m_timestampToEcho << " and Echo="     << ts->GetEcho ());
2629
}
2622
}
2630
2623
2631
void
2624
void
(-)i/src/internet/model/tcp-socket-base.h (-1 lines)
 Lines 667-673   protected: Link Here 
667
667
668
  bool     m_timestampEnabled;    //!< Timestamp option enabled
668
  bool     m_timestampEnabled;    //!< Timestamp option enabled
669
  uint32_t m_timestampToEcho;     //!< Timestamp to echo
669
  uint32_t m_timestampToEcho;     //!< Timestamp to echo
670
  uint32_t m_lastEchoedTime;      //!< Last echoed timestamp
671
};
670
};
672
671
673
} // namespace ns3
672
} // namespace ns3

Return to bug 2041