blob: ba858df8da09c3195a552480926e59be5fd9a30a [file] [log] [blame]
Vince Lehman8a4c29e2016-07-11 08:49:35 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Eric Newberry185ab292017-03-28 06:45:39 +00003 * Copyright (c) 2014-2017, 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
Eric Newberry185ab292017-03-28 06:45:39 +000029#include "core/rtt-estimator.hpp"
Vince Lehman8a4c29e2016-07-11 08:49:35 +000030#include "fw/strategy-info.hpp"
31#include "table/measurements-accessor.hpp"
32
33namespace nfd {
34namespace fw {
35namespace asf {
36
37class RttStats
38{
39public:
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
71private:
72 static Rtt
73 computeSrtt(Rtt previousSrtt, Rtt currentRtt);
74
75public:
76 static const Rtt RTT_TIMEOUT;
77 static const Rtt RTT_NO_MEASUREMENT;
78
79private:
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*/
92class FaceInfo
93{
94public:
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 Shifc021862016-08-25 21:51:18 +0000110 setTimeoutEvent(const scheduler::EventId& id, const Name& interestName);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000111
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 Shifc021862016-08-25 21:51:18 +0000125 cancelTimeoutEvent(const Name& prefix);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000126
127 bool
128 isTimeoutScheduled() const
129 {
130 return m_isTimeoutScheduled;
131 }
132
133 void
Junxiao Shi15e98b02016-08-12 11:21:44 +0000134 recordRtt(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000135
136 void
Junxiao Shifc021862016-08-25 21:51:18 +0000137 recordTimeout(const Name& interestName);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000138
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
169private:
170 void
171 cancelTimeoutEvent();
172
173 bool
Junxiao Shifc021862016-08-25 21:51:18 +0000174 doesNameMatchLastInterest(const Name& name);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000175
176private:
177 RttStats m_rttStats;
Junxiao Shifc021862016-08-25 21:51:18 +0000178 Name m_lastInterestName;
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000179
180 // Timeout associated with measurement
181 scheduler::EventId m_measurementExpirationId;
182
183 // RTO associated with Interest
184 scheduler::EventId m_timeoutEventId;
185 bool m_isTimeoutScheduled;
186};
187
188typedef std::unordered_map<face::FaceId, FaceInfo> FaceInfoTable;
189
190////////////////////////////////////////////////////////////////////////////////
191////////////////////////////////////////////////////////////////////////////////
192
193/** \brief stores stategy information about each face in this namespace
194 */
195class NamespaceInfo : public StrategyInfo
196{
197public:
198 NamespaceInfo();
199
200 static constexpr int
201 getTypeId()
202 {
203 return 1030;
204 }
205
206 FaceInfo&
207 getOrCreateFaceInfo(const fib::Entry& fibEntry, const Face& face);
208
209 FaceInfo*
210 getFaceInfo(const fib::Entry& fibEntry, const Face& face);
211
212 void
213 expireFaceInfo(nfd::face::FaceId faceId);
214
215 void
216 extendFaceInfoLifetime(FaceInfo& info, const Face& face);
217
Ashlesh Gawandecad76b62017-04-04 15:28:30 -0500218 FaceInfo*
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000219 get(nfd::face::FaceId faceId)
220 {
Ashlesh Gawandecad76b62017-04-04 15:28:30 -0500221 if (m_fit.find(faceId) != m_fit.end()) {
222 return &m_fit.at(faceId);
223 }
224 else {
225 return nullptr;
226 }
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000227 }
228
229 FaceInfoTable::iterator
230 find(nfd::face::FaceId faceId)
231 {
232 return m_fit.find(faceId);
233 }
234
235 FaceInfoTable::iterator
236 end()
237 {
238 return m_fit.end();
239 }
240
241 const FaceInfoTable::iterator
242 insert(nfd::face::FaceId faceId)
243 {
244 const auto& pair = m_fit.insert(std::make_pair(faceId, FaceInfo()));
245 return pair.first;
246 }
247
248 bool
249 isProbingDue() const
250 {
251 return m_isProbingDue;
252 }
253
254 void
255 setIsProbingDue(bool isProbingDue)
256 {
257 m_isProbingDue = isProbingDue;
258 }
259
260 bool
261 isFirstProbeScheduled() const
262 {
263 return m_hasFirstProbeBeenScheduled;
264 }
265
266 void
267 setHasFirstProbeBeenScheduled(bool hasBeenScheduled)
268 {
269 m_hasFirstProbeBeenScheduled = hasBeenScheduled;
270 }
271
272private:
273 FaceInfoTable m_fit;
274
275 bool m_isProbingDue;
276 bool m_hasFirstProbeBeenScheduled;
277};
278
279////////////////////////////////////////////////////////////////////////////////
280////////////////////////////////////////////////////////////////////////////////
281
282/** \brief Helper class to retrieve and create strategy measurements
283 */
284class AsfMeasurements : noncopyable
285{
286public:
287 explicit
288 AsfMeasurements(MeasurementsAccessor& measurements);
289
290 FaceInfo*
Junxiao Shifc021862016-08-25 21:51:18 +0000291 getFaceInfo(const fib::Entry& fibEntry, const Interest& interest, const Face& face);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000292
293 FaceInfo&
Junxiao Shifc021862016-08-25 21:51:18 +0000294 getOrCreateFaceInfo(const fib::Entry& fibEntry, const Interest& interest, const Face& face);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000295
Junxiao Shifc021862016-08-25 21:51:18 +0000296 NamespaceInfo*
297 getNamespaceInfo(const Name& prefix);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000298
299 NamespaceInfo&
Junxiao Shifc021862016-08-25 21:51:18 +0000300 getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Interest& interest);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000301
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000302private:
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000303 void
Junxiao Shi80f9fcd2016-07-23 02:48:36 +0000304 extendLifetime(measurements::Entry& me);
Vince Lehman8a4c29e2016-07-11 08:49:35 +0000305
306public:
307 static constexpr time::microseconds MEASUREMENTS_LIFETIME = time::seconds(300);
308
309private:
310 MeasurementsAccessor& m_measurements;
311};
312
313} // namespace asf
314} // namespace fw
315} // namespace nfd
316
317#endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP