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-2019, 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
* @author Davide Pesavento
25
*/
26
27
#include "
ndn-cxx/util/rtt-estimator.hpp
"
28
29
namespace
ndn
{
30
namespace
util {
31
32
RttEstimator::RttEstimator
(shared_ptr<const Options> options)
33
: m_options(options ? std::
move
(options) : make_shared<const
Options
>())
34
, m_rto(m_options->initialRto)
35
{
36
BOOST_ASSERT(
m_options
->alpha >= 0 &&
m_options
->alpha <= 1);
37
BOOST_ASSERT(
m_options
->beta >= 0 &&
m_options
->beta <= 1);
38
BOOST_ASSERT(
m_options
->initialRto >= 0_ns);
39
BOOST_ASSERT(
m_options
->minRto >= 0_ns);
40
BOOST_ASSERT(
m_options
->maxRto >=
m_options
->minRto);
41
BOOST_ASSERT(
m_options
->k >= 0);
42
BOOST_ASSERT(
m_options
->rtoBackoffMultiplier >= 1);
43
}
44
45
void
46
RttEstimator::addMeasurement
(time::nanoseconds rtt,
size_t
nExpectedSamples)
47
{
48
BOOST_ASSERT(rtt >= 0_ns);
49
BOOST_ASSERT(nExpectedSamples > 0);
50
51
if
(!
hasSamples
()) {
// first measurement
52
m_sRtt = rtt;
53
m_rttVar = m_sRtt / 2;
54
}
55
else
{
56
double
alpha
=
m_options
->alpha / nExpectedSamples;
57
double
beta =
m_options
->beta / nExpectedSamples;
58
m_rttVar = time::duration_cast<time::nanoseconds>((1 - beta) * m_rttVar +
59
beta *
time::abs
(m_sRtt - rtt));
60
m_sRtt = time::duration_cast<time::nanoseconds>((1 -
alpha
) * m_sRtt +
alpha
* rtt);
61
}
62
m_rto =
clamp
(m_sRtt +
m_options
->k * m_rttVar,
63
m_options
->minRto,
m_options
->maxRto);
64
}
65
66
void
67
RttEstimator::backoffRto
()
68
{
69
m_rto =
clamp
(m_rto *
m_options
->rtoBackoffMultiplier,
70
m_options
->minRto,
m_options
->maxRto);
71
}
72
73
void
74
RttEstimatorWithStats::addMeasurement
(time::nanoseconds rtt,
size_t
nExpectedSamples)
75
{
76
RttEstimator::addMeasurement
(rtt, nExpectedSamples);
77
78
m_rttAvg = (m_nRttSamples * m_rttAvg + rtt) / (m_nRttSamples + 1);
79
m_rttMax = std::max(rtt, m_rttMax);
80
m_rttMin = std::min(rtt, m_rttMin);
81
m_nRttSamples++;
82
}
83
84
}
// namespace util
85
}
// namespace ndn
nonstd::optional_lite::std11::move
T & move(T &t)
Definition:
optional.hpp:421
ns3::alpha
const double alpha
Definition:
l2-rate-tracer.cpp:142
rtt-estimator.hpp
ndn::util::RttEstimatorWithStats::addMeasurement
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
Definition:
rtt-estimator.cpp:74
ndn::util::RttEstimator::RttEstimator
RttEstimator(shared_ptr< const Options > options=nullptr)
Constructor.
Definition:
rtt-estimator.cpp:32
ndn::util::RttEstimator::m_options
shared_ptr< const Options > m_options
Definition:
rtt-estimator.hpp:115
ndn::clamp
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition:
backports.hpp:117
ndn::util::RttEstimator::addMeasurement
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
Definition:
rtt-estimator.cpp:46
ndn::time::abs
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
Definition:
time.hpp:50
ndn::util::RttEstimator::Options
Definition:
rtt-estimator.hpp:45
ndn::util::RttEstimator::hasSamples
bool hasSamples() const
Definition:
rtt-estimator.hpp:74
ndn::util::RttEstimator::backoffRto
void backoffRto()
Backoff RTO by a factor of Options::rtoBackoffMultiplier.
Definition:
rtt-estimator.cpp:67
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndnSIM
ndn-cxx
ndn-cxx
util
rtt-estimator.cpp
Generated on Mon Jun 1 2020 22:32:15 for ndnSIM by
1.8.18