blob: 10c081c1bf19766294464c1d6a704a06d704d569 [file] [log] [blame]
Vince Lehman8a4c29e2016-07-11 08:49:35 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -05002/*
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, Regents of the University of California,
Vince Lehman8a4c29e2016-07-11 08:49:35 +00004 * 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#ifndef NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
27#define NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
28
Vince Lehman8a4c29e2016-07-11 08:49:35 +000029#include "fw/strategy-info.hpp"
30#include "table/measurements-accessor.hpp"
31
Ernest McCracken1402fa12019-06-09 00:36:28 -070032#include <ndn-cxx/util/rtt-estimator.hpp>
33
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040034#include <unordered_map>
35
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040036namespace nfd::fw::asf {
Vince Lehman8a4c29e2016-07-11 08:49:35 +000037
awlane5fdcbec2023-12-15 14:56:05 -060038/**
39 * \brief Strategy information for each face in a namespace.
40 */
Vince Lehman8a4c29e2016-07-11 08:49:35 +000041class FaceInfo
42{
43public:
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040044 explicit
45 FaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
46 : m_rttEstimator(std::move(opts))
Vince Lehman8a4c29e2016-07-11 08:49:35 +000047 {
Vince Lehman8a4c29e2016-07-11 08:49:35 +000048 }
49
Vince Lehman8a4c29e2016-07-11 08:49:35 +000050 bool
51 isTimeoutScheduled() const
52 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040053 return !!m_timeoutEvent;
54 }
55
56 time::nanoseconds
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -050057 scheduleTimeout(const Name& interestName, ndn::scheduler::EventCallback cb);
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040058
59 void
60 cancelTimeout(const Name& prefix);
61
62 void
63 recordRtt(time::nanoseconds rtt)
64 {
65 m_lastRtt = rtt;
66 m_rttEstimator.addMeasurement(rtt);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000067 }
68
69 void
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040070 recordTimeout(const Name& interestName)
71 {
72 m_lastRtt = RTT_TIMEOUT;
73 cancelTimeout(interestName);
74 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +000075
Ernest McCracken1402fa12019-06-09 00:36:28 -070076 time::nanoseconds
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040077 getLastRtt() const
Vince Lehman8a4c29e2016-07-11 08:49:35 +000078 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040079 return m_lastRtt;
Vince Lehman8a4c29e2016-07-11 08:49:35 +000080 }
81
Ernest McCracken1402fa12019-06-09 00:36:28 -070082 time::nanoseconds
Vince Lehman8a4c29e2016-07-11 08:49:35 +000083 getSrtt() const
84 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040085 return m_rttEstimator.getSmoothedRtt();
Vince Lehman8a4c29e2016-07-11 08:49:35 +000086 }
87
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050088 size_t
Saurab Dulalaf3ff5a2021-09-19 19:45:07 -040089 getNTimeouts() const
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050090 {
Saurab Dulalaf3ff5a2021-09-19 19:45:07 -040091 return m_nTimeouts;
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050092 }
93
94 void
Saurab Dulalaf3ff5a2021-09-19 19:45:07 -040095 setNTimeouts(size_t nTimeouts)
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050096 {
Saurab Dulalaf3ff5a2021-09-19 19:45:07 -040097 m_nTimeouts = nTimeouts;
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050098 }
99
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400100public:
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400101 static constexpr time::nanoseconds RTT_NO_MEASUREMENT = -1_ns;
102 static constexpr time::nanoseconds RTT_TIMEOUT = -2_ns;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000103
104private:
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400105 ndn::util::RttEstimator m_rttEstimator;
106 time::nanoseconds m_lastRtt = RTT_NO_MEASUREMENT;
Junxiao Shifc021862016-08-25 21:51:18 +0000107 Name m_lastInterestName;
Saurab Dulalaf3ff5a2021-09-19 19:45:07 -0400108 size_t m_nTimeouts = 0;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000109
110 // Timeout associated with measurement
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -0500111 ndn::scheduler::ScopedEventId m_measurementExpiration;
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400112 friend class NamespaceInfo;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000113
114 // RTO associated with Interest
Davide Pesavento2c9d2ca2024-01-27 16:36:51 -0500115 ndn::scheduler::ScopedEventId m_timeoutEvent;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000116};
117
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000118////////////////////////////////////////////////////////////////////////////////
119////////////////////////////////////////////////////////////////////////////////
120
awlane5fdcbec2023-12-15 14:56:05 -0600121/**
122 * \brief Stores strategy information about each face in this namespace.
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000123 */
Davide Pesavento3db98072021-03-09 23:03:27 -0500124class NamespaceInfo final : public StrategyInfo
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000125{
126public:
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000127 static constexpr int
128 getTypeId()
129 {
130 return 1030;
131 }
132
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400133 explicit
134 NamespaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
135 : m_rttEstimatorOpts(std::move(opts))
136 {
137 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000138
139 FaceInfo*
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400140 getFaceInfo(FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000141
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400142 FaceInfo&
143 getOrCreateFaceInfo(FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000144
145 void
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500146 extendFaceInfoLifetime(FaceInfo& info, FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000147
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000148 bool
149 isProbingDue() const
150 {
151 return m_isProbingDue;
152 }
153
154 void
155 setIsProbingDue(bool isProbingDue)
156 {
157 m_isProbingDue = isProbingDue;
158 }
159
160 bool
161 isFirstProbeScheduled() const
162 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400163 return m_isFirstProbeScheduled;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000164 }
165
166 void
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400167 setIsFirstProbeScheduled(bool isScheduled)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000168 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400169 m_isFirstProbeScheduled = isScheduled;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000170 }
171
172private:
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400173 std::unordered_map<FaceId, FaceInfo> m_fiMap;
174 shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts;
175 bool m_isProbingDue = false;
176 bool m_isFirstProbeScheduled = false;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000177};
178
179////////////////////////////////////////////////////////////////////////////////
180////////////////////////////////////////////////////////////////////////////////
181
awlane5fdcbec2023-12-15 14:56:05 -0600182/**
183 * \brief Helper class to retrieve and create strategy measurements.
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000184 */
185class AsfMeasurements : noncopyable
186{
187public:
188 explicit
189 AsfMeasurements(MeasurementsAccessor& measurements);
190
191 FaceInfo*
Saurab Dulal432be572021-01-26 12:09:29 -0600192 getFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000193
194 FaceInfo&
Saurab Dulal432be572021-01-26 12:09:29 -0600195 getOrCreateFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000196
Junxiao Shifc021862016-08-25 21:51:18 +0000197 NamespaceInfo*
198 getNamespaceInfo(const Name& prefix);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000199
200 NamespaceInfo&
Saurab Dulal432be572021-01-26 12:09:29 -0600201 getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Name& prefix);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000202
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000203private:
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000204 void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000205 extendLifetime(measurements::Entry& me);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000206
207public:
Davide Pesavento14e71f02019-03-28 17:35:25 -0400208 static constexpr time::microseconds MEASUREMENTS_LIFETIME = 5_min;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000209
210private:
211 MeasurementsAccessor& m_measurements;
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400212 shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000213};
214
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400215} // namespace nfd::fw::asf
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000216
217#endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP