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-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 #include "asf-measurements.hpp"
27 #include "common/global.hpp"
28 
29 namespace nfd {
30 namespace fw {
31 namespace asf {
32 
33 const time::nanoseconds FaceInfo::RTT_NO_MEASUREMENT{-1};
34 const time::nanoseconds FaceInfo::RTT_TIMEOUT{-2};
35 
36 time::nanoseconds
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 
86 constexpr time::microseconds AsfMeasurements::MEASUREMENTS_LIFETIME;
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 Interest& interest, FaceId faceId)
96 {
97  return getOrCreateNamespaceInfo(fibEntry, interest).getFaceInfo(faceId);
98 }
99 
100 FaceInfo&
102  FaceId faceId)
103 {
104  return getOrCreateNamespaceInfo(fibEntry, interest).getOrCreateFaceInfo(faceId);
105 }
106 
109 {
110  measurements::Entry* me = m_measurements.findLongestPrefixMatch(prefix);
111  if (me == nullptr) {
112  return nullptr;
113  }
114 
115  // Set or update entry lifetime
116  extendLifetime(*me);
117 
118  NamespaceInfo* info = me->insertStrategyInfo<NamespaceInfo>(m_rttEstimatorOpts).first;
119  BOOST_ASSERT(info != nullptr);
120  return info;
121 }
122 
125 {
126  measurements::Entry* me = m_measurements.get(fibEntry);
127 
128  // If the FIB entry is not under the strategy's namespace, find a part of the prefix
129  // that falls under the strategy's namespace
130  for (size_t prefixLen = fibEntry.getPrefix().size() + 1;
131  me == nullptr && prefixLen <= interest.getName().size(); ++prefixLen) {
132  me = m_measurements.get(interest.getName().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
global.hpp
ndn::detail::ScopedCancelHandle::cancel
void cancel()
Cancel the operation.
Definition: cancel-handle.hpp:109
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:421
asf-measurements.hpp
ndn::Name::isPrefixOf
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Definition: name.cpp:299
nfd::fw::asf::FaceInfo::RTT_NO_MEASUREMENT
static const time::nanoseconds RTT_NO_MEASUREMENT
Definition: asf-measurements.hpp:106
ndn::Name::size
size_t size() const
Returns the number of components.
Definition: name.hpp:153
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::measurements::MeasurementsAccessor::extendLifetime
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
Definition: measurements-accessor.hpp:166
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::face::FaceId
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:44
ndn::scheduler::EventCallback
std::function< void()> EventCallback
Function to be invoked when a scheduled event expires.
Definition: scheduler.hpp:45
nfd::getScheduler
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
Definition: global.cpp:70
ndn::Name::getPrefix
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
Definition: name.hpp:211
nfd::fw::asf::FaceInfo::scheduleTimeout
time::nanoseconds scheduleTimeout(const Name &interestName, scheduler::EventCallback cb)
Definition: asf-measurements.cpp:37
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
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
nfd::measurements::MeasurementsAccessor::get
Entry * get(const Name &name)
find or insert a Measurements entry for name
Definition: measurements-accessor.hpp:122
nfd::fw::asf::FaceInfo
Strategy information for each face in a namespace.
Definition: asf-measurements.hpp:41
nfd::measurements::MeasurementsAccessor::findLongestPrefixMatch
Entry * findLongestPrefixMatch(const Name &name, const EntryPredicate &pred=AnyEntry()) const
perform a longest prefix match for name
Definition: measurements-accessor.hpp:146
ndn::util::RttEstimator::getEstimatedRto
time::nanoseconds getEstimatedRto() const
Returns the estimated RTO value.
Definition: rtt-estimator.hpp:83
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
nfd::StrategyInfoHost::insertStrategyInfo
std::pair< T *, bool > insertStrategyInfo(A &&... args)
Insert a StrategyInfo item.
Definition: strategy-info-host.hpp:63
nfd::fw::asf::NamespaceInfo
Stores strategy information about each face in this namespace.
Definition: asf-measurements.hpp:129
nfd::measurements::Entry
Represents a Measurements entry.
Definition: measurements-entry.hpp:42
RttEstimator
ndn RttEstimator
Definition: ndn-rtt-estimator.cpp:38
ndn::Interest::getName
const Name & getName() const noexcept
Definition: interest.hpp:121
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
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
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
nfd::fib::Entry::getPrefix
const Name & getPrefix() const
Definition: fib-entry.hpp:60