NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2
/*
3
* Copyright (C) 2016-2018, Arizona Board of Regents.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*
21
* @author Shuo Yang
22
* @author Weiwei Liu
23
* @author Chavoosh Ghasemi
24
*/
25
26
#include "
ndn-cxx/util/rtt-estimator.hpp
"
27
28
#include <cmath>
29
#include <limits>
30
31
namespace
ndn
{
32
namespace
util {
33
34
RttEstimator::RttEstimator
(
const
Options
& options)
35
: m_options(options)
36
, m_sRtt(std::numeric_limits<double>::quiet_NaN())
37
, m_rttVar(std::numeric_limits<double>::quiet_NaN())
38
, m_rto(m_options.initialRto.count())
39
, m_rttMin(std::numeric_limits<double>::max())
40
, m_rttMax(std::numeric_limits<double>::min())
41
, m_rttAvg(0.0)
42
, m_nRttSamples(0)
43
{
44
}
45
46
void
47
RttEstimator::addMeasurement
(
MillisecondsDouble
rtt,
size_t
nExpectedSamples)
48
{
49
BOOST_ASSERT(nExpectedSamples > 0);
50
51
if
(m_nRttSamples == 0) {
// first measurement
52
m_sRtt = rtt;
53
m_rttVar = m_sRtt / 2;
54
m_rto = m_sRtt + m_options.
k
* m_rttVar;
55
}
56
else
{
57
double
alpha
= m_options.
alpha
/ nExpectedSamples;
58
double
beta = m_options.
beta
/ nExpectedSamples;
59
m_rttVar = (1 - beta) * m_rttVar + beta *
time::abs
(m_sRtt - rtt);
60
m_sRtt = (1 -
alpha
) * m_sRtt +
alpha
* rtt;
61
m_rto = m_sRtt + m_options.
k
* m_rttVar;
62
}
63
64
m_rto =
clamp
(m_rto, m_options.
minRto
, m_options.
maxRto
);
65
66
m_rttAvg =
MillisecondsDouble
((m_nRttSamples * m_rttAvg.count() + rtt.count()) / (m_nRttSamples + 1));
67
m_rttMax = std::max<MillisecondsDouble>(rtt, m_rttMax);
68
m_rttMin = std::min<MillisecondsDouble>(rtt, m_rttMin);
69
m_nRttSamples++;
70
}
71
72
void
73
RttEstimator::backoffRto
()
74
{
75
m_rto =
clamp
(m_rto * m_options.
rtoBackoffMultiplier
,
76
m_options.
minRto
, m_options.
maxRto
);
77
}
78
79
}
// namespace util
80
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::util::RttEstimator::Options::minRto
MillisecondsDouble minRto
lower bound of RTO
Definition:
rtt-estimator.hpp:60
ndn::util::RttEstimator::Options::alpha
double alpha
weight of exponential moving average for meanRtt
Definition:
rtt-estimator.hpp:56
ndn::util::RttEstimator::Options
Definition:
rtt-estimator.hpp:47
ndn::util::RttEstimator::Options::beta
double beta
weight of exponential moving average for varRtt
Definition:
rtt-estimator.hpp:57
ndn::clamp
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition:
backports.hpp:78
ns3::alpha
const double alpha
Definition:
l2-rate-tracer.cpp:142
rtt-estimator.hpp
ndn::time::abs
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
Definition:
time.hpp:50
ndn::util::RttEstimator::backoffRto
void backoffRto()
Backoff RTO by a factor of Options::rtoBackoffMultiplier.
Definition:
rtt-estimator.cpp:73
ndn::util::RttEstimator::RttEstimator
RttEstimator(const Options &options=Options())
Create a RTT Estimator.
Definition:
rtt-estimator.cpp:34
ndn::util::RttEstimator::addMeasurement
void addMeasurement(MillisecondsDouble rtt, size_t nExpectedSamples)
Add a new RTT measurement to the estimator.
Definition:
rtt-estimator.cpp:47
ndn::util::RttEstimator::Options::rtoBackoffMultiplier
int rtoBackoffMultiplier
Definition:
rtt-estimator.hpp:62
ndn::util::RttEstimator::Options::maxRto
MillisecondsDouble maxRto
upper bound of RTO
Definition:
rtt-estimator.hpp:61
ndn::util::RttEstimator::Options::k
int k
factor of RTT variation when calculating RTO
Definition:
rtt-estimator.hpp:58
ndn::util::RttEstimator::MillisecondsDouble
time::duration< double, time::milliseconds::period > MillisecondsDouble
Definition:
rtt-estimator.hpp:44
ndnSIM
ndn-cxx
ndn-cxx
util
rtt-estimator.cpp
Generated on Sun Feb 24 2019 22:16:07 for ndnSIM by
1.8.15