Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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" |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 27 | #include "algorithm.hpp" |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 28 | |
| 29 | namespace nfd { |
| 30 | namespace fw { |
| 31 | |
| 32 | const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL = |
| 33 | time::milliseconds(1); |
| 34 | const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0; |
| 35 | const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL = |
| 36 | time::milliseconds(250); |
| 37 | |
| 38 | class RetxSuppressionExponential::PitInfo : public StrategyInfo |
| 39 | { |
| 40 | public: |
| 41 | static constexpr int |
| 42 | getTypeId() |
| 43 | { |
| 44 | return 1020; |
| 45 | } |
| 46 | |
| 47 | explicit |
| 48 | PitInfo(const Duration& initialInterval) |
| 49 | : suppressionInterval(initialInterval) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | public: |
| 54 | /** \brief if last transmission occurred within suppressionInterval, |
| 55 | * retransmission will be suppressed |
| 56 | */ |
| 57 | Duration suppressionInterval; |
| 58 | }; |
| 59 | |
| 60 | RetxSuppressionExponential::RetxSuppressionExponential(const Duration& initialInterval, |
| 61 | float multiplier, |
| 62 | const Duration& maxInterval) |
| 63 | : m_initialInterval(initialInterval) |
| 64 | , m_multiplier(multiplier) |
| 65 | , m_maxInterval(maxInterval) |
| 66 | { |
| 67 | BOOST_ASSERT(initialInterval > time::milliseconds::zero()); |
| 68 | BOOST_ASSERT(multiplier >= 1.0); |
| 69 | BOOST_ASSERT(maxInterval >= initialInterval); |
| 70 | } |
| 71 | |
| 72 | RetxSuppression::Result |
| 73 | RetxSuppressionExponential::decide(const Face& inFace, const Interest& interest, |
| 74 | pit::Entry& pitEntry) const |
| 75 | { |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 76 | bool isNewPitEntry = !hasPendingOutRecords(pitEntry); |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 77 | if (isNewPitEntry) { |
| 78 | return NEW; |
| 79 | } |
| 80 | |
| 81 | time::steady_clock::TimePoint lastOutgoing = this->getLastOutgoing(pitEntry); |
| 82 | time::steady_clock::TimePoint now = time::steady_clock::now(); |
| 83 | time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing; |
| 84 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 85 | PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first; |
Junxiao Shi | 73b909a | 2015-02-08 21:31:42 -0700 | [diff] [blame] | 86 | bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval; |
| 87 | |
| 88 | if (shouldSuppress) { |
| 89 | return SUPPRESS; |
| 90 | } |
| 91 | |
| 92 | pi->suppressionInterval = std::min(m_maxInterval, |
| 93 | time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier)); |
| 94 | return FORWARD; |
| 95 | } |
| 96 | |
| 97 | } // namespace fw |
| 98 | } // namespace nfd |