NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
26 #ifndef NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
27 #define NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
28 
29 #include "fw/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 private:
170  void
171  cancelTimeoutEvent();
172 
173  bool
174  doesNameMatchLastInterest(const Name& name);
175 
176 private:
177  RttStats m_rttStats;
178  Name m_lastInterestName;
179 
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 
188 typedef std::unordered_map<face::FaceId, FaceInfo> FaceInfoTable;
189 
192 
196 {
197 public:
198  NamespaceInfo();
199 
200  static constexpr int
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 
218  FaceInfo&
219  get(nfd::face::FaceId faceId)
220  {
221  return m_fit.at(faceId);
222  }
223 
226  {
227  return m_fit.find(faceId);
228  }
229 
231  end()
232  {
233  return m_fit.end();
234  }
235 
238  {
239  const auto& pair = m_fit.insert(std::make_pair(faceId, FaceInfo()));
240  return pair.first;
241  }
242 
243  bool
244  isProbingDue() const
245  {
246  return m_isProbingDue;
247  }
248 
249  void
250  setIsProbingDue(bool isProbingDue)
251  {
252  m_isProbingDue = isProbingDue;
253  }
254 
255  bool
257  {
258  return m_hasFirstProbeBeenScheduled;
259  }
260 
261  void
262  setHasFirstProbeBeenScheduled(bool hasBeenScheduled)
263  {
264  m_hasFirstProbeBeenScheduled = hasBeenScheduled;
265  }
266 
267 private:
268  FaceInfoTable m_fit;
269 
270  bool m_isProbingDue;
271  bool m_hasFirstProbeBeenScheduled;
272 };
273 
276 
279 class AsfMeasurements : noncopyable
280 {
281 public:
282  explicit
283  AsfMeasurements(MeasurementsAccessor& measurements);
284 
285  FaceInfo*
286  getFaceInfo(const fib::Entry& fibEntry, const Interest& interest, const Face& face);
287 
288  FaceInfo&
289  getOrCreateFaceInfo(const fib::Entry& fibEntry, const Interest& interest, const Face& face);
290 
292  getNamespaceInfo(const Name& prefix);
293 
295  getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Interest& interest);
296 
297 private:
298  void
299  extendLifetime(measurements::Entry& me);
300 
301 public:
302  static constexpr time::microseconds MEASUREMENTS_LIFETIME = time::seconds(300);
303 
304 private:
305  MeasurementsAccessor& m_measurements;
306 };
307 
308 } // namespace asf
309 } // namespace fw
310 } // namespace nfd
311 
312 #endif // NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
Duration computeRto() const
time::microseconds Duration
Helper class to retrieve and create strategy measurements.
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
const scheduler::EventId & getMeasurementExpirationEventId()
STL namespace.
represents an Interest packet
Definition: interest.hpp:42
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
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:39
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
static constexpr int getTypeId()
void setHasFirstProbeBeenScheduled(bool hasBeenScheduled)
FaceInfoTable::iterator find(nfd::face::FaceId faceId)
void setIsProbingDue(bool isProbingDue)
static const Rtt RTT_NO_MEASUREMENT
RttStats::Rtt getRtt() const
Name abstraction to represent an absolute name.
Definition: name.hpp:46
Strategy information for each face in a namespace.
const FaceInfoTable::iterator insert(nfd::face::FaceId faceId)
allows Strategy to access portion of Measurements table under its namespace
RttStats::Rtt getSrtt() const
implements the Mean-Deviation RTT estimator
uint64_t FaceId
identifies a face
Definition: face.hpp:39
contains arbitrary information forwarding strategy places on table entries
time::duration< double, boost::micro > Rtt
std::unordered_map< face::FaceId, FaceInfo > FaceInfoTable