NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
rtt-estimator.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "rtt-estimator.hpp"
27 
28 namespace nfd {
29 
30 RttEstimator::RttEstimator(uint16_t maxMultiplier, Duration minRto, double gain)
31  : m_maxMultiplier(maxMultiplier)
32  , m_minRto(minRto.count())
33  , m_rtt(RttEstimator::getInitialRtt().count())
34  , m_gain(gain)
35  , m_variance(0)
36  , m_multiplier(1)
37  , m_nSamples(0)
38 {
39 }
40 
41 void
43 {
44  double m = static_cast<double>(measure.count());
45  if (m_nSamples > 0) {
46  double err = m - m_rtt;
47  double gErr = err * m_gain;
48  m_rtt += gErr;
49  double difference = std::abs(err) - m_variance;
50  m_variance += difference * m_gain;
51  }
52  else {
53  m_rtt = m;
54  m_variance = m;
55  }
56  ++m_nSamples;
57  m_multiplier = 1;
58 }
59 
60 void
62 {
63  m_multiplier = std::min(static_cast<uint16_t>(m_multiplier + 1), m_maxMultiplier);
64 }
65 
66 void
68 {
69  m_multiplier = std::min(static_cast<uint16_t>(m_multiplier * 2), m_maxMultiplier);
70 }
71 
74 {
75  double rto = std::max(m_minRto, m_rtt + 4 * m_variance);
76  rto *= m_multiplier;
77  return Duration(static_cast<Duration::rep>(rto));
78 }
79 
80 } // namespace nfd
time::microseconds Duration
RttEstimator(uint16_t maxMultiplier=16, Duration minRto=time::milliseconds(1), double gain=0.1)
Duration computeRto() const
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
Definition: time.hpp:53
void addMeasurement(Duration measure)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
implements the Mean-Deviation RTT estimator