blob: 114b491e5f2734378aa70f652f16969c735780d4 [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"
27
28namespace nfd {
29namespace fw {
30
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040031const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL = 10_ms;
Davide Pesaventoe4b22382018-06-10 14:37:24 -040032const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL = 250_ms;
33const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0f;
Junxiao Shi73b909a2015-02-08 21:31:42 -070034
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040035namespace {
36
37class PitInfo final : public StrategyInfo
Junxiao Shi73b909a2015-02-08 21:31:42 -070038{
39public:
40 static constexpr int
41 getTypeId()
42 {
43 return 1020;
44 }
45
46 explicit
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040047 PitInfo(const RetxSuppressionExponential::Duration& initialInterval)
Junxiao Shi73b909a2015-02-08 21:31:42 -070048 : suppressionInterval(initialInterval)
49 {
50 }
51
52public:
53 /** \brief if last transmission occurred within suppressionInterval,
54 * retransmission will be suppressed
55 */
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040056 RetxSuppressionExponential::Duration suppressionInterval;
Junxiao Shi73b909a2015-02-08 21:31:42 -070057};
58
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040059} // namespace
60
61RetxSuppressionExponential::RetxSuppressionExponential(Duration initialInterval,
62 Duration maxInterval,
63 float multiplier)
Junxiao Shi73b909a2015-02-08 21:31:42 -070064 : m_initialInterval(initialInterval)
Junxiao Shi73b909a2015-02-08 21:31:42 -070065 , m_maxInterval(maxInterval)
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040066 , m_multiplier(multiplier)
Junxiao Shi73b909a2015-02-08 21:31:42 -070067{
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -040068 if (m_initialInterval <= 0_ns) {
69 NDN_THROW(std::invalid_argument("Retx suppression initial interval must be > 0"));
70 }
71 if (m_maxInterval < m_initialInterval) {
72 NDN_THROW(std::invalid_argument("Retx suppression max interval must be >= initial interval"));
73 }
74 if (m_multiplier < 1.0f) {
75 NDN_THROW(std::invalid_argument("Retx suppression multiplier must be >= 1"));
76 }
Junxiao Shi73b909a2015-02-08 21:31:42 -070077}
78
Ashlesh Gawande90015992017-07-11 17:25:48 -050079RetxSuppressionResult
80RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry)
Junxiao Shi73b909a2015-02-08 21:31:42 -070081{
Junxiao Shifef73e42016-03-29 14:15:05 -070082 bool isNewPitEntry = !hasPendingOutRecords(pitEntry);
Junxiao Shi73b909a2015-02-08 21:31:42 -070083 if (isNewPitEntry) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050084 return RetxSuppressionResult::NEW;
Junxiao Shi73b909a2015-02-08 21:31:42 -070085 }
86
Davide Pesaventoe4b22382018-06-10 14:37:24 -040087 auto lastOutgoing = getLastOutgoing(pitEntry);
88 auto now = time::steady_clock::now();
89 auto sinceLastOutgoing = now - lastOutgoing;
Junxiao Shi73b909a2015-02-08 21:31:42 -070090
Junxiao Shifc021862016-08-25 21:51:18 +000091 PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
Junxiao Shi73b909a2015-02-08 21:31:42 -070092 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
93
94 if (shouldSuppress) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050095 return RetxSuppressionResult::SUPPRESS;
Junxiao Shi73b909a2015-02-08 21:31:42 -070096 }
97
98 pi->suppressionInterval = std::min(m_maxInterval,
Ashlesh Gawande90015992017-07-11 17:25:48 -050099 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
100
101 return RetxSuppressionResult::FORWARD;
102}
103
104RetxSuppressionResult
105RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace)
106{
107 // NEW if outRecord for the face does not exist
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +0000108 auto outRecord = pitEntry.getOutRecord(outFace);
Ashlesh Gawande90015992017-07-11 17:25:48 -0500109 if (outRecord == pitEntry.out_end()) {
110 return RetxSuppressionResult::NEW;
111 }
112
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400113 auto lastOutgoing = outRecord->getLastRenewed();
114 auto now = time::steady_clock::now();
115 auto sinceLastOutgoing = now - lastOutgoing;
Ashlesh Gawande90015992017-07-11 17:25:48 -0500116
117 // insertStrategyInfo does not insert m_initialInterval again if it already exists
118 PitInfo* pi = outRecord->insertStrategyInfo<PitInfo>(m_initialInterval).first;
119 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
120
121 if (shouldSuppress) {
122 return RetxSuppressionResult::SUPPRESS;
123 }
124
125 return RetxSuppressionResult::FORWARD;
126}
127
128void
129RetxSuppressionExponential::incrementIntervalForOutRecord(pit::OutRecord& outRecord)
130{
131 PitInfo* pi = outRecord.insertStrategyInfo<PitInfo>(m_initialInterval).first;
132 pi->suppressionInterval = std::min(m_maxInterval,
133 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
Junxiao Shi73b909a2015-02-08 21:31:42 -0700134}
135
Ashlesh Gawande1ef93d02022-04-08 00:25:06 -0400136std::unique_ptr<RetxSuppressionExponential>
137RetxSuppressionExponential::construct(const StrategyParameters& params)
138{
139 auto init = params.getOrDefault<Duration::rep>("retx-suppression-initial",
140 RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL.count());
141 auto max = params.getOrDefault<Duration::rep>("retx-suppression-max",
142 RetxSuppressionExponential::DEFAULT_MAX_INTERVAL.count());
143 auto mult = params.getOrDefault<float>("retx-suppression-multiplier",
144 RetxSuppressionExponential::DEFAULT_MULTIPLIER);
145
146 return make_unique<RetxSuppressionExponential>(Duration(init), Duration(max), mult);
147}
148
Junxiao Shi73b909a2015-02-08 21:31:42 -0700149} // namespace fw
150} // namespace nfd