blob: 14039f62536ff8553a5bc9b1e13d1f37f7284519 [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 Pesavento14e71f02019-03-28 17:35:25 -04003 * Copyright (c) 2014-2019, 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
Vince Lehman8a4c29e2016-07-11 08:49:35 +000034namespace nfd {
35namespace fw {
36namespace asf {
37
Vince Lehman8a4c29e2016-07-11 08:49:35 +000038/** \brief Strategy information for each face in a namespace
39*/
40class FaceInfo
41{
42public:
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040043 explicit
44 FaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
45 : m_rttEstimator(std::move(opts))
Vince Lehman8a4c29e2016-07-11 08:49:35 +000046 {
Vince Lehman8a4c29e2016-07-11 08:49:35 +000047 }
48
Vince Lehman8a4c29e2016-07-11 08:49:35 +000049 bool
50 isTimeoutScheduled() const
51 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040052 return !!m_timeoutEvent;
53 }
54
55 time::nanoseconds
56 scheduleTimeout(const Name& interestName, scheduler::EventCallback cb);
57
58 void
59 cancelTimeout(const Name& prefix);
60
61 void
62 recordRtt(time::nanoseconds rtt)
63 {
64 m_lastRtt = rtt;
65 m_rttEstimator.addMeasurement(rtt);
Vince Lehman8a4c29e2016-07-11 08:49:35 +000066 }
67
68 void
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040069 recordTimeout(const Name& interestName)
70 {
71 m_lastRtt = RTT_TIMEOUT;
72 cancelTimeout(interestName);
73 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +000074
75 bool
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040076 hasTimeout() const
Vince Lehman8a4c29e2016-07-11 08:49:35 +000077 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040078 return getLastRtt() == RTT_TIMEOUT;
Vince Lehman8a4c29e2016-07-11 08:49:35 +000079 }
80
Ernest McCracken1402fa12019-06-09 00:36:28 -070081 time::nanoseconds
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040082 getLastRtt() const
Vince Lehman8a4c29e2016-07-11 08:49:35 +000083 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040084 return m_lastRtt;
Vince Lehman8a4c29e2016-07-11 08:49:35 +000085 }
86
Ernest McCracken1402fa12019-06-09 00:36:28 -070087 time::nanoseconds
Vince Lehman8a4c29e2016-07-11 08:49:35 +000088 getSrtt() const
89 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -040090 return m_rttEstimator.getSmoothedRtt();
Vince Lehman8a4c29e2016-07-11 08:49:35 +000091 }
92
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -050093 size_t
94 getNSilentTimeouts() const
95 {
96 return m_nSilentTimeouts;
97 }
98
99 void
100 setNSilentTimeouts(size_t nSilentTimeouts)
101 {
102 m_nSilentTimeouts = nSilentTimeouts;
103 }
104
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400105public:
106 static const time::nanoseconds RTT_NO_MEASUREMENT;
107 static const time::nanoseconds RTT_TIMEOUT;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000108
109private:
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400110 ndn::util::RttEstimator m_rttEstimator;
111 time::nanoseconds m_lastRtt = RTT_NO_MEASUREMENT;
Junxiao Shifc021862016-08-25 21:51:18 +0000112 Name m_lastInterestName;
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400113 size_t m_nSilentTimeouts = 0;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000114
115 // Timeout associated with measurement
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400116 scheduler::ScopedEventId m_measurementExpiration;
117 friend class NamespaceInfo;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000118
119 // RTO associated with Interest
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400120 scheduler::ScopedEventId m_timeoutEvent;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000121};
122
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000123////////////////////////////////////////////////////////////////////////////////
124////////////////////////////////////////////////////////////////////////////////
125
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400126/** \brief Stores strategy information about each face in this namespace
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000127 */
128class NamespaceInfo : public StrategyInfo
129{
130public:
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000131 static constexpr int
132 getTypeId()
133 {
134 return 1030;
135 }
136
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400137 explicit
138 NamespaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
139 : m_rttEstimatorOpts(std::move(opts))
140 {
141 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000142
143 FaceInfo*
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400144 getFaceInfo(FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000145
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400146 FaceInfo&
147 getOrCreateFaceInfo(FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000148
149 void
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500150 extendFaceInfoLifetime(FaceInfo& info, FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000151
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000152 bool
153 isProbingDue() const
154 {
155 return m_isProbingDue;
156 }
157
158 void
159 setIsProbingDue(bool isProbingDue)
160 {
161 m_isProbingDue = isProbingDue;
162 }
163
164 bool
165 isFirstProbeScheduled() const
166 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400167 return m_isFirstProbeScheduled;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000168 }
169
170 void
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400171 setIsFirstProbeScheduled(bool isScheduled)
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000172 {
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400173 m_isFirstProbeScheduled = isScheduled;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000174 }
175
176private:
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400177 std::unordered_map<FaceId, FaceInfo> m_fiMap;
178 shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts;
179 bool m_isProbingDue = false;
180 bool m_isFirstProbeScheduled = false;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000181};
182
183////////////////////////////////////////////////////////////////////////////////
184////////////////////////////////////////////////////////////////////////////////
185
186/** \brief Helper class to retrieve and create strategy measurements
187 */
188class AsfMeasurements : noncopyable
189{
190public:
191 explicit
192 AsfMeasurements(MeasurementsAccessor& measurements);
193
194 FaceInfo*
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500195 getFaceInfo(const fib::Entry& fibEntry, const Interest& interest, FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000196
197 FaceInfo&
Ashlesh Gawande92e4ea52017-07-19 11:38:12 -0500198 getOrCreateFaceInfo(const fib::Entry& fibEntry, const Interest& interest, FaceId faceId);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000199
Junxiao Shifc021862016-08-25 21:51:18 +0000200 NamespaceInfo*
201 getNamespaceInfo(const Name& prefix);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000202
203 NamespaceInfo&
Junxiao Shifc021862016-08-25 21:51:18 +0000204 getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Interest& interest);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000205
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000206private:
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000207 void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000208 extendLifetime(measurements::Entry& me);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000209
210public:
Davide Pesavento14e71f02019-03-28 17:35:25 -0400211 static constexpr time::microseconds MEASUREMENTS_LIFETIME = 5_min;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000212
213private:
214 MeasurementsAccessor& m_measurements;
Davide Pesaventoa6f637a2019-08-28 23:23:20 -0400215 shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000216};
217
218} // namespace asf
219} // namespace fw
220} // namespace nfd
221
222#endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP