Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, Regents of the University of California, |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [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 | #ifndef NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP |
| 27 | #define NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP |
| 28 | |
Davide Pesavento | 972de80 | 2024-02-16 18:42:55 -0500 | [diff] [blame] | 29 | #include "face/face-common.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 30 | #include "fw/strategy-info.hpp" |
| 31 | #include "table/measurements-accessor.hpp" |
| 32 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 33 | #include <ndn-cxx/util/rtt-estimator.hpp> |
| 34 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 35 | #include <unordered_map> |
| 36 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | namespace nfd::fw::asf { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 38 | |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame] | 39 | /** |
| 40 | * \brief Strategy information for each face in a namespace. |
| 41 | */ |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 42 | class FaceInfo |
| 43 | { |
| 44 | public: |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 45 | explicit |
| 46 | FaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts) |
| 47 | : m_rttEstimator(std::move(opts)) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 48 | { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 51 | bool |
| 52 | isTimeoutScheduled() const |
| 53 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 54 | return !!m_timeoutEvent; |
| 55 | } |
| 56 | |
| 57 | time::nanoseconds |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 58 | scheduleTimeout(const Name& interestName, ndn::scheduler::EventCallback cb); |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 59 | |
| 60 | void |
| 61 | cancelTimeout(const Name& prefix); |
| 62 | |
| 63 | void |
| 64 | recordRtt(time::nanoseconds rtt) |
| 65 | { |
| 66 | m_lastRtt = rtt; |
| 67 | m_rttEstimator.addMeasurement(rtt); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 71 | recordTimeout(const Name& interestName) |
| 72 | { |
| 73 | m_lastRtt = RTT_TIMEOUT; |
| 74 | cancelTimeout(interestName); |
| 75 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 76 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 77 | time::nanoseconds |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 78 | getLastRtt() const |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 79 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 80 | return m_lastRtt; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 83 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 84 | getSrtt() const |
| 85 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 86 | return m_rttEstimator.getSmoothedRtt(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 89 | size_t |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 90 | getNTimeouts() const |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 91 | { |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 92 | return m_nTimeouts; |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 96 | setNTimeouts(size_t nTimeouts) |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 97 | { |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 98 | m_nTimeouts = nTimeouts; |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 101 | public: |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 102 | static constexpr time::nanoseconds RTT_NO_MEASUREMENT = -1_ns; |
| 103 | static constexpr time::nanoseconds RTT_TIMEOUT = -2_ns; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 104 | |
| 105 | private: |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 106 | ndn::util::RttEstimator m_rttEstimator; |
| 107 | time::nanoseconds m_lastRtt = RTT_NO_MEASUREMENT; |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 108 | Name m_lastInterestName; |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 109 | size_t m_nTimeouts = 0; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 110 | |
| 111 | // Timeout associated with measurement |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 112 | ndn::scheduler::ScopedEventId m_measurementExpiration; |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 113 | friend class NamespaceInfo; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 114 | |
| 115 | // RTO associated with Interest |
Davide Pesavento | 2c9d2ca | 2024-01-27 16:36:51 -0500 | [diff] [blame] | 116 | ndn::scheduler::ScopedEventId m_timeoutEvent; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 119 | //////////////////////////////////////////////////////////////////////////////// |
| 120 | //////////////////////////////////////////////////////////////////////////////// |
| 121 | |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame] | 122 | /** |
| 123 | * \brief Stores strategy information about each face in this namespace. |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 124 | */ |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 125 | class NamespaceInfo final : public StrategyInfo |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 126 | { |
| 127 | public: |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 128 | static constexpr int |
| 129 | getTypeId() |
| 130 | { |
| 131 | return 1030; |
| 132 | } |
| 133 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 134 | explicit |
awlane | ee97f53 | 2024-09-19 15:48:21 -0500 | [diff] [blame] | 135 | NamespaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts, time::milliseconds measurementLifetime) |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 136 | : m_rttEstimatorOpts(std::move(opts)) |
awlane | ee97f53 | 2024-09-19 15:48:21 -0500 | [diff] [blame] | 137 | , m_measurementLifetime(measurementLifetime) |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 138 | { |
| 139 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 140 | |
| 141 | FaceInfo* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 142 | getFaceInfo(FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 143 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 144 | FaceInfo& |
| 145 | getOrCreateFaceInfo(FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 146 | |
| 147 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 148 | extendFaceInfoLifetime(FaceInfo& info, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 149 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 150 | bool |
| 151 | isProbingDue() const |
| 152 | { |
| 153 | return m_isProbingDue; |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | setIsProbingDue(bool isProbingDue) |
| 158 | { |
| 159 | m_isProbingDue = isProbingDue; |
| 160 | } |
| 161 | |
| 162 | bool |
| 163 | isFirstProbeScheduled() const |
| 164 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 165 | return m_isFirstProbeScheduled; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 169 | setIsFirstProbeScheduled(bool isScheduled) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 170 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 171 | m_isFirstProbeScheduled = isScheduled; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | private: |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 175 | std::unordered_map<FaceId, FaceInfo> m_fiMap; |
| 176 | shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts; |
awlane | ee97f53 | 2024-09-19 15:48:21 -0500 | [diff] [blame] | 177 | time::milliseconds m_measurementLifetime; |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 178 | bool m_isProbingDue = false; |
| 179 | bool m_isFirstProbeScheduled = false; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | //////////////////////////////////////////////////////////////////////////////// |
| 183 | //////////////////////////////////////////////////////////////////////////////// |
| 184 | |
awlane | 5fdcbec | 2023-12-15 14:56:05 -0600 | [diff] [blame] | 185 | /** |
| 186 | * \brief Helper class to retrieve and create strategy measurements. |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 187 | */ |
| 188 | class AsfMeasurements : noncopyable |
| 189 | { |
| 190 | public: |
| 191 | explicit |
| 192 | AsfMeasurements(MeasurementsAccessor& measurements); |
| 193 | |
| 194 | FaceInfo* |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 195 | getFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 196 | |
| 197 | FaceInfo& |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 198 | getOrCreateFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 199 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 200 | NamespaceInfo* |
| 201 | getNamespaceInfo(const Name& prefix); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 202 | |
| 203 | NamespaceInfo& |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 204 | getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Name& prefix); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 205 | |
awlane | ee97f53 | 2024-09-19 15:48:21 -0500 | [diff] [blame] | 206 | void |
| 207 | setMeasurementsLifetime(time::milliseconds measurementsLifetime) |
| 208 | { |
| 209 | // Measurement lifetime should not expire as soon as it is configured |
| 210 | BOOST_ASSERT(measurementsLifetime > 0_ms); |
| 211 | m_measurementsLifetime = measurementsLifetime; |
| 212 | } |
| 213 | |
| 214 | time::milliseconds |
| 215 | getMeasurementsLifetime() const |
| 216 | { |
| 217 | return m_measurementsLifetime; |
| 218 | } |
| 219 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 220 | private: |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 221 | void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 222 | extendLifetime(measurements::Entry& me); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 223 | |
| 224 | public: |
awlane | ee97f53 | 2024-09-19 15:48:21 -0500 | [diff] [blame] | 225 | static constexpr time::milliseconds DEFAULT_MEASUREMENTS_LIFETIME = 5_min; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 226 | |
| 227 | private: |
awlane | ee97f53 | 2024-09-19 15:48:21 -0500 | [diff] [blame] | 228 | time::milliseconds m_measurementsLifetime = DEFAULT_MEASUREMENTS_LIFETIME; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 229 | MeasurementsAccessor& m_measurements; |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 230 | shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 231 | }; |
| 232 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 233 | } // namespace nfd::fw::asf |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 234 | |
| 235 | #endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP |