Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 30 | namespace ndn { |
| 31 | namespace chunks { |
| 32 | |
| 33 | constexpr double CUBIC_C = 0.4; |
| 34 | |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame] | 35 | PipelineInterestsCubic::PipelineInterestsCubic(Face& face, RttEstimatorWithStats& rttEstimator, |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 36 | const Options& opts) |
| 37 | : PipelineInterestsAdaptive(face, rttEstimator, opts) |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 38 | , m_lastDecrease(time::steady_clock::now()) |
| 39 | { |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 40 | if (m_options.isVerbose) { |
| 41 | printOptions(); |
| 42 | std::cerr << "\tCubic beta = " << m_options.cubicBeta << "\n" |
| 43 | << "\tFast convergence = " << (m_options.enableFastConv ? "yes" : "no") << "\n"; |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | PipelineInterestsCubic::increaseWindow() |
| 49 | { |
| 50 | // Slow start phase |
| 51 | if (m_cwnd < m_ssthresh) { |
| 52 | m_cwnd += 1.0; |
| 53 | } |
| 54 | // Congestion avoidance phase |
| 55 | else { |
| 56 | // If wmax is still 0, set it to the current cwnd. Usually unnecessary, |
| 57 | // if m_ssthresh is large enough. |
| 58 | if (m_wmax < m_options.initCwnd) { |
| 59 | m_wmax = m_cwnd; |
| 60 | } |
| 61 | |
| 62 | // 1. Time since last congestion event in seconds |
| 63 | const double t = (time::steady_clock::now() - m_lastDecrease).count() / 1e9; |
| 64 | |
| 65 | // 2. Time it takes to increase the window to m_wmax = the cwnd right before the last |
| 66 | // window decrease. |
| 67 | // K = cubic_root(wmax*(1-beta_cubic)/C) (Eq. 2) |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 68 | const double k = std::cbrt(m_wmax * (1 - m_options.cubicBeta) / CUBIC_C); |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 69 | |
| 70 | // 3. Target: W_cubic(t) = C*(t-K)^3 + wmax (Eq. 1) |
| 71 | const double wCubic = CUBIC_C * std::pow(t - k, 3) + m_wmax; |
| 72 | |
Klaus Schneider | 4a2e89d | 2019-10-27 10:04:39 -0700 | [diff] [blame] | 73 | // 4. Estimate of Reno Increase (Eq. 4) |
| 74 | const double rtt = m_rttEstimator.getSmoothedRtt().count() / 1e9; |
| 75 | const double wEst = m_wmax * m_options.cubicBeta + |
| 76 | (3 * (1 - m_options.cubicBeta) / (1 + m_options.cubicBeta)) * (t / rtt); |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 77 | |
| 78 | // Actual adaptation |
| 79 | double cubicIncrement = std::max(wCubic, wEst) - m_cwnd; |
| 80 | // Cubic increment must be positive |
| 81 | // Note: This change is not part of the RFC, but I added it to improve performance. |
| 82 | cubicIncrement = std::max(0.0, cubicIncrement); |
| 83 | |
| 84 | m_cwnd += cubicIncrement / m_cwnd; |
| 85 | } |
| 86 | |
| 87 | emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | PipelineInterestsCubic::decreaseWindow() |
| 92 | { |
| 93 | // A flow remembers the last value of wmax, |
| 94 | // before it updates wmax for the current congestion event. |
| 95 | |
| 96 | // Current wmax < last_wmax |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 97 | if (m_options.enableFastConv && m_cwnd < m_lastWmax) { |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 98 | m_lastWmax = m_cwnd; |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 99 | m_wmax = m_cwnd * (1.0 + m_options.cubicBeta) / 2.0; |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 100 | } |
| 101 | else { |
| 102 | // Save old cwnd as wmax |
| 103 | m_lastWmax = m_cwnd; |
| 104 | m_wmax = m_cwnd; |
| 105 | } |
| 106 | |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 107 | m_ssthresh = std::max(m_options.initCwnd, m_cwnd * m_options.cubicBeta); |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 108 | m_cwnd = m_ssthresh; |
| 109 | m_lastDecrease = time::steady_clock::now(); |
| 110 | |
| 111 | emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd); |
| 112 | } |
| 113 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 114 | } // namespace chunks |
| 115 | } // namespace ndn |