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-2021, 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 "fw/strategy-info.hpp"
31 
33 
34 namespace nfd {
35 namespace fw {
36 namespace asf {
37 
40 class FaceInfo
41 {
42 public:
43  explicit
44  FaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
45  : m_rttEstimator(std::move(opts))
46  {
47  }
48 
49  bool
51  {
52  return !!m_timeoutEvent;
53  }
54 
56  scheduleTimeout(const Name& interestName, scheduler::EventCallback cb);
57 
58  void
59  cancelTimeout(const Name& prefix);
60 
61  void
63  {
64  m_lastRtt = rtt;
65  m_rttEstimator.addMeasurement(rtt);
66  }
67 
68  void
69  recordTimeout(const Name& interestName)
70  {
71  m_lastRtt = RTT_TIMEOUT;
72  cancelTimeout(interestName);
73  }
74 
75  bool
76  hasTimeout() const
77  {
78  return getLastRtt() == RTT_TIMEOUT;
79  }
80 
82  getLastRtt() const
83  {
84  return m_lastRtt;
85  }
86 
88  getSrtt() const
89  {
90  return m_rttEstimator.getSmoothedRtt();
91  }
92 
93  size_t
94  getNTimeouts() const
95  {
96  return m_nTimeouts;
97  }
98 
99  void
100  setNTimeouts(size_t nTimeouts)
101  {
102  m_nTimeouts = nTimeouts;
103  }
104 
105 public:
108 
109 private:
110  ndn::util::RttEstimator m_rttEstimator;
112  Name m_lastInterestName;
113  size_t m_nTimeouts = 0;
114 
115  // Timeout associated with measurement
116  scheduler::ScopedEventId m_measurementExpiration;
117  friend class NamespaceInfo;
118 
119  // RTO associated with Interest
120  scheduler::ScopedEventId m_timeoutEvent;
121 };
122 
125 
128 class NamespaceInfo final : public StrategyInfo
129 {
130 public:
131  static constexpr int
133  {
134  return 1030;
135  }
136 
137  explicit
138  NamespaceInfo(shared_ptr<const ndn::util::RttEstimator::Options> opts)
139  : m_rttEstimatorOpts(std::move(opts))
140  {
141  }
142 
143  FaceInfo*
144  getFaceInfo(FaceId faceId);
145 
146  FaceInfo&
147  getOrCreateFaceInfo(FaceId faceId);
148 
149  void
150  extendFaceInfoLifetime(FaceInfo& info, FaceId faceId);
151 
152  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
166  {
167  return m_isFirstProbeScheduled;
168  }
169 
170  void
171  setIsFirstProbeScheduled(bool isScheduled)
172  {
173  m_isFirstProbeScheduled = isScheduled;
174  }
175 
176 private:
177  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;
181 };
182 
185 
188 class AsfMeasurements : noncopyable
189 {
190 public:
191  explicit
192  AsfMeasurements(MeasurementsAccessor& measurements);
193 
194  FaceInfo*
195  getFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId);
196 
197  FaceInfo&
198  getOrCreateFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId);
199 
201  getNamespaceInfo(const Name& prefix);
202 
204  getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Name& prefix);
205 
206 private:
207  void
208  extendLifetime(measurements::Entry& me);
209 
210 public:
211  static constexpr time::microseconds MEASUREMENTS_LIFETIME = 5_min;
212 
213 private:
214  MeasurementsAccessor& m_measurements;
215  shared_ptr<const ndn::util::RttEstimator::Options> m_rttEstimatorOpts;
216 };
217 
218 } // namespace asf
219 } // namespace fw
220 } // namespace nfd
221 
222 #endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
NamespaceInfo(shared_ptr< const ndn::util::RttEstimator::Options > opts)
Helper class to retrieve and create strategy measurements.
time::nanoseconds scheduleTimeout(const Name &interestName, scheduler::EventCallback cb)
static const time::nanoseconds RTT_TIMEOUT
RTT/RTO estimator.
std::function< void()> EventCallback
Function to be invoked when a scheduled event expires.
Definition: scheduler.hpp:45
represents a FIB entry
Definition: fib-entry.hpp:53
boost::chrono::microseconds microseconds
Definition: time.hpp:49
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
SignatureInfo info
STL namespace.
Stores strategy information about each face in this namespace.
void recordRtt(time::nanoseconds rtt)
FaceInfo(shared_ptr< const ndn::util::RttEstimator::Options > opts)
time::nanoseconds getLastRtt() const
Represents a Measurements entry.
void setIsFirstProbeScheduled(bool isScheduled)
void cancelTimeout(const Name &prefix)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
static constexpr int getTypeId()
void setIsProbingDue(bool isProbingDue)
Represents an absolute name.
Definition: name.hpp:41
void setNTimeouts(size_t nTimeouts)
Strategy information for each face in a namespace.
allows Strategy to access portion of Measurements table under its namespace
time::nanoseconds getSmoothedRtt() const
Returns the smoothed RTT value (SRTT).
time::nanoseconds getSrtt() const
void recordTimeout(const Name &interestName)
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:44
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
Contains arbitrary information placed by the forwarding strategy on table entries.
static const time::nanoseconds RTT_NO_MEASUREMENT