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 | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 34 | namespace nfd { |
| 35 | namespace fw { |
| 36 | namespace asf { |
| 37 | |
| 38 | class RttStats |
| 39 | { |
| 40 | public: |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 41 | RttStats(); |
| 42 | |
| 43 | void |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 44 | addRttMeasurement(time::nanoseconds rtt); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 45 | |
| 46 | void |
| 47 | recordTimeout() |
| 48 | { |
| 49 | m_rtt = RTT_TIMEOUT; |
| 50 | } |
| 51 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 52 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 53 | getRtt() const |
| 54 | { |
| 55 | return m_rtt; |
| 56 | } |
| 57 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 58 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 59 | getSrtt() const |
| 60 | { |
| 61 | return m_srtt; |
| 62 | } |
| 63 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 64 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 65 | computeRto() const |
| 66 | { |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 67 | return m_rttEstimator.getEstimatedRto(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 70 | public: |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 71 | static const time::nanoseconds RTT_TIMEOUT; |
| 72 | static const time::nanoseconds RTT_NO_MEASUREMENT; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 73 | |
| 74 | private: |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 75 | time::nanoseconds m_srtt; |
| 76 | time::nanoseconds m_rtt; |
| 77 | ndn::util::RttEstimator m_rttEstimator; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 78 | |
| 79 | static const double ALPHA; |
| 80 | }; |
| 81 | |
| 82 | //////////////////////////////////////////////////////////////////////////////// |
| 83 | //////////////////////////////////////////////////////////////////////////////// |
| 84 | |
| 85 | /** \brief Strategy information for each face in a namespace |
| 86 | */ |
| 87 | class FaceInfo |
| 88 | { |
| 89 | public: |
| 90 | class Error : public std::runtime_error |
| 91 | { |
| 92 | public: |
| 93 | explicit |
| 94 | Error(const std::string& what) |
| 95 | : std::runtime_error(what) |
| 96 | { |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | FaceInfo(); |
| 101 | |
| 102 | ~FaceInfo(); |
| 103 | |
| 104 | void |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 105 | setTimeoutEvent(const scheduler::EventId& id, const Name& interestName); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 106 | |
| 107 | void |
| 108 | setMeasurementExpirationEventId(const scheduler::EventId& id) |
| 109 | { |
| 110 | m_measurementExpirationId = id; |
| 111 | } |
| 112 | |
| 113 | const scheduler::EventId& |
| 114 | getMeasurementExpirationEventId() |
| 115 | { |
| 116 | return m_measurementExpirationId; |
| 117 | } |
| 118 | |
| 119 | void |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 120 | cancelTimeoutEvent(const Name& prefix); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 121 | |
| 122 | bool |
| 123 | isTimeoutScheduled() const |
| 124 | { |
| 125 | return m_isTimeoutScheduled; |
| 126 | } |
| 127 | |
| 128 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 129 | recordRtt(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 130 | |
| 131 | void |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 132 | recordTimeout(const Name& interestName); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 133 | |
| 134 | bool |
| 135 | isTimeout() const |
| 136 | { |
| 137 | return getRtt() == RttStats::RTT_TIMEOUT; |
| 138 | } |
| 139 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 140 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 141 | computeRto() const |
| 142 | { |
| 143 | return m_rttStats.computeRto(); |
| 144 | } |
| 145 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 146 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 147 | getRtt() const |
| 148 | { |
| 149 | return m_rttStats.getRtt(); |
| 150 | } |
| 151 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 152 | time::nanoseconds |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 153 | getSrtt() const |
| 154 | { |
| 155 | return m_rttStats.getSrtt(); |
| 156 | } |
| 157 | |
| 158 | bool |
| 159 | hasSrttMeasurement() const |
| 160 | { |
| 161 | return getSrtt() != RttStats::RTT_NO_MEASUREMENT; |
| 162 | } |
| 163 | |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 164 | size_t |
| 165 | getNSilentTimeouts() const |
| 166 | { |
| 167 | return m_nSilentTimeouts; |
| 168 | } |
| 169 | |
| 170 | void |
| 171 | setNSilentTimeouts(size_t nSilentTimeouts) |
| 172 | { |
| 173 | m_nSilentTimeouts = nSilentTimeouts; |
| 174 | } |
| 175 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 176 | private: |
| 177 | void |
| 178 | cancelTimeoutEvent(); |
| 179 | |
| 180 | bool |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 181 | doesNameMatchLastInterest(const Name& name); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 182 | |
| 183 | private: |
| 184 | RttStats m_rttStats; |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 185 | Name m_lastInterestName; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 186 | |
| 187 | // Timeout associated with measurement |
| 188 | scheduler::EventId m_measurementExpirationId; |
| 189 | |
| 190 | // RTO associated with Interest |
| 191 | scheduler::EventId m_timeoutEventId; |
| 192 | bool m_isTimeoutScheduled; |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 193 | size_t m_nSilentTimeouts; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 196 | typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 197 | |
| 198 | //////////////////////////////////////////////////////////////////////////////// |
| 199 | //////////////////////////////////////////////////////////////////////////////// |
| 200 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 201 | /** \brief stores strategy information about each face in this namespace |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 202 | */ |
| 203 | class NamespaceInfo : public StrategyInfo |
| 204 | { |
| 205 | public: |
| 206 | NamespaceInfo(); |
| 207 | |
| 208 | static constexpr int |
| 209 | getTypeId() |
| 210 | { |
| 211 | return 1030; |
| 212 | } |
| 213 | |
| 214 | FaceInfo& |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 215 | getOrCreateFaceInfo(const fib::Entry& fibEntry, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 216 | |
| 217 | FaceInfo* |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 218 | getFaceInfo(const fib::Entry& fibEntry, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 219 | |
| 220 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 221 | expireFaceInfo(FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 222 | |
| 223 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 224 | extendFaceInfoLifetime(FaceInfo& info, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 225 | |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 226 | FaceInfo* |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 227 | get(FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 228 | { |
Ashlesh Gawande | cad76b6 | 2017-04-04 15:28:30 -0500 | [diff] [blame] | 229 | if (m_fit.find(faceId) != m_fit.end()) { |
| 230 | return &m_fit.at(faceId); |
| 231 | } |
| 232 | else { |
| 233 | return nullptr; |
| 234 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | FaceInfoTable::iterator |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 238 | find(FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 239 | { |
| 240 | return m_fit.find(faceId); |
| 241 | } |
| 242 | |
| 243 | FaceInfoTable::iterator |
| 244 | end() |
| 245 | { |
| 246 | return m_fit.end(); |
| 247 | } |
| 248 | |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 249 | FaceInfoTable::iterator |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 250 | insert(FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 251 | { |
Ernest McCracken | 1402fa1 | 2019-06-09 00:36:28 -0700 | [diff] [blame] | 252 | return m_fit.emplace(std::piecewise_construct, |
| 253 | std::forward_as_tuple(faceId), |
| 254 | std::forward_as_tuple()).first; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | bool |
| 258 | isProbingDue() const |
| 259 | { |
| 260 | return m_isProbingDue; |
| 261 | } |
| 262 | |
| 263 | void |
| 264 | setIsProbingDue(bool isProbingDue) |
| 265 | { |
| 266 | m_isProbingDue = isProbingDue; |
| 267 | } |
| 268 | |
| 269 | bool |
| 270 | isFirstProbeScheduled() const |
| 271 | { |
| 272 | return m_hasFirstProbeBeenScheduled; |
| 273 | } |
| 274 | |
| 275 | void |
| 276 | setHasFirstProbeBeenScheduled(bool hasBeenScheduled) |
| 277 | { |
| 278 | m_hasFirstProbeBeenScheduled = hasBeenScheduled; |
| 279 | } |
| 280 | |
| 281 | private: |
| 282 | FaceInfoTable m_fit; |
| 283 | |
| 284 | bool m_isProbingDue; |
| 285 | bool m_hasFirstProbeBeenScheduled; |
| 286 | }; |
| 287 | |
| 288 | //////////////////////////////////////////////////////////////////////////////// |
| 289 | //////////////////////////////////////////////////////////////////////////////// |
| 290 | |
| 291 | /** \brief Helper class to retrieve and create strategy measurements |
| 292 | */ |
| 293 | class AsfMeasurements : noncopyable |
| 294 | { |
| 295 | public: |
| 296 | explicit |
| 297 | AsfMeasurements(MeasurementsAccessor& measurements); |
| 298 | |
| 299 | FaceInfo* |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 300 | getFaceInfo(const fib::Entry& fibEntry, const Interest& interest, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 301 | |
| 302 | FaceInfo& |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 303 | getOrCreateFaceInfo(const fib::Entry& fibEntry, const Interest& interest, FaceId faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 304 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 305 | NamespaceInfo* |
| 306 | getNamespaceInfo(const Name& prefix); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 307 | |
| 308 | NamespaceInfo& |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 309 | getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Interest& interest); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 310 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 311 | private: |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 312 | void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 313 | extendLifetime(measurements::Entry& me); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 314 | |
| 315 | public: |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 316 | static constexpr time::microseconds MEASUREMENTS_LIFETIME = 5_min; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 317 | |
| 318 | private: |
| 319 | MeasurementsAccessor& m_measurements; |
| 320 | }; |
| 321 | |
| 322 | } // namespace asf |
| 323 | } // namespace fw |
| 324 | } // namespace nfd |
| 325 | |
| 326 | #endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP |