blob: 4d84fdd574850a1e6b83da96c9e14770e6ee10cb [file] [log] [blame]
Klaus Schneider9e5122b2019-03-19 17:03:25 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventob3570c62022-02-19 19:19:00 -05003 * Copyright (c) 2016-2022, Regents of the University of California,
Klaus Schneider9e5122b2019-03-19 17:03:25 -07004 * 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 Shuo Yang
24 * @author Weiwei Liu
25 * @author Chavoosh Ghasemi
26 * @author Klaus Schneider
27 */
28
29#include "pipeline-interests-aimd.hpp"
30
31#include <cmath>
32
Davide Pesaventob3570c62022-02-19 19:19:00 -050033namespace ndn::chunks {
Klaus Schneider9e5122b2019-03-19 17:03:25 -070034
Davide Pesavento5e3773d2019-08-22 15:35:08 -040035PipelineInterestsAimd::PipelineInterestsAimd(Face& face, RttEstimatorWithStats& rttEstimator,
Davide Pesavento97a33b22019-10-17 22:10:47 -040036 const Options& opts)
37 : PipelineInterestsAdaptive(face, rttEstimator, opts)
Klaus Schneider9e5122b2019-03-19 17:03:25 -070038{
Davide Pesavento97a33b22019-10-17 22:10:47 -040039 if (m_options.isVerbose) {
40 printOptions();
Klaus Schneider9e5122b2019-03-19 17:03:25 -070041 }
42}
43
44void
45PipelineInterestsAimd::increaseWindow()
46{
47 if (m_cwnd < m_ssthresh) {
48 m_cwnd += m_options.aiStep; // additive increase
49 }
50 else {
51 m_cwnd += m_options.aiStep / std::floor(m_cwnd); // congestion avoidance
52 }
53
54 emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd);
55}
56
57void
58PipelineInterestsAimd::decreaseWindow()
59{
60 // please refer to RFC 5681, Section 3.1 for the rationale behind it
61 m_ssthresh = std::max(MIN_SSTHRESH, m_cwnd * m_options.mdCoef); // multiplicative decrease
62 m_cwnd = m_options.resetCwndToInit ? m_options.initCwnd : m_ssthresh;
63
64 emitSignal(afterCwndChange, time::steady_clock::now() - getStartTime(), m_cwnd);
65}
66
Davide Pesaventob3570c62022-02-19 19:19:00 -050067} // namespace ndn::chunks