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 | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, 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 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 29 | #include "fw/strategy-info.hpp" |
| 30 | #include "table/measurements-accessor.hpp" |
| 31 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 32 | #include <ndn-cxx/util/rtt-estimator.hpp> |
| 33 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame^] | 34 | #include <unordered_map> |
| 35 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 36 | namespace nfd { |
| 37 | namespace fw { |
| 38 | namespace asf { |
| 39 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 40 | /** \brief Strategy information for each face in a namespace |
| 41 | */ |
| 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 |
| 58 | scheduleTimeout(const Name& interestName, scheduler::EventCallback cb); |
| 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 | |
| 77 | bool |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 78 | hasTimeout() 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 getLastRtt() == RTT_TIMEOUT; |
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 |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 84 | getLastRtt() const |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 85 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 86 | return m_lastRtt; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 89 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 90 | getSrtt() const |
| 91 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 92 | return m_rttEstimator.getSmoothedRtt(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 95 | size_t |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 96 | getNTimeouts() const |
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 | return m_nTimeouts; |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 102 | setNTimeouts(size_t nTimeouts) |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 103 | { |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 104 | m_nTimeouts = nTimeouts; |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 105 | } |
| 106 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 107 | public: |
| 108 | static const time::nanoseconds RTT_NO_MEASUREMENT; |
| 109 | static const time::nanoseconds RTT_TIMEOUT; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 110 | |
| 111 | private: |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 112 | ndn::util::RttEstimator m_rttEstimator; |
| 113 | time::nanoseconds m_lastRtt = RTT_NO_MEASUREMENT; |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 114 | Name m_lastInterestName; |
Saurab Dulal | af3ff5a | 2021-09-19 19:45:07 -0400 | [diff] [blame] | 115 | size_t m_nTimeouts = 0; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 116 | |
| 117 | // Timeout associated with measurement |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 118 | scheduler::ScopedEventId m_measurementExpiration; |
| 119 | friend class NamespaceInfo; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 120 | |
| 121 | // RTO associated with Interest |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 122 | scheduler::ScopedEventId m_timeoutEvent; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 125 | //////////////////////////////////////////////////////////////////////////////// |
| 126 | //////////////////////////////////////////////////////////////////////////////// |
| 127 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 128 | /** \brief Stores strategy information about each face in this namespace |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 129 | */ |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 130 | class NamespaceInfo final : public StrategyInfo |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 131 | { |
| 132 | public: |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 133 | static constexpr int |
| 134 | getTypeId() |
| 135 | { |
| 136 | return 1030; |
| 137 | } |
| 138 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 139 | explicit |
| 140 | NamespaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts) |
| 141 | : m_rttEstimatorOpts(std::move(opts)) |
| 142 | { |
| 143 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 144 | |
| 145 | FaceInfo* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 146 | getFaceInfo(FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 147 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 148 | FaceInfo& |
| 149 | getOrCreateFaceInfo(FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 150 | |
| 151 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 152 | extendFaceInfoLifetime(FaceInfo& info, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 153 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 154 | bool |
| 155 | isProbingDue() const |
| 156 | { |
| 157 | return m_isProbingDue; |
| 158 | } |
| 159 | |
| 160 | void |
| 161 | setIsProbingDue(bool isProbingDue) |
| 162 | { |
| 163 | m_isProbingDue = isProbingDue; |
| 164 | } |
| 165 | |
| 166 | bool |
| 167 | isFirstProbeScheduled() const |
| 168 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 169 | return m_isFirstProbeScheduled; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | void |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 173 | setIsFirstProbeScheduled(bool isScheduled) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 174 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 175 | m_isFirstProbeScheduled = isScheduled; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | private: |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 179 | std::unordered_map<FaceId, FaceInfo> m_fiMap; |
| 180 | shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts; |
| 181 | bool m_isProbingDue = false; |
| 182 | bool m_isFirstProbeScheduled = false; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | //////////////////////////////////////////////////////////////////////////////// |
| 186 | //////////////////////////////////////////////////////////////////////////////// |
| 187 | |
| 188 | /** \brief Helper class to retrieve and create strategy measurements |
| 189 | */ |
| 190 | class AsfMeasurements : noncopyable |
| 191 | { |
| 192 | public: |
| 193 | explicit |
| 194 | AsfMeasurements(MeasurementsAccessor& measurements); |
| 195 | |
| 196 | FaceInfo* |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 197 | getFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 198 | |
| 199 | FaceInfo& |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 200 | getOrCreateFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 201 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 202 | NamespaceInfo* |
| 203 | getNamespaceInfo(const Name& prefix); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 204 | |
| 205 | NamespaceInfo& |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 206 | getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Name& prefix); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 207 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 208 | private: |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 209 | void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 210 | extendLifetime(measurements::Entry& me); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 211 | |
| 212 | public: |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 213 | static constexpr time::microseconds MEASUREMENTS_LIFETIME = 5_min; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 214 | |
| 215 | private: |
| 216 | MeasurementsAccessor& m_measurements; |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 217 | shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | } // namespace asf |
| 221 | } // namespace fw |
| 222 | } // namespace nfd |
| 223 | |
| 224 | #endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP |