blob: f2ff1b2b1501ce4cfffb6d0c27da8030dcadf801 [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/*
3 * Copyright (c) 2014-2017, 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
31const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL =
32 time::milliseconds(1);
33const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0;
34const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL =
35 time::milliseconds(250);
36
37class RetxSuppressionExponential::PitInfo : public StrategyInfo
38{
39public:
40 static constexpr int
41 getTypeId()
42 {
43 return 1020;
44 }
45
46 explicit
47 PitInfo(const Duration& initialInterval)
48 : suppressionInterval(initialInterval)
49 {
50 }
51
52public:
53 /** \brief if last transmission occurred within suppressionInterval,
54 * retransmission will be suppressed
55 */
56 Duration suppressionInterval;
57};
58
59RetxSuppressionExponential::RetxSuppressionExponential(const Duration& initialInterval,
60 float multiplier,
61 const Duration& maxInterval)
62 : m_initialInterval(initialInterval)
63 , m_multiplier(multiplier)
64 , m_maxInterval(maxInterval)
65{
66 BOOST_ASSERT(initialInterval > time::milliseconds::zero());
67 BOOST_ASSERT(multiplier >= 1.0);
68 BOOST_ASSERT(maxInterval >= initialInterval);
69}
70
Ashlesh Gawande90015992017-07-11 17:25:48 -050071RetxSuppressionResult
72RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry)
Junxiao Shi73b909a2015-02-08 21:31:42 -070073{
Junxiao Shifef73e42016-03-29 14:15:05 -070074 bool isNewPitEntry = !hasPendingOutRecords(pitEntry);
Junxiao Shi73b909a2015-02-08 21:31:42 -070075 if (isNewPitEntry) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050076 return RetxSuppressionResult::NEW;
Junxiao Shi73b909a2015-02-08 21:31:42 -070077 }
78
Ashlesh Gawande90015992017-07-11 17:25:48 -050079 time::steady_clock::TimePoint lastOutgoing = getLastOutgoing(pitEntry);
Junxiao Shi73b909a2015-02-08 21:31:42 -070080 time::steady_clock::TimePoint now = time::steady_clock::now();
81 time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing;
82
Junxiao Shifc021862016-08-25 21:51:18 +000083 PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
Junxiao Shi73b909a2015-02-08 21:31:42 -070084 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
85
86 if (shouldSuppress) {
Ashlesh Gawande90015992017-07-11 17:25:48 -050087 return RetxSuppressionResult::SUPPRESS;
Junxiao Shi73b909a2015-02-08 21:31:42 -070088 }
89
90 pi->suppressionInterval = std::min(m_maxInterval,
Ashlesh Gawande90015992017-07-11 17:25:48 -050091 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
92
93 return RetxSuppressionResult::FORWARD;
94}
95
96RetxSuppressionResult
97RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace)
98{
99 // NEW if outRecord for the face does not exist
100 auto outRecord = pitEntry.getOutRecord(outFace);
101 if (outRecord == pitEntry.out_end()) {
102 return RetxSuppressionResult::NEW;
103 }
104
105 time::steady_clock::TimePoint lastOutgoing = outRecord->getLastRenewed();
106 time::steady_clock::TimePoint now = time::steady_clock::now();
107 time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing;
108
109 // insertStrategyInfo does not insert m_initialInterval again if it already exists
110 PitInfo* pi = outRecord->insertStrategyInfo<PitInfo>(m_initialInterval).first;
111 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
112
113 if (shouldSuppress) {
114 return RetxSuppressionResult::SUPPRESS;
115 }
116
117 return RetxSuppressionResult::FORWARD;
118}
119
120void
121RetxSuppressionExponential::incrementIntervalForOutRecord(pit::OutRecord& outRecord)
122{
123 PitInfo* pi = outRecord.insertStrategyInfo<PitInfo>(m_initialInterval).first;
124 pi->suppressionInterval = std::min(m_maxInterval,
125 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
Junxiao Shi73b909a2015-02-08 21:31:42 -0700126}
127
128} // namespace fw
129} // namespace nfd