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-2024, 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 "face/face-common.hpp"
30 #include "fw/strategy-info.hpp"
32 
33 #include <ndn-cxx/util/rtt-estimator.hpp>
34 
35 #include <unordered_map>
36 
37 namespace nfd::fw::asf {
38 
42 class FaceInfo
43 {
44 public:
45  explicit
46  FaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
47  : m_rttEstimator(std::move(opts))
48  {
49  }
50 
51  bool
53  {
54  return !!m_timeoutEvent;
55  }
56 
57  time::nanoseconds
58  scheduleTimeout(const Name& interestName, ndn::scheduler::EventCallback cb);
59 
60  void
61  cancelTimeout(const Name& prefix);
62 
63  void
64  recordRtt(time::nanoseconds rtt)
65  {
66  m_lastRtt = rtt;
67  m_rttEstimator.addMeasurement(rtt);
68  }
69 
70  void
71  recordTimeout(const Name& interestName)
72  {
73  m_lastRtt = RTT_TIMEOUT;
74  cancelTimeout(interestName);
75  }
76 
77  time::nanoseconds
78  getLastRtt() const
79  {
80  return m_lastRtt;
81  }
82 
83  time::nanoseconds
84  getSrtt() const
85  {
86  return m_rttEstimator.getSmoothedRtt();
87  }
88 
89  size_t
90  getNTimeouts() const
91  {
92  return m_nTimeouts;
93  }
94 
95  void
96  setNTimeouts(size_t nTimeouts)
97  {
98  m_nTimeouts = nTimeouts;
99  }
100 
101 public:
102  static constexpr time::nanoseconds RTT_NO_MEASUREMENT = -1_ns;
103  static constexpr time::nanoseconds RTT_TIMEOUT = -2_ns;
104 
105 private:
106  ndn::util::RttEstimator m_rttEstimator;
107  time::nanoseconds m_lastRtt = RTT_NO_MEASUREMENT;
108  Name m_lastInterestName;
109  size_t m_nTimeouts = 0;
110 
111  // Timeout associated with measurement
112  ndn::scheduler::ScopedEventId m_measurementExpiration;
113  friend class NamespaceInfo;
114 
115  // RTO associated with Interest
116  ndn::scheduler::ScopedEventId m_timeoutEvent;
117 };
118 
121 
125 class NamespaceInfo final : public StrategyInfo
126 {
127 public:
128  static constexpr int
130  {
131  return 1030;
132  }
133 
134  explicit
135  NamespaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
136  : m_rttEstimatorOpts(std::move(opts))
137  {
138  }
139 
140  FaceInfo*
141  getFaceInfo(FaceId faceId);
142 
143  FaceInfo&
144  getOrCreateFaceInfo(FaceId faceId);
145 
146  void
147  extendFaceInfoLifetime(FaceInfo& info, FaceId faceId);
148 
149  bool
150  isProbingDue() const
151  {
152  return m_isProbingDue;
153  }
154 
155  void
157  {
158  m_isProbingDue = isProbingDue;
159  }
160 
161  bool
163  {
164  return m_isFirstProbeScheduled;
165  }
166 
167  void
168  setIsFirstProbeScheduled(bool isScheduled)
169  {
170  m_isFirstProbeScheduled = isScheduled;
171  }
172 
173 private:
174  std::unordered_map<FaceId, FaceInfo> m_fiMap;
175  shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts;
176  bool m_isProbingDue = false;
177  bool m_isFirstProbeScheduled = false;
178 };
179 
182 
186 class AsfMeasurements : noncopyable
187 {
188 public:
189  explicit
190  AsfMeasurements(MeasurementsAccessor& measurements);
191 
192  FaceInfo*
193  getFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId);
194 
195  FaceInfo&
196  getOrCreateFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId);
197 
199  getNamespaceInfo(const Name& prefix);
200 
202  getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Name& prefix);
203 
204 private:
205  void
206  extendLifetime(measurements::Entry& me);
207 
208 public:
209  static constexpr time::microseconds MEASUREMENTS_LIFETIME = 5_min;
210 
211 private:
212  MeasurementsAccessor& m_measurements;
213  shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts;
214 };
215 
216 } // namespace nfd::fw::asf
217 
218 #endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
Represents an entry in the FIB.
Definition: fib-entry.hpp:91
Contains arbitrary information placed by the forwarding strategy on table entries.
Helper class to retrieve and create strategy measurements.
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Name &prefix)
AsfMeasurements(MeasurementsAccessor &measurements)
static constexpr time::microseconds MEASUREMENTS_LIFETIME
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Name &interestName, FaceId faceId)
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, const Name &interestName, FaceId faceId)
NamespaceInfo * getNamespaceInfo(const Name &prefix)
Strategy information for each face in a namespace.
static constexpr time::nanoseconds RTT_TIMEOUT
void cancelTimeout(const Name &prefix)
time::nanoseconds scheduleTimeout(const Name &interestName, ndn::scheduler::EventCallback cb)
static constexpr time::nanoseconds RTT_NO_MEASUREMENT
time::nanoseconds getSrtt() const
void setNTimeouts(size_t nTimeouts)
time::nanoseconds getLastRtt() const
FaceInfo(shared_ptr< const ndn::util::RttEstimator::Options > opts)
void recordTimeout(const Name &interestName)
void recordRtt(time::nanoseconds rtt)
Stores strategy information about each face in this namespace.
NamespaceInfo(shared_ptr< const ndn::util::RttEstimator::Options > opts)
void setIsFirstProbeScheduled(bool isScheduled)
FaceInfo * getFaceInfo(FaceId faceId)
static constexpr int getTypeId()
void extendFaceInfoLifetime(FaceInfo &info, FaceId faceId)
FaceInfo & getOrCreateFaceInfo(FaceId faceId)
void setIsProbingDue(bool isProbingDue)
Represents an entry in the Measurements table.
Allows fw::Strategy to access the portion of Measurements table under its namespace.
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:48