blob: 414cc8a7d2b002b1e871df60e252444c11b02d28 [file] [log] [blame]
Klaus Schneider9e5122b2019-03-19 17:03:25 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2016-2019, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
6 *
7 * This file is part of ndn-tools (Named Data Networking Essential Tools).
8 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
9 *
10 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
22 *
23 * @author Klaus Schneider
24 */
25
26#include "pipeline-interests-cubic.hpp"
27
28#include <cmath>
29
30namespace ndn {
31namespace chunks {
32
33constexpr double CUBIC_C = 0.4;
34
35PipelineInterestsCubic::PipelineInterestsCubic(Face& face, RttEstimator& rttEstimator,
36 const Options& options)
37 : PipelineInterestsAdaptive(face, rttEstimator, options)
38 , m_cubicOptions(options)
39 , m_lastDecrease(time::steady_clock::now())
40{
41 if (options.isVerbose) {
42 std::cerr << options;
43 }
44}
45
46void
47PipelineInterestsCubic::increaseWindow()
48{
49 // Slow start phase
50 if (m_cwnd < m_ssthresh) {
51 m_cwnd += 1.0;
52 }
53 // Congestion avoidance phase
54 else {
55 // If wmax is still 0, set it to the current cwnd. Usually unnecessary,
56 // if m_ssthresh is large enough.
57 if (m_wmax < m_options.initCwnd) {
58 m_wmax = m_cwnd;
59 }
60
61 // 1. Time since last congestion event in seconds
62 const double t = (time::steady_clock::now() - m_lastDecrease).count() / 1e9;
63
64 // 2. Time it takes to increase the window to m_wmax = the cwnd right before the last
65 // window decrease.
66 // K = cubic_root(wmax*(1-beta_cubic)/C) (Eq. 2)
67 const double k = std::cbrt(m_wmax * (1 - m_cubicOptions.cubicBeta) / CUBIC_C);
68
69 // 3. Target: W_cubic(t) = C*(t-K)^3 + wmax (Eq. 1)
70 const double wCubic = CUBIC_C * std::pow(t - k, 3) + m_wmax;
71
72 // 4. Estimate of Reno Increase (Currently Disabled)
73 // const double rtt = m_rtt->GetCurrentEstimate().GetSeconds();
74 // const double w_est = wmax*m_beta + (3*(1-m_beta)/(1+m_beta)) * (t/rtt);
75 const double wEst = 0.0;
76
77 // Actual adaptation
78 double cubicIncrement = std::max(wCubic, wEst) - m_cwnd;
79 // Cubic increment must be positive
80 // Note: This change is not part of the RFC, but I added it to improve performance.
81 cubicIncrement = std::max(0.0, cubicIncrement);
82
83 m_cwnd += cubicIncrement / m_cwnd;
84 }
85
86 emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd);
87}
88
89void
90PipelineInterestsCubic::decreaseWindow()
91{
92 // A flow remembers the last value of wmax,
93 // before it updates wmax for the current congestion event.
94
95 // Current wmax < last_wmax
96 if (m_cubicOptions.enableFastConv && m_cwnd < m_lastWmax) {
97 m_lastWmax = m_cwnd;
98 m_wmax = m_cwnd * (1.0 + m_cubicOptions.cubicBeta) / 2.0;
99 }
100 else {
101 // Save old cwnd as wmax
102 m_lastWmax = m_cwnd;
103 m_wmax = m_cwnd;
104 }
105
106 m_ssthresh = std::max(m_options.initCwnd, m_cwnd * m_cubicOptions.cubicBeta);
107 m_cwnd = m_ssthresh;
108 m_lastDecrease = time::steady_clock::now();
109
110 emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd);
111}
112
113std::ostream&
114operator<<(std::ostream& os, const PipelineInterestsCubicOptions& options)
115{
116 os << static_cast<const PipelineInterestsAdaptiveOptions&>(options)
117 << "Cubic pipeline parameters:\n"
118 << "\tFast convergence = " << (options.enableFastConv ? "yes" : "no") << "\n"
119 << "\tCubic beta = " << options.cubicBeta << "\n";
120 return os;
121}
122
123} // namespace chunks
124} // namespace ndn