blob: 6158120eae84eeb69aa943b19bb68a8418c61289 [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
29namespace nfd {
30namespace fw {
31
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040032namespace {
33
34class PitInfo final : public StrategyInfo
Junxiao Shi73b909a2015-02-08 21:31:42 -070035{
36public:
37 static constexpr int
38 getTypeId()
39 {
40 return 1020;
41 }
42
43 explicit
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040044 PitInfo(const RetxSuppressionExponential::Duration& initialInterval)
Junxiao Shi73b909a2015-02-08 21:31:42 -070045 : suppressionInterval(initialInterval)
46 {
47 }
48
49public:
50 /** \brief if last transmission occurred within suppressionInterval,
51 * retransmission will be suppressed
52 */
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040053 RetxSuppressionExponential::Duration suppressionInterval;
Junxiao Shi73b909a2015-02-08 21:31:42 -070054};
55
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040056} // namespace
57
58RetxSuppressionExponential::RetxSuppressionExponential(Duration initialInterval,
59 Duration maxInterval,
60 float multiplier)
Junxiao Shi73b909a2015-02-08 21:31:42 -070061 : m_initialInterval(initialInterval)
Junxiao Shi73b909a2015-02-08 21:31:42 -070062 , m_maxInterval(maxInterval)
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040063 , m_multiplier(multiplier)
Junxiao Shi73b909a2015-02-08 21:31:42 -070064{
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040065 if (m_initialInterval <= 0_ns) {
66 NDN_THROW(std::invalid_argument("Retx suppression initial interval must be > 0"));
67 }
68 if (m_maxInterval < m_initialInterval) {
69 NDN_THROW(std::invalid_argument("Retx suppression max interval must be >= initial interval"));
70 }
71 if (m_multiplier < 1.0f) {
72 NDN_THROW(std::invalid_argument("Retx suppression multiplier must be >= 1"));
73 }
Junxiao Shi73b909a2015-02-08 21:31:42 -070074}
75
Ashlesh Gawande90015992017-07-11 17:25:48 -050076RetxSuppressionResult
77RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry)
Junxiao Shi73b909a2015-02-08 21:31:42 -070078{
Junxiao Shifef73e42016-03-29 14:15:05 -070079 bool isNewPitEntry = !hasPendingOutRecords(pitEntry);
Junxiao Shi73b909a2015-02-08 21:31:42 -070080 if (isNewPitEntry) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050081 return RetxSuppressionResult::NEW;
Junxiao Shi73b909a2015-02-08 21:31:42 -070082 }
83
Davide Pesaventoe4b22382018-06-10 14:37:24 -040084 auto lastOutgoing = getLastOutgoing(pitEntry);
85 auto now = time::steady_clock::now();
86 auto sinceLastOutgoing = now - lastOutgoing;
Junxiao Shi73b909a2015-02-08 21:31:42 -070087
Junxiao Shifc021862016-08-25 21:51:18 +000088 PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
Junxiao Shi73b909a2015-02-08 21:31:42 -070089 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
90
91 if (shouldSuppress) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050092 return RetxSuppressionResult::SUPPRESS;
Junxiao Shi73b909a2015-02-08 21:31:42 -070093 }
94
95 pi->suppressionInterval = std::min(m_maxInterval,
Ashlesh Gawande90015992017-07-11 17:25:48 -050096 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
97
98 return RetxSuppressionResult::FORWARD;
99}
100
101RetxSuppressionResult
102RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace)
103{
104 // NEW if outRecord for the face does not exist
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000105 auto outRecord = pitEntry.getOutRecord(outFace);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500106 if (outRecord == pitEntry.out_end()) {
107 return RetxSuppressionResult::NEW;
108 }
109
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400110 auto lastOutgoing = outRecord->getLastRenewed();
111 auto now = time::steady_clock::now();
112 auto sinceLastOutgoing = now - lastOutgoing;
Ashlesh Gawande90015992017-07-11 17:25:48 -0500113
114 // insertStrategyInfo does not insert m_initialInterval again if it already exists
115 PitInfo* pi = outRecord->insertStrategyInfo<PitInfo>(m_initialInterval).first;
116 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
117
118 if (shouldSuppress) {
119 return RetxSuppressionResult::SUPPRESS;
120 }
121
122 return RetxSuppressionResult::FORWARD;
123}
124
125void
126RetxSuppressionExponential::incrementIntervalForOutRecord(pit::OutRecord& outRecord)
127{
128 PitInfo* pi = outRecord.insertStrategyInfo<PitInfo>(m_initialInterval).first;
129 pi->suppressionInterval = std::min(m_maxInterval,
130 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
Junxiao Shi73b909a2015-02-08 21:31:42 -0700131}
132
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400133std::unique_ptr<RetxSuppressionExponential>
134RetxSuppressionExponential::construct(const StrategyParameters& params)
135{
136 auto init = params.getOrDefault<Duration::rep>("retx-suppression-initial",
137 RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL.count());
138 auto max = params.getOrDefault<Duration::rep>("retx-suppression-max",
139 RetxSuppressionExponential::DEFAULT_MAX_INTERVAL.count());
140 auto mult = params.getOrDefault<float>("retx-suppression-multiplier",
141 RetxSuppressionExponential::DEFAULT_MULTIPLIER);
142
143 return make_unique<RetxSuppressionExponential>(Duration(init), Duration(max), mult);
144}
145
Junxiao Shi73b909a2015-02-08 21:31:42 -0700146} // namespace fw
147} // namespace nfd