NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
asf-measurements.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, Regents of the University of California,
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 
29 #include "core/rtt-estimator.hpp"
30 #include "fw/strategy-info.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
46 
47  void
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 
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 
89 
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
110  setTimeoutEvent(const scheduler::EventId& id, const Name& interestName);
111 
112  void
114  {
115  m_measurementExpirationId = id;
116  }
117 
118  const scheduler::EventId&
120  {
121  return m_measurementExpirationId;
122  }
123 
124  void
125  cancelTimeoutEvent(const Name& prefix);
126 
127  bool
129  {
130  return m_isTimeoutScheduled;
131  }
132 
133  void
134  recordRtt(const shared_ptr<pit::Entry>& pitEntry, const Face& inFace);
135 
136  void
137  recordTimeout(const Name& interestName);
138 
139  bool
140  isTimeout() const
141  {
142  return getRtt() == RttStats::RTT_TIMEOUT;
143  }
144 
146  computeRto() const
147  {
148  return m_rttStats.computeRto();
149  }
150 
152  getRtt() const
153  {
154  return m_rttStats.getRtt();
155  }
156 
158  getSrtt() const
159  {
160  return m_rttStats.getSrtt();
161  }
162 
163  bool
165  {
167  }
168 
169  size_t
171  {
172  return m_nSilentTimeouts;
173  }
174 
175  void
176  setNSilentTimeouts(size_t nSilentTimeouts)
177  {
178  m_nSilentTimeouts = nSilentTimeouts;
179  }
180 
181 private:
182  void
183  cancelTimeoutEvent();
184 
185  bool
186  doesNameMatchLastInterest(const Name& name);
187 
188 private:
189  RttStats m_rttStats;
190  Name m_lastInterestName;
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;
198  size_t m_nSilentTimeouts;
199 };
200 
201 typedef std::unordered_map<FaceId, FaceInfo> FaceInfoTable;
202 
205 
209 {
210 public:
211  NamespaceInfo();
212 
213  static constexpr int
215  {
216  return 1030;
217  }
218 
219  FaceInfo&
220  getOrCreateFaceInfo(const fib::Entry& fibEntry, FaceId faceId);
221 
222  FaceInfo*
223  getFaceInfo(const fib::Entry& fibEntry, FaceId faceId);
224 
225  void
226  expireFaceInfo(FaceId faceId);
227 
228  void
229  extendFaceInfoLifetime(FaceInfo& info, FaceId faceId);
230 
231  FaceInfo*
232  get(FaceId faceId)
233  {
234  if (m_fit.find(faceId) != m_fit.end()) {
235  return &m_fit.at(faceId);
236  }
237  else {
238  return nullptr;
239  }
240  }
241 
243  find(FaceId faceId)
244  {
245  return m_fit.find(faceId);
246  }
247 
249  end()
250  {
251  return m_fit.end();
252  }
253 
255  insert(FaceId faceId)
256  {
257  const auto& pair = m_fit.insert(std::make_pair(faceId, FaceInfo()));
258  return pair.first;
259  }
260 
261  bool
262  isProbingDue() const
263  {
264  return m_isProbingDue;
265  }
266 
267  void
269  {
270  m_isProbingDue = isProbingDue;
271  }
272 
273  bool
275  {
276  return m_hasFirstProbeBeenScheduled;
277  }
278 
279  void
280  setHasFirstProbeBeenScheduled(bool hasBeenScheduled)
281  {
282  m_hasFirstProbeBeenScheduled = hasBeenScheduled;
283  }
284 
285 private:
286  FaceInfoTable m_fit;
287 
288  bool m_isProbingDue;
289  bool m_hasFirstProbeBeenScheduled;
290 };
291 
294 
297 class AsfMeasurements : noncopyable
298 {
299 public:
300  explicit
301  AsfMeasurements(MeasurementsAccessor& measurements);
302 
303  FaceInfo*
304  getFaceInfo(const fib::Entry& fibEntry, const Interest& interest, FaceId faceId);
305 
306  FaceInfo&
307  getOrCreateFaceInfo(const fib::Entry& fibEntry, const Interest& interest, FaceId faceId);
308 
310  getNamespaceInfo(const Name& prefix);
311 
313  getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Interest& interest);
314 
315 private:
316  void
317  extendLifetime(measurements::Entry& me);
318 
319 public:
320  static constexpr time::microseconds MEASUREMENTS_LIFETIME = time::seconds(300);
321 
322 private:
323  MeasurementsAccessor& m_measurements;
324 };
325 
326 } // namespace asf
327 } // namespace fw
328 } // namespace nfd
329 
330 #endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
Duration computeRto() const
time::microseconds Duration
Opaque handle for a scheduled event.
Helper class to retrieve and create strategy measurements.
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, FaceId faceId)
void recordRtt(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
void setMeasurementExpirationEventId(const scheduler::EventId &id)
generalization of a network interface
Definition: face.hpp:67
represents a FIB entry
Definition: fib-entry.hpp:51
void addRttMeasurement(RttEstimator::Duration &durationRtt)
RttEstimator::Duration computeRto() const
Error(const std::string &what)
RttEstimator::Duration computeRto() const
void extendFaceInfoLifetime(FaceInfo &info, FaceId faceId)
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Interest &interest, FaceId faceId)
const scheduler::EventId & getMeasurementExpirationEventId()
STL namespace.
AsfMeasurements(MeasurementsAccessor &measurements)
Represents an Interest packet.
Definition: interest.hpp:42
void setNSilentTimeouts(size_t nSilentTimeouts)
stores stategy information about each face in this namespace
static const Rtt RTT_TIMEOUT
FaceInfoTable::iterator end()
represents a Measurements entry
Table::const_iterator iterator
Definition: cs-internal.hpp:41
void expireFaceInfo(FaceId faceId)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
FaceInfoTable::iterator find(FaceId faceId)
static constexpr int getTypeId()
void setHasFirstProbeBeenScheduled(bool hasBeenScheduled)
void setIsProbingDue(bool isProbingDue)
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Interest &interest)
const FaceInfoTable::iterator insert(FaceId faceId)
static const Rtt RTT_NO_MEASUREMENT
static constexpr time::microseconds MEASUREMENTS_LIFETIME
RttStats::Rtt getRtt() const
Represents an absolute name.
Definition: name.hpp:42
void setTimeoutEvent(const scheduler::EventId &id, const Name &interestName)
Strategy information for each face in a namespace.
std::unordered_map< FaceId, FaceInfo > FaceInfoTable
allows Strategy to access portion of Measurements table under its namespace
NamespaceInfo * getNamespaceInfo(const Name &prefix)
RttStats::Rtt getSrtt() const
implements the Mean-Deviation RTT estimator
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, FaceId faceId)
void recordTimeout(const Name &interestName)
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, const Interest &interest, FaceId faceId)
uint64_t FaceId
identifies a face
Definition: face.hpp:39
contains arbitrary information forwarding strategy places on table entries
size_t getNSilentTimeouts() const
time::duration< double, boost::micro > Rtt