blob: aabc719a71392ee1de7ea536e45f9a3f4ac984bf [file] [log] [blame]
Junxiao Shi73b909a2015-02-08 21:31:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shifef73e42016-03-29 14:15:05 -07003 * Copyright (c) 2014-2016, 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"
Junxiao Shifef73e42016-03-29 14:15:05 -070027#include "pit-algorithm.hpp"
Junxiao Shi73b909a2015-02-08 21:31:42 -070028
29namespace nfd {
30namespace fw {
31
32const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL =
33 time::milliseconds(1);
34const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0;
35const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL =
36 time::milliseconds(250);
37
38class RetxSuppressionExponential::PitInfo : public StrategyInfo
39{
40public:
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
53public:
54 /** \brief if last transmission occurred within suppressionInterval,
55 * retransmission will be suppressed
56 */
57 Duration suppressionInterval;
58};
59
60RetxSuppressionExponential::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
72RetxSuppression::Result
73RetxSuppressionExponential::decide(const Face& inFace, const Interest& interest,
74 pit::Entry& pitEntry) const
75{
Junxiao Shifef73e42016-03-29 14:15:05 -070076 bool isNewPitEntry = !hasPendingOutRecords(pitEntry);
Junxiao Shi73b909a2015-02-08 21:31:42 -070077 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 Shifc021862016-08-25 21:51:18 +000085 PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
Junxiao Shi73b909a2015-02-08 21:31:42 -070086 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