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  } else {
52  m_rtt = m;
53  m_variance = m;
54  }
55  ++m_nSamples;
56  m_multiplier = 1;
57 }
58 
59 void
61 {
62  m_multiplier = std::min(static_cast<uint16_t>(m_multiplier + 1), m_maxMultiplier);
63 }
64 
65 void
67 {
68  m_multiplier = std::min(static_cast<uint16_t>(m_multiplier * 2), m_maxMultiplier);
69 }
70 
73 {
74  double rto = std::max(m_minRto, m_rtt + 4 * m_variance);
75  rto *= m_multiplier;
76  return Duration(static_cast<Duration::rep>(rto));
77 }
78 
79 } // namespace nfd
Duration computeRto() const
time::microseconds Duration
RttEstimator(uint16_t maxMultiplier=16, Duration minRto=time::milliseconds(1), double gain=0.1)
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