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-2019, 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 
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);
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 
81  time::nanoseconds
82  getLastRtt() const
83  {
84  return m_lastRtt;
85  }
86 
87  time::nanoseconds
88  getSrtt() const
89  {
90  return m_rttEstimator.getSmoothedRtt();
91  }
92 
93  size_t
95  {
96  return m_nSilentTimeouts;
97  }
98 
99  void
100  setNSilentTimeouts(size_t nSilentTimeouts)
101  {
102  m_nSilentTimeouts = nSilentTimeouts;
103  }
104 
105 public:
106  static const time::nanoseconds RTT_NO_MEASUREMENT;
107  static const time::nanoseconds RTT_TIMEOUT;
108 
109 private:
110  ndn::util::RttEstimator m_rttEstimator;
111  time::nanoseconds m_lastRtt = RTT_NO_MEASUREMENT;
112  Name m_lastInterestName;
113  size_t m_nSilentTimeouts = 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 
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
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 Interest& interest, FaceId faceId);
196 
197  FaceInfo&
198  getOrCreateFaceInfo(const fib::Entry& fibEntry, const Interest& interest, FaceId faceId);
199 
201  getNamespaceInfo(const Name& prefix);
202 
204  getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Interest& interest);
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
nfd::fw::asf::NamespaceInfo::NamespaceInfo
NamespaceInfo(shared_ptr< const ndn::util::RttEstimator::Options > opts)
Definition: asf-measurements.hpp:138
nfd::fw::asf::NamespaceInfo::setIsProbingDue
void setIsProbingDue(bool isProbingDue)
Definition: asf-measurements.hpp:159
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:421
nfd::fw::asf::FaceInfo::RTT_NO_MEASUREMENT
static const time::nanoseconds RTT_NO_MEASUREMENT
Definition: asf-measurements.hpp:106
nfd::fw::asf::FaceInfo::recordTimeout
void recordTimeout(const Name &interestName)
Definition: asf-measurements.hpp:69
nfd::fw::asf::FaceInfo::getNSilentTimeouts
size_t getNSilentTimeouts() const
Definition: asf-measurements.hpp:94
rtt-estimator.hpp
nfd::fw::asf::AsfMeasurements
Helper class to retrieve and create strategy measurements.
Definition: asf-measurements.hpp:189
nfd::fw::asf::FaceInfo::hasTimeout
bool hasTimeout() const
Definition: asf-measurements.hpp:76
nfd::fw::asf::AsfMeasurements::getOrCreateFaceInfo
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Interest &interest, FaceId faceId)
Definition: asf-measurements.cpp:101
nfd::measurements::MeasurementsAccessor
allows Strategy to access portion of Measurements table under its namespace
Definition: measurements-accessor.hpp:46
nfd::fw::asf::NamespaceInfo::getTypeId
static constexpr int getTypeId()
Definition: asf-measurements.hpp:132
measurements-accessor.hpp
nfd::fw::asf::AsfMeasurements::MEASUREMENTS_LIFETIME
static constexpr time::microseconds MEASUREMENTS_LIFETIME
Definition: asf-measurements.hpp:211
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
nfd::fw::asf::FaceInfo::FaceInfo
FaceInfo(shared_ptr< const ndn::util::RttEstimator::Options > opts)
Definition: asf-measurements.hpp:44
nfd::fw::asf::FaceInfo::getLastRtt
time::nanoseconds getLastRtt() const
Definition: asf-measurements.hpp:82
nfd::fw::StrategyInfo
contains arbitrary information forwarding strategy places on table entries
Definition: strategy-info.hpp:37
nfd::face::FaceId
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:44
nfd::fw::asf::FaceInfo::setNSilentTimeouts
void setNSilentTimeouts(size_t nSilentTimeouts)
Definition: asf-measurements.hpp:100
ndn::scheduler::EventCallback
std::function< void()> EventCallback
Function to be invoked when a scheduled event expires.
Definition: scheduler.hpp:45
nfd::fw::asf::NamespaceInfo::setIsFirstProbeScheduled
void setIsFirstProbeScheduled(bool isScheduled)
Definition: asf-measurements.hpp:171
nfd::fw::asf::FaceInfo::scheduleTimeout
time::nanoseconds scheduleTimeout(const Name &interestName, scheduler::EventCallback cb)
Definition: asf-measurements.cpp:37
nfd::fw::asf::NamespaceInfo::isProbingDue
bool isProbingDue() const
Definition: asf-measurements.hpp:153
nfd::fw::asf::NamespaceInfo::isFirstProbeScheduled
bool isFirstProbeScheduled() const
Definition: asf-measurements.hpp:165
nfd::fw::asf::AsfMeasurements::getOrCreateNamespaceInfo
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Interest &interest)
Definition: asf-measurements.cpp:124
nfd::fw::asf::NamespaceInfo::getFaceInfo
FaceInfo * getFaceInfo(FaceId faceId)
Definition: asf-measurements.cpp:57
nfd::fw::asf::AsfMeasurements::getFaceInfo
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, const Interest &interest, FaceId faceId)
Definition: asf-measurements.cpp:95
nfd::fw::asf::AsfMeasurements::getNamespaceInfo
NamespaceInfo * getNamespaceInfo(const Name &prefix)
Definition: asf-measurements.cpp:108
nfd::fw::asf::FaceInfo::getSrtt
time::nanoseconds getSrtt() const
Definition: asf-measurements.hpp:88
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
nfd::fw::asf::FaceInfo
Strategy information for each face in a namespace.
Definition: asf-measurements.hpp:41
nfd::fib::Entry
represents a FIB entry
Definition: fib-entry.hpp:54
nfd::fw::asf::NamespaceInfo::extendFaceInfoLifetime
void extendFaceInfoLifetime(FaceInfo &info, FaceId faceId)
Definition: asf-measurements.cpp:77
ndn::util::RttEstimator::addMeasurement
void addMeasurement(time::nanoseconds rtt, size_t nExpectedSamples=1)
Records a new RTT measurement.
Definition: rtt-estimator.cpp:46
nfd::fw::asf::NamespaceInfo
Stores strategy information about each face in this namespace.
Definition: asf-measurements.hpp:129
nfd::fw::asf::FaceInfo::recordRtt
void recordRtt(time::nanoseconds rtt)
Definition: asf-measurements.hpp:62
nfd::measurements::Entry
Represents a Measurements entry.
Definition: measurements-entry.hpp:42
ndn::util::RttEstimator
RTT/RTO estimator.
Definition: rtt-estimator.hpp:42
nfd::fw::asf::FaceInfo::RTT_TIMEOUT
static const time::nanoseconds RTT_TIMEOUT
Definition: asf-measurements.hpp:107
nfd::fw::asf::NamespaceInfo::getOrCreateFaceInfo
FaceInfo & getOrCreateFaceInfo(FaceId faceId)
Definition: asf-measurements.cpp:64
ndn::util::RttEstimator::getSmoothedRtt
time::nanoseconds getSmoothedRtt() const
Returns the smoothed RTT value (SRTT).
Definition: rtt-estimator.hpp:93
strategy-info.hpp
nfd::fw::asf::AsfMeasurements::AsfMeasurements
AsfMeasurements(MeasurementsAccessor &measurements)
Definition: asf-measurements.cpp:88
nfd::fw::asf::FaceInfo::cancelTimeout
void cancelTimeout(const Name &prefix)
Definition: asf-measurements.cpp:46
ndn::detail::ScopedCancelHandle< EventId >
nfd::fw::asf::FaceInfo::isTimeoutScheduled
bool isTimeoutScheduled() const
Definition: asf-measurements.hpp:50