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