NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
asf-measurements.cpp
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 #include "asf-measurements.hpp"
27 #include "common/global.hpp"
28 
29 namespace nfd {
30 namespace fw {
31 namespace asf {
32 
35 
38 {
39  BOOST_ASSERT(!m_timeoutEvent);
40  m_lastInterestName = interestName;
41  m_timeoutEvent = getScheduler().schedule(m_rttEstimator.getEstimatedRto(), std::move(cb));
42  return m_rttEstimator.getEstimatedRto();
43 }
44 
45 void
47 {
48  if (m_lastInterestName.isPrefixOf(prefix)) {
49  m_timeoutEvent.cancel();
50  }
51 }
52 
55 
56 FaceInfo*
58 {
59  auto it = m_fiMap.find(faceId);
60  return it != m_fiMap.end() ? &it->second : nullptr;
61 }
62 
63 FaceInfo&
65 {
66  auto ret = m_fiMap.emplace(std::piecewise_construct,
67  std::forward_as_tuple(faceId),
68  std::forward_as_tuple(m_rttEstimatorOpts));
69  auto& faceInfo = ret.first->second;
70  if (ret.second) {
71  extendFaceInfoLifetime(faceInfo, faceId);
72  }
73  return faceInfo;
74 }
75 
76 void
78 {
79  info.m_measurementExpiration = getScheduler().schedule(AsfMeasurements::MEASUREMENTS_LIFETIME,
80  [=] { m_fiMap.erase(faceId); });
81 }
82 
85 
87 
89  : m_measurements(measurements)
90  , m_rttEstimatorOpts(make_shared<ndn::util::RttEstimator::Options>())
91 {
92 }
93 
94 FaceInfo*
95 AsfMeasurements::getFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId)
96 {
97  return getOrCreateNamespaceInfo(fibEntry, interestName).getFaceInfo(faceId);
98 }
99 
100 FaceInfo&
101 AsfMeasurements::getOrCreateFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId)
102 {
103  return getOrCreateNamespaceInfo(fibEntry, interestName).getOrCreateFaceInfo(faceId);
104 }
105 
108 {
109  auto* me = m_measurements.findLongestPrefixMatch(prefix);
110  if (me == nullptr) {
111  return nullptr;
112  }
113 
114  // Set or update entry lifetime
115  extendLifetime(*me);
116 
117  NamespaceInfo* info = me->insertStrategyInfo<NamespaceInfo>(m_rttEstimatorOpts).first;
118  BOOST_ASSERT(info != nullptr);
119  return info;
120 }
121 
124 {
125  auto* me = m_measurements.get(fibEntry);
126 
127  // If the FIB entry is not under the strategy's namespace, find a part of the prefix
128  // that falls under the strategy's namespace
129  for (size_t prefixLen = fibEntry.getPrefix().size() + 1;
130  me == nullptr && prefixLen <= prefix.size();
131  ++prefixLen) {
132  me = m_measurements.get(prefix.getPrefix(prefixLen));
133  }
134 
135  // Either the FIB entry or the Interest's name must be under this strategy's namespace
136  BOOST_ASSERT(me != nullptr);
137 
138  // Set or update entry lifetime
139  extendLifetime(*me);
140 
141  NamespaceInfo* info = me->insertStrategyInfo<NamespaceInfo>(m_rttEstimatorOpts).first;
142  BOOST_ASSERT(info != nullptr);
143  return *info;
144 }
145 
146 void
147 AsfMeasurements::extendLifetime(measurements::Entry& me)
148 {
149  m_measurements.extendLifetime(me, MEASUREMENTS_LIFETIME);
150 }
151 
152 } // namespace asf
153 } // namespace fw
154 } // namespace nfd
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
Definition: name.hpp:209
const Name & getPrefix() const
Definition: fib-entry.hpp:60
Copyright (c) 2011-2015 Regents of the University of California.
time::nanoseconds getEstimatedRto() const
Returns the estimated RTO value.
time::nanoseconds scheduleTimeout(const Name &interestName, scheduler::EventCallback cb)
static const time::nanoseconds RTT_TIMEOUT
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
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Definition: name.cpp:300
void extendFaceInfoLifetime(FaceInfo &info, FaceId faceId)
boost::chrono::microseconds microseconds
Definition: time.hpp:49
SignatureInfo info
AsfMeasurements(MeasurementsAccessor &measurements)
Stores strategy information about each face in this namespace.
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
Entry * findLongestPrefixMatch(const Name &name, const EntryPredicate &pred=AnyEntry()) const
perform a longest prefix match for name
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Name &interestName, FaceId faceId)
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
Definition: global.cpp:70
Represents a Measurements entry.
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, const Name &interestName, FaceId faceId)
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Name &prefix)
void cancelTimeout(const Name &prefix)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
static constexpr time::microseconds MEASUREMENTS_LIFETIME
Represents an absolute name.
Definition: name.hpp:41
Strategy information for each face in a namespace.
size_t size() const
Returns the number of components.
Definition: name.hpp:151
FaceInfo * getFaceInfo(FaceId faceId)
allows Strategy to access portion of Measurements table under its namespace
NamespaceInfo * getNamespaceInfo(const Name &prefix)
void cancel()
Cancel the operation.
Entry * get(const Name &name)
find or insert a Measurements entry for name
ndn RttEstimator
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:44
FaceInfo & getOrCreateFaceInfo(FaceId faceId)
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
static const time::nanoseconds RTT_NO_MEASUREMENT