blob: c634173435a0bad76723c2e098f5779074a9ac12 [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/*
ashiqopud3ae85d2019-02-17 02:29:55 +00003 * Copyright (c) 2014-2019, 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
Davide Pesaventoe4b22382018-06-10 14:37:24 -040031const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL = 1_ms;
32const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL = 250_ms;
33const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0f;
Junxiao Shi73b909a2015-02-08 21:31:42 -070034
35class RetxSuppressionExponential::PitInfo : public StrategyInfo
36{
37public:
38 static constexpr int
39 getTypeId()
40 {
41 return 1020;
42 }
43
44 explicit
45 PitInfo(const Duration& initialInterval)
46 : suppressionInterval(initialInterval)
47 {
48 }
49
50public:
51 /** \brief if last transmission occurred within suppressionInterval,
52 * retransmission will be suppressed
53 */
54 Duration suppressionInterval;
55};
56
57RetxSuppressionExponential::RetxSuppressionExponential(const Duration& initialInterval,
58 float multiplier,
59 const Duration& maxInterval)
60 : m_initialInterval(initialInterval)
61 , m_multiplier(multiplier)
62 , m_maxInterval(maxInterval)
63{
Davide Pesaventoe4b22382018-06-10 14:37:24 -040064 BOOST_ASSERT(initialInterval > 0_us);
65 BOOST_ASSERT(multiplier >= 1.0f);
Junxiao Shi73b909a2015-02-08 21:31:42 -070066 BOOST_ASSERT(maxInterval >= initialInterval);
67}
68
Ashlesh Gawande90015992017-07-11 17:25:48 -050069RetxSuppressionResult
70RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry)
Junxiao Shi73b909a2015-02-08 21:31:42 -070071{
Junxiao Shifef73e42016-03-29 14:15:05 -070072 bool isNewPitEntry = !hasPendingOutRecords(pitEntry);
Junxiao Shi73b909a2015-02-08 21:31:42 -070073 if (isNewPitEntry) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050074 return RetxSuppressionResult::NEW;
Junxiao Shi73b909a2015-02-08 21:31:42 -070075 }
76
Davide Pesaventoe4b22382018-06-10 14:37:24 -040077 auto lastOutgoing = getLastOutgoing(pitEntry);
78 auto now = time::steady_clock::now();
79 auto sinceLastOutgoing = now - lastOutgoing;
Junxiao Shi73b909a2015-02-08 21:31:42 -070080
Junxiao Shifc021862016-08-25 21:51:18 +000081 PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
Junxiao Shi73b909a2015-02-08 21:31:42 -070082 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
83
84 if (shouldSuppress) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050085 return RetxSuppressionResult::SUPPRESS;
Junxiao Shi73b909a2015-02-08 21:31:42 -070086 }
87
88 pi->suppressionInterval = std::min(m_maxInterval,
Ashlesh Gawande90015992017-07-11 17:25:48 -050089 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
90
91 return RetxSuppressionResult::FORWARD;
92}
93
94RetxSuppressionResult
95RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace)
96{
97 // NEW if outRecord for the face does not exist
Md Ashiqur Rahmanc88d2d42019-08-28 20:19:47 +000098 auto outRecord = pitEntry.getOutRecord(outFace);
Ashlesh Gawande90015992017-07-11 17:25:48 -050099 if (outRecord == pitEntry.out_end()) {
100 return RetxSuppressionResult::NEW;
101 }
102
Davide Pesaventoe4b22382018-06-10 14:37:24 -0400103 auto lastOutgoing = outRecord->getLastRenewed();
104 auto now = time::steady_clock::now();
105 auto sinceLastOutgoing = now - lastOutgoing;
Ashlesh Gawande90015992017-07-11 17:25:48 -0500106
107 // insertStrategyInfo does not insert m_initialInterval again if it already exists
108 PitInfo* pi = outRecord->insertStrategyInfo<PitInfo>(m_initialInterval).first;
109 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
110
111 if (shouldSuppress) {
112 return RetxSuppressionResult::SUPPRESS;
113 }
114
115 return RetxSuppressionResult::FORWARD;
116}
117
118void
119RetxSuppressionExponential::incrementIntervalForOutRecord(pit::OutRecord& outRecord)
120{
121 PitInfo* pi = outRecord.insertStrategyInfo<PitInfo>(m_initialInterval).first;
122 pi->suppressionInterval = std::min(m_maxInterval,
123 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
Junxiao Shi73b909a2015-02-08 21:31:42 -0700124}
125
126} // namespace fw
127} // namespace nfd