blob: 6d8cdcb61a866e78ee4e3d0408db7d4336f192c9 [file] [log] [blame]
Junxiao Shi73b909a2015-02-08 21:31:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande90015992017-07-11 17:25:48 -05002/*
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi73b909a2015-02-08 21:31:42 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "retx-suppression-exponential.hpp"
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040027#include "algorithm.hpp"
Junxiao Shi73b909a2015-02-08 21:31:42 -070028
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040029namespace nfd::fw {
Junxiao Shi73b909a2015-02-08 21:31:42 -070030
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040031namespace {
32
33class PitInfo final : public StrategyInfo
Junxiao Shi73b909a2015-02-08 21:31:42 -070034{
35public:
36 static constexpr int
37 getTypeId()
38 {
39 return 1020;
40 }
41
42 explicit
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040043 PitInfo(const RetxSuppressionExponential::Duration& initialInterval)
Junxiao Shi73b909a2015-02-08 21:31:42 -070044 : suppressionInterval(initialInterval)
45 {
46 }
47
48public:
49 /** \brief if last transmission occurred within suppressionInterval,
50 * retransmission will be suppressed
51 */
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040052 RetxSuppressionExponential::Duration suppressionInterval;
Junxiao Shi73b909a2015-02-08 21:31:42 -070053};
54
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040055} // namespace
56
57RetxSuppressionExponential::RetxSuppressionExponential(Duration initialInterval,
58 Duration maxInterval,
59 float multiplier)
Junxiao Shi73b909a2015-02-08 21:31:42 -070060 : m_initialInterval(initialInterval)
Junxiao Shi73b909a2015-02-08 21:31:42 -070061 , m_maxInterval(maxInterval)
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040062 , m_multiplier(multiplier)
Junxiao Shi73b909a2015-02-08 21:31:42 -070063{
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040064 if (m_initialInterval <= 0_ns) {
65 NDN_THROW(std::invalid_argument("Retx suppression initial interval must be > 0"));
66 }
67 if (m_maxInterval < m_initialInterval) {
68 NDN_THROW(std::invalid_argument("Retx suppression max interval must be >= initial interval"));
69 }
70 if (m_multiplier < 1.0f) {
71 NDN_THROW(std::invalid_argument("Retx suppression multiplier must be >= 1"));
72 }
Junxiao Shi73b909a2015-02-08 21:31:42 -070073}
74
Ashlesh Gawande90015992017-07-11 17:25:48 -050075RetxSuppressionResult
76RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry)
Junxiao Shi73b909a2015-02-08 21:31:42 -070077{
Junxiao Shifef73e42016-03-29 14:15:05 -070078 bool isNewPitEntry = !hasPendingOutRecords(pitEntry);
Junxiao Shi73b909a2015-02-08 21:31:42 -070079 if (isNewPitEntry) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050080 return RetxSuppressionResult::NEW;
Junxiao Shi73b909a2015-02-08 21:31:42 -070081 }
82
Davide Pesaventoe4b22382018-06-10 14:37:24 -040083 auto lastOutgoing = getLastOutgoing(pitEntry);
84 auto now = time::steady_clock::now();
85 auto sinceLastOutgoing = now - lastOutgoing;
Junxiao Shi73b909a2015-02-08 21:31:42 -070086
Junxiao Shifc021862016-08-25 21:51:18 +000087 PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
Junxiao Shi73b909a2015-02-08 21:31:42 -070088 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
89
90 if (shouldSuppress) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050091 return RetxSuppressionResult::SUPPRESS;
Junxiao Shi73b909a2015-02-08 21:31:42 -070092 }
93
94 pi->suppressionInterval = std::min(m_maxInterval,
Ashlesh Gawande90015992017-07-11 17:25:48 -050095 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
96
97 return RetxSuppressionResult::FORWARD;
98}
99
100RetxSuppressionResult
101RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace)
102{
103 // NEW if outRecord for the face does not exist
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000104 auto outRecord = pitEntry.getOutRecord(outFace);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500105 if (outRecord == pitEntry.out_end()) {
106 return RetxSuppressionResult::NEW;
107 }
108
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400109 auto lastOutgoing = outRecord->getLastRenewed();
110 auto now = time::steady_clock::now();
111 auto sinceLastOutgoing = now - lastOutgoing;
Ashlesh Gawande90015992017-07-11 17:25:48 -0500112
113 // insertStrategyInfo does not insert m_initialInterval again if it already exists
114 PitInfo* pi = outRecord->insertStrategyInfo<PitInfo>(m_initialInterval).first;
115 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
116
117 if (shouldSuppress) {
118 return RetxSuppressionResult::SUPPRESS;
119 }
120
121 return RetxSuppressionResult::FORWARD;
122}
123
124void
125RetxSuppressionExponential::incrementIntervalForOutRecord(pit::OutRecord& outRecord)
126{
127 PitInfo* pi = outRecord.insertStrategyInfo<PitInfo>(m_initialInterval).first;
128 pi->suppressionInterval = std::min(m_maxInterval,
129 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
Junxiao Shi73b909a2015-02-08 21:31:42 -0700130}
131
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400132std::unique_ptr<RetxSuppressionExponential>
133RetxSuppressionExponential::construct(const StrategyParameters& params)
134{
135 auto init = params.getOrDefault<Duration::rep>("retx-suppression-initial",
136 RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL.count());
137 auto max = params.getOrDefault<Duration::rep>("retx-suppression-max",
138 RetxSuppressionExponential::DEFAULT_MAX_INTERVAL.count());
139 auto mult = params.getOrDefault<float>("retx-suppression-multiplier",
140 RetxSuppressionExponential::DEFAULT_MULTIPLIER);
141
142 return make_unique<RetxSuppressionExponential>(Duration(init), Duration(max), mult);
143}
144
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400145} // namespace nfd::fw