Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 2 | /* |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 4 | * 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 | |
| 28 | namespace nfd { |
| 29 | namespace fw { |
| 30 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 31 | const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL = 1_ms; |
| 32 | const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL = 250_ms; |
| 33 | const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0f; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 34 | |
| 35 | class RetxSuppressionExponential::PitInfo : public StrategyInfo |
| 36 | { |
| 37 | public: |
| 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 | |
| 50 | public: |
| 51 | /** \brief if last transmission occurred within suppressionInterval, |
| 52 | * retransmission will be suppressed |
| 53 | */ |
| 54 | Duration suppressionInterval; |
| 55 | }; |
| 56 | |
| 57 | RetxSuppressionExponential::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 Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 64 | BOOST_ASSERT(initialInterval > 0_us); |
| 65 | BOOST_ASSERT(multiplier >= 1.0f); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 66 | BOOST_ASSERT(maxInterval >= initialInterval); |
| 67 | } |
| 68 | |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 69 | RetxSuppressionResult |
| 70 | RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry) |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 71 | { |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 72 | bool isNewPitEntry = !hasPendingOutRecords(pitEntry); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 73 | if (isNewPitEntry) { |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 74 | return RetxSuppressionResult::NEW; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 77 | auto lastOutgoing = getLastOutgoing(pitEntry); |
| 78 | auto now = time::steady_clock::now(); |
| 79 | auto sinceLastOutgoing = now - lastOutgoing; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 80 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 81 | PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 82 | bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval; |
| 83 | |
| 84 | if (shouldSuppress) { |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 85 | return RetxSuppressionResult::SUPPRESS; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | pi->suppressionInterval = std::min(m_maxInterval, |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 89 | time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier)); |
| 90 | |
| 91 | return RetxSuppressionResult::FORWARD; |
| 92 | } |
| 93 | |
| 94 | RetxSuppressionResult |
| 95 | RetxSuppressionExponential::decidePerUpstream(pit::Entry& pitEntry, Face& outFace) |
| 96 | { |
| 97 | // NEW if outRecord for the face does not exist |
ashiqopu | d3ae85d | 2019-02-17 02:29:55 +0000 | [diff] [blame] | 98 | auto outRecord = pitEntry.getOutRecord(outFace, 0); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 99 | if (outRecord == pitEntry.out_end()) { |
| 100 | return RetxSuppressionResult::NEW; |
| 101 | } |
| 102 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 103 | auto lastOutgoing = outRecord->getLastRenewed(); |
| 104 | auto now = time::steady_clock::now(); |
| 105 | auto sinceLastOutgoing = now - lastOutgoing; |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 106 | |
| 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 | |
| 118 | void |
| 119 | RetxSuppressionExponential::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 Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | } // namespace fw |
| 127 | } // namespace nfd |