NFD: Named Data Networking Forwarding Daemon 24.07-28-gdcc0e6e0
Loading...
Searching...
No Matches
retx-suppression-exponential.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, Regents of the University of California,
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
27#include "algorithm.hpp"
28
29namespace nfd::fw {
30
31namespace {
32
33class PitInfo final : public StrategyInfo
34{
35public:
36 static constexpr int
37 getTypeId()
38 {
39 return 1020;
40 }
41
42 explicit
43 PitInfo(const RetxSuppressionExponential::Duration& initialInterval)
44 : suppressionInterval(initialInterval)
45 {
46 }
47
48public:
49 // If the last transmission occurred within this interval, retx will be suppressed
51};
52
53} // namespace
54
56 Duration maxInterval,
57 float multiplier)
58 : m_initialInterval(initialInterval)
59 , m_maxInterval(maxInterval)
60 , m_multiplier(multiplier)
61{
62 if (m_initialInterval <= 0_ns) {
63 NDN_THROW(std::invalid_argument("Retx suppression initial interval must be > 0"));
64 }
65 if (m_maxInterval < m_initialInterval) {
66 NDN_THROW(std::invalid_argument("Retx suppression max interval must be >= initial interval"));
67 }
68 if (m_multiplier < 1.0f) {
69 NDN_THROW(std::invalid_argument("Retx suppression multiplier must be >= 1"));
70 }
71}
72
75{
76 bool isNewPitEntry = !hasPendingOutRecords(pitEntry);
77 if (isNewPitEntry) {
79 }
80
81 auto lastOutgoing = getLastOutgoing(pitEntry);
82 auto now = time::steady_clock::now();
83 auto sinceLastOutgoing = now - lastOutgoing;
84
85 PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
86 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
87
88 if (shouldSuppress) {
90 }
91
92 pi->suppressionInterval = std::min(m_maxInterval,
93 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
94
96}
97
100{
101 // NEW if outRecord for the face does not exist
102 auto outRecord = pitEntry.findOutRecord(outFace);
103 if (outRecord == pitEntry.out_end()) {
105 }
106
107 auto lastOutgoing = outRecord->getLastRenewed();
108 auto now = time::steady_clock::now();
109 auto sinceLastOutgoing = now - lastOutgoing;
110
111 // insertStrategyInfo does not insert m_initialInterval again if it already exists
112 PitInfo* pi = outRecord->insertStrategyInfo<PitInfo>(m_initialInterval).first;
113 bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
114
115 if (shouldSuppress) {
117 }
118
120}
121
122void
124{
125 PitInfo* pi = outRecord.insertStrategyInfo<PitInfo>(m_initialInterval).first;
126 pi->suppressionInterval = std::min(m_maxInterval,
127 time::duration_cast<Duration>(pi->suppressionInterval * m_multiplier));
128}
129
130std::unique_ptr<RetxSuppressionExponential>
132{
133 auto init = params.getOrDefault<Duration::rep>("retx-suppression-initial",
135 auto max = params.getOrDefault<Duration::rep>("retx-suppression-max",
137 auto mult = params.getOrDefault<float>("retx-suppression-multiplier",
139
140 return make_unique<RetxSuppressionExponential>(Duration(init), Duration(max), mult);
141}
142
143} // namespace nfd::fw
This file contains common algorithms used by forwarding strategies.
std::pair< T *, bool > insertStrategyInfo(A &&... args)
Insert a StrategyInfo item.
Generalization of a network interface.
Definition face.hpp:118
time::milliseconds Duration
Time granularity.
static std::unique_ptr< RetxSuppressionExponential > construct(const StrategyParameters &params)
void incrementIntervalForOutRecord(pit::OutRecord &outRecord)
Increment the suppression interval for an out-record.
RetxSuppressionResult decidePerUpstream(pit::Entry &pitEntry, Face &outFace)
Determines whether Interest is a retransmission per upstream and if so, whether it shall be forwarded...
RetxSuppressionResult decidePerPitEntry(pit::Entry &pitEntry)
Determines whether Interest is a retransmission per PIT entry and if so, whether it shall be forwarde...
RetxSuppressionExponential(Duration initialInterval=DEFAULT_INITIAL_INTERVAL, Duration maxInterval=DEFAULT_MAX_INTERVAL, float multiplier=DEFAULT_MULTIPLIER)
std::enable_if_t< std::is_signed_v< T >, T > getOrDefault(const key_type &key, const T &defaultVal) const
Definition strategy.hpp:489
Represents an entry in the Interest table (PIT).
OutRecordCollection::iterator findOutRecord(const Face &face) noexcept
Get the out-record for face.
OutRecordCollection::iterator out_end() noexcept
Contains information about an Interest toward an outgoing face.
@ SUPPRESS
Interest is a retransmission and should be suppressed.
@ NEW
Interest is new (not a retransmission).
@ FORWARD
Interest is a retransmission and should be forwarded.
bool hasPendingOutRecords(const pit::Entry &pitEntry)
Determine whether pitEntry has any pending out-records.
Definition algorithm.cpp:85
time::steady_clock::time_point getLastOutgoing(const pit::Entry &pitEntry)
Definition algorithm.cpp:96
RetxSuppressionExponential::Duration suppressionInterval