src/internet/model/rtt-estimator.cc
author Tom Henderson <tomh@tomh.org>
Wed, 30 May 2012 10:38:47 -0700
changeset 8830 e3e89a0ccb7d
parent 7817 f0fc223f89ff
child 9698 9d91a3c643b2
permissions -rw-r--r--
bug 1399: TCP not backing off retransmissions properly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     2
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     4
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     7
// published by the Free Software Foundation;
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     8
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    12
// GNU General Public License for more details.
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    13
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    17
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    18
// Author: Rajib Bhattacharjea<raj.b@gatech.edu>
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    19
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    20
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    21
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    22
// Ported from:
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    23
// Georgia Tech Network Simulator - Round Trip Time Estimation Class
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    24
// George F. Riley.  Georgia Tech, Spring 2002
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    25
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    26
// Implements several variations of round trip time estimators
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    27
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    28
#include <iostream>
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    29
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    30
#include "rtt-estimator.h"
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    31
#include "ns3/simulator.h"
2556
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    32
#include "ns3/double.h"
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    33
#include "ns3/integer.h"
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
    34
#include "ns3/uinteger.h"
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
    35
#include "ns3/log.h"
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
    36
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
    37
NS_LOG_COMPONENT_DEFINE ("RttEstimator");
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    38
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7126
diff changeset
    39
namespace ns3 {
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    40
2255
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
    41
NS_OBJECT_ENSURE_REGISTERED (RttEstimator);
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
    42
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
    43
TypeId 
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
    44
RttEstimator::GetTypeId (void)
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
    45
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2556
diff changeset
    46
  static TypeId tid = TypeId ("ns3::RttEstimator")
2556
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    47
    .SetParent<Object> ()
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    48
    .AddAttribute ("MaxMultiplier", 
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    49
                   "Maximum RTO Multiplier",
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
    50
                   UintegerValue (64),
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
    51
                   MakeUintegerAccessor (&RttEstimator::m_maxMultiplier),
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
    52
                   MakeUintegerChecker<uint16_t> ())
2556
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    53
    .AddAttribute ("InitialEstimation", 
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    54
                   "Initial RTT estimation",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2608
diff changeset
    55
                   TimeValue (Seconds (1.0)),
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    56
                   MakeTimeAccessor (&RttEstimator::m_initialEstimatedRtt),
2556
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    57
                   MakeTimeChecker ())
4023
d320dea20aca Add a minimum RTO (adapted from Mathieu, bug 418)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    58
    .AddAttribute ("MinRTO", 
d320dea20aca Add a minimum RTO (adapted from Mathieu, bug 418)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    59
                   "Minimum retransmit timeout value",
7619
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7256
diff changeset
    60
                   TimeValue (Seconds (0.2)), // RFC2988 says min RTO=1 sec, but Linux uses 200ms. See http://www.postel.org/pipermail/end2end-interest/2004-November/004402.html
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    61
                   MakeTimeAccessor (&RttEstimator::SetMinRto,
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    62
                                     &RttEstimator::GetMinRto),
4023
d320dea20aca Add a minimum RTO (adapted from Mathieu, bug 418)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    63
                   MakeTimeChecker ())
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7126
diff changeset
    64
  ;
2255
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
    65
  return tid;
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
    66
}
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    67
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    68
void 
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    69
RttEstimator::SetMinRto (Time minRto)
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    70
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
    71
  NS_LOG_FUNCTION (this << minRto);
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    72
  m_minRto = minRto;
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    73
}
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    74
Time 
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    75
RttEstimator::GetMinRto (void) const
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    76
{
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
    77
  return m_minRto;
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    78
}
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    79
void 
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    80
RttEstimator::SetCurrentEstimate (Time estimate)
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    81
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
    82
  NS_LOG_FUNCTION (this << estimate);
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    83
  m_currentEstimatedRtt = estimate;
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    84
}
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    85
Time 
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
    86
RttEstimator::GetCurrentEstimate (void) const
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    87
{
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
    88
  return m_currentEstimatedRtt;
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    89
}
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    90
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
    91
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    92
//RttHistory methods
6434
ac8b4bf77e50 Bug 385 - Add a generic "sequence number" class.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4023
diff changeset
    93
RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    94
  : seq (s), count (c), time (t), retx (false)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7126
diff changeset
    95
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
    96
  NS_LOG_FUNCTION (this);
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7126
diff changeset
    97
}
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    98
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    99
RttHistory::RttHistory (const RttHistory& h)
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   100
  : seq (h.seq), count (h.count), time (h.time), retx (h.retx)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7126
diff changeset
   101
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   102
  NS_LOG_FUNCTION (this);
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7126
diff changeset
   103
}
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   104
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   105
// Base class methods
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   106
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   107
RttEstimator::RttEstimator ()
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   108
  : m_next (1), m_history (),
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   109
    m_nSamples (0),
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   110
    m_multiplier (1)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   111
{ 
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   112
  NS_LOG_FUNCTION (this);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   113
  //note next=1 everywhere since first segment will have sequence 1
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   114
  
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   115
  // We need attributes initialized here, not later, so use the 
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   116
  // ConstructSelf() technique documented in the manual
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   117
  ObjectBase::ConstructSelf (AttributeConstructionList ());
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   118
  m_currentEstimatedRtt = m_initialEstimatedRtt;
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   119
  NS_LOG_DEBUG ("Initialize m_currentEstimatedRtt to " << m_currentEstimatedRtt.GetSeconds () << " sec.");
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   120
}
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   121
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   122
RttEstimator::RttEstimator (const RttEstimator& c)
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   123
  : Object (c), m_next (c.m_next), m_history (c.m_history), 
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   124
    m_maxMultiplier (c.m_maxMultiplier), 
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   125
    m_initialEstimatedRtt (c.m_initialEstimatedRtt),
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   126
    m_currentEstimatedRtt (c.m_currentEstimatedRtt), m_minRto (c.m_minRto),
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   127
    m_nSamples (c.m_nSamples), m_multiplier (c.m_multiplier)
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   128
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   129
  NS_LOG_FUNCTION (this);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   130
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   131
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   132
RttEstimator::~RttEstimator ()
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   133
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   134
  NS_LOG_FUNCTION (this);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   135
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   136
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   137
void RttEstimator::SentSeq (SequenceNumber32 seq, uint32_t size)
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   138
{ 
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   139
  NS_LOG_FUNCTION (this << seq << size);
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   140
  // Note that a particular sequence has been sent
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   141
  if (seq == m_next)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   142
    { // This is the next expected one, just log at end
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   143
      m_history.push_back (RttHistory (seq, size, Simulator::Now () ));
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   144
      m_next = seq + SequenceNumber32 (size); // Update next expected
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   145
    }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   146
  else
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   147
    { // This is a retransmit, find in list and mark as re-tx
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   148
      for (RttHistory_t::iterator i = m_history.begin (); i != m_history.end (); ++i)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   149
        {
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   150
          if ((seq >= i->seq) && (seq < (i->seq + SequenceNumber32 (i->count))))
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   151
            { // Found it
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   152
              i->retx = true;
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   153
              // One final test..be sure this re-tx does not extend "next"
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   154
              if ((seq + SequenceNumber32 (size)) > m_next)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   155
                {
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   156
                  m_next = seq + SequenceNumber32 (size);
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   157
                  i->count = ((seq + SequenceNumber32 (size)) - i->seq); // And update count in hist
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   158
                }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   159
              break;
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   160
            }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   161
        }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   162
    }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   163
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   164
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   165
Time RttEstimator::AckSeq (SequenceNumber32 ackSeq)
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   166
{ 
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   167
  NS_LOG_FUNCTION (this << ackSeq);
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   168
  // An ack has been received, calculate rtt and log this measurement
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   169
  // Note we use a linear search (O(n)) for this since for the common
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   170
  // case the ack'ed packet will be at the head of the list
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   171
  Time m = Seconds (0.0);
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   172
  if (m_history.size () == 0) return (m);    // No pending history, just exit
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   173
  RttHistory& h = m_history.front ();
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   174
  if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count)))
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   175
    { // Ok to use this sample
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   176
      m = Simulator::Now () - h.time; // Elapsed time
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   177
      Measurement (m);                // Log the measurement
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   178
      ResetMultiplier ();             // Reset multiplier on valid measurement
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   179
    }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   180
  // Now delete all ack history with seq <= ack
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   181
  while(m_history.size () > 0)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   182
    {
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   183
      RttHistory& h = m_history.front ();
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   184
      if ((h.seq + SequenceNumber32 (h.count)) > ackSeq) break;               // Done removing
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   185
      m_history.pop_front (); // Remove
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   186
    }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   187
  return m;
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   188
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   189
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   190
void RttEstimator::ClearSent ()
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   191
{ 
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   192
  NS_LOG_FUNCTION (this);
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   193
  // Clear all history entries
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   194
  m_next = 1;
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   195
  m_history.clear ();
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   196
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   197
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   198
void RttEstimator::IncreaseMultiplier ()
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   199
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   200
  NS_LOG_FUNCTION (this);
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   201
  m_multiplier = (m_multiplier*2 < m_maxMultiplier) ? m_multiplier*2 : m_maxMultiplier;
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   202
  NS_LOG_DEBUG ("Multiplier increased to " << m_multiplier);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   203
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   204
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   205
void RttEstimator::ResetMultiplier ()
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   206
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   207
  NS_LOG_FUNCTION (this);
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   208
  m_multiplier = 1;
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   209
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   210
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   211
void RttEstimator::Reset ()
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   212
{ 
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   213
  NS_LOG_FUNCTION (this);
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   214
  // Reset to initial state
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   215
  m_next = 1;
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   216
  m_currentEstimatedRtt = m_initialEstimatedRtt;
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   217
  m_history.clear ();         // Remove all info from the history
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   218
  m_nSamples = 0;
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   219
  ResetMultiplier ();
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   220
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   221
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   222
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   223
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   224
//-----------------------------------------------------------------------------
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   225
//-----------------------------------------------------------------------------
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   226
// Mean-Deviation Estimator
2255
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   227
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   228
NS_OBJECT_ENSURE_REGISTERED (RttMeanDeviation);
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   229
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   230
TypeId 
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   231
RttMeanDeviation::GetTypeId (void)
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   232
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2556
diff changeset
   233
  static TypeId tid = TypeId ("ns3::RttMeanDeviation")
2255
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   234
    .SetParent<RttEstimator> ()
2556
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   235
    .AddConstructor<RttMeanDeviation> ()
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   236
    .AddAttribute ("Gain",
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   237
                   "Gain used in estimating the RTT, must be 0 < Gain < 1",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2608
diff changeset
   238
                   DoubleValue (0.1),
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   239
                   MakeDoubleAccessor (&RttMeanDeviation::m_gain),
2556
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   240
                   MakeDoubleChecker<double> ())
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7126
diff changeset
   241
  ;
2255
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   242
  return tid;
ac534291636f merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2224
diff changeset
   243
}
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   244
2556
b13dd6239954 get rid of DefaultValue usage in internet-node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   245
RttMeanDeviation::RttMeanDeviation() :
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   246
  m_variance (0) 
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   247
{ 
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   248
  NS_LOG_FUNCTION (this);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   249
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   250
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   251
RttMeanDeviation::RttMeanDeviation (const RttMeanDeviation& c)
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   252
  : RttEstimator (c), m_gain (c.m_gain), m_variance (c.m_variance)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   253
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   254
  NS_LOG_FUNCTION (this);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   255
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   256
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   257
void RttMeanDeviation::Measurement (Time m)
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   258
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   259
  NS_LOG_FUNCTION (this << m);
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   260
  if (m_nSamples)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   261
    { // Not first
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   262
      Time err (m - m_currentEstimatedRtt);
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   263
      double gErr = err.ToDouble (Time::S) * m_gain;
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   264
      m_currentEstimatedRtt += Time::FromDouble (gErr, Time::S);
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   265
      Time difference = Abs (err) - m_variance;
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   266
      NS_LOG_DEBUG ("m_variance += " << Time::FromDouble (difference.ToDouble (Time::S) * m_gain, Time::S));
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   267
      m_variance += Time::FromDouble (difference.ToDouble (Time::S) * m_gain, Time::S);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   268
    }
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   269
  else
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   270
    { // First sample
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   271
      m_currentEstimatedRtt = m;             // Set estimate to current
7040
444bb5c76bff get rid of Scalar and co.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6434
diff changeset
   272
      //variance = sample / 2;               // And variance to current / 2
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   273
      m_variance = m; // try this
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   274
      NS_LOG_DEBUG ("(first sample) m_variance += " << m);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   275
    }
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   276
  m_nSamples++;
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   277
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   278
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   279
Time RttMeanDeviation::RetransmitTimeout ()
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   280
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   281
  NS_LOG_FUNCTION (this);
8830
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   282
  NS_LOG_DEBUG ("RetransmitTimeout:  var " << m_variance.GetSeconds () << " est " << m_currentEstimatedRtt.GetSeconds () << " multiplier " << m_multiplier);
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   283
  // RTO = srtt + 4* rttvar
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   284
  int64_t temp = m_currentEstimatedRtt.ToInteger (Time::MS) + 4 * m_variance.ToInteger (Time::MS);
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   285
  if (temp < m_minRto.ToInteger (Time::MS))
4023
d320dea20aca Add a minimum RTO (adapted from Mathieu, bug 418)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
   286
    {
8830
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   287
      temp = m_minRto.ToInteger (Time::MS);
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   288
    } 
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   289
  temp = temp * m_multiplier; // Apply backoff
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   290
  Time retval = Time::FromInteger (temp, Time::MS);
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   291
  NS_LOG_DEBUG ("RetransmitTimeout:  return " << retval.GetSeconds ());
e3e89a0ccb7d bug 1399: TCP not backing off retransmissions properly
Tom Henderson <tomh@tomh.org>
parents: 7817
diff changeset
   292
  return (retval);  
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   293
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   294
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   295
Ptr<RttEstimator> RttMeanDeviation::Copy () const
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   296
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   297
  NS_LOG_FUNCTION (this);
2925
7149e19cada4 use CopyObject and not Create to copy RttMeanDeviation. Implement the copy constructor correctly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2608
diff changeset
   298
  return CopyObject<RttMeanDeviation> (this);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   299
}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   300
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   301
void RttMeanDeviation::Reset ()
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   302
{ 
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   303
  NS_LOG_FUNCTION (this);
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   304
  // Reset to initial state
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   305
  m_variance = Seconds (0);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   306
  RttEstimator::Reset ();
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   307
}
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   308
void RttMeanDeviation::Gain (double g)
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   309
{
7817
f0fc223f89ff add logging to RttEstimator classes
Tom Henderson <tomh@tomh.org>
parents: 7816
diff changeset
   310
  NS_LOG_FUNCTION (this);
7776
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   311
  NS_ASSERT_MSG( (g > 0) && (g < 1), "RttMeanDeviation: Gain must be less than 1 and greater than 0" );
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   312
  m_gain = g;
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   313
}
19174ba45009 Bug 1351 (1333) - RttEstimator class bugfix, documentation improvements and code cleanup
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7619
diff changeset
   314
7816
6c1a7055aeba additional cleanup of RttEstimator class
Tom Henderson <tomh@tomh.org>
parents: 7776
diff changeset
   315
} //namespace ns3