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 | /* |
| 3 | * Copyright (c) 2014-2017, 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 | |
| 31 | const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL = |
| 32 | time::milliseconds(1); |
| 33 | const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0; |
| 34 | const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL = |
| 35 | time::milliseconds(250); |
| 36 | |
| 37 | class RetxSuppressionExponential::PitInfo : public StrategyInfo |
| 38 | { |
| 39 | public: |
| 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 | |
| 52 | public: |
| 53 | /** \brief if last transmission occurred within suppressionInterval, |
| 54 | * retransmission will be suppressed |
| 55 | */ |
| 56 | Duration suppressionInterval; |
| 57 | }; |
| 58 | |
| 59 | RetxSuppressionExponential::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 Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 71 | RetxSuppressionResult |
| 72 | RetxSuppressionExponential::decidePerPitEntry(pit::Entry& pitEntry) |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 73 | { |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 74 | bool isNewPitEntry = !hasPendingOutRecords(pitEntry); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 75 | if (isNewPitEntry) { |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 76 | return RetxSuppressionResult::NEW; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 79 | time::steady_clock::TimePoint lastOutgoing = getLastOutgoing(pitEntry); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 80 | time::steady_clock::TimePoint now = time::steady_clock::now(); |
| 81 | time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing; |
| 82 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 83 | PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 84 | bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval; |
| 85 | |
| 86 | if (shouldSuppress) { |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 87 | return RetxSuppressionResult::SUPPRESS; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | pi->suppressionInterval = std::min(m_maxInterval, |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 91 | time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier)); |
| 92 | |
| 93 | return RetxSuppressionResult::FORWARD; |
| 94 | } |
| 95 | |
| 96 | RetxSuppressionResult |
| 97 | RetxSuppressionExponential::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 | |
| 120 | void |
| 121 | RetxSuppressionExponential::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 Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | } // namespace fw |
| 129 | } // namespace nfd |