Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 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" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 27 | #include "common/global.hpp" |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 28 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 29 | namespace nfd::fw::asf { |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 30 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 31 | time::nanoseconds |
| 32 | FaceInfo::scheduleTimeout(const Name& interestName, scheduler::EventCallback cb) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 33 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 34 | BOOST_ASSERT(!m_timeoutEvent); |
| 35 | m_lastInterestName = interestName; |
| 36 | m_timeoutEvent = getScheduler().schedule(m_rttEstimator.getEstimatedRto(), std::move(cb)); |
| 37 | return m_rttEstimator.getEstimatedRto(); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 41 | FaceInfo::cancelTimeout(const Name& prefix) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 42 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 43 | if (m_lastInterestName.isPrefixOf(prefix)) { |
| 44 | m_timeoutEvent.cancel(); |
| 45 | } |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | //////////////////////////////////////////////////////////////////////////////// |
| 49 | //////////////////////////////////////////////////////////////////////////////// |
| 50 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 51 | FaceInfo* |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 52 | NamespaceInfo::getFaceInfo(FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 53 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 54 | auto it = m_fiMap.find(faceId); |
| 55 | return it != m_fiMap.end() ? &it->second : nullptr; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | FaceInfo& |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 59 | NamespaceInfo::getOrCreateFaceInfo(FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 60 | { |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 61 | auto [it, isNew] = m_fiMap.try_emplace(faceId, m_rttEstimatorOpts); |
| 62 | auto& faceInfo = it->second; |
| 63 | if (isNew) { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 64 | extendFaceInfoLifetime(faceInfo, faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 65 | } |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 66 | return faceInfo; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void |
Ashlesh Gawande | 92e4ea5 | 2017-07-19 11:38:12 -0500 | [diff] [blame] | 70 | NamespaceInfo::extendFaceInfoLifetime(FaceInfo& info, FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 71 | { |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 72 | info.m_measurementExpiration = getScheduler().schedule(AsfMeasurements::MEASUREMENTS_LIFETIME, |
| 73 | [=] { m_fiMap.erase(faceId); }); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | //////////////////////////////////////////////////////////////////////////////// |
| 77 | //////////////////////////////////////////////////////////////////////////////// |
| 78 | |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 79 | AsfMeasurements::AsfMeasurements(MeasurementsAccessor& measurements) |
| 80 | : m_measurements(measurements) |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 81 | , m_rttEstimatorOpts(make_shared<ndn::util::RttEstimator::Options>()) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 82 | { |
| 83 | } |
| 84 | |
| 85 | FaceInfo* |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 86 | AsfMeasurements::getFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 87 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 88 | return getOrCreateNamespaceInfo(fibEntry, interestName).getFaceInfo(faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | FaceInfo& |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 92 | AsfMeasurements::getOrCreateFaceInfo(const fib::Entry& fibEntry, const Name& interestName, FaceId faceId) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 93 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 94 | return getOrCreateNamespaceInfo(fibEntry, interestName).getOrCreateFaceInfo(faceId); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 97 | NamespaceInfo* |
| 98 | AsfMeasurements::getNamespaceInfo(const Name& prefix) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 99 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 100 | auto* me = m_measurements.findLongestPrefixMatch(prefix); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 101 | if (me == nullptr) { |
| 102 | return nullptr; |
| 103 | } |
| 104 | |
| 105 | // Set or update entry lifetime |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 106 | extendLifetime(*me); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 107 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 108 | NamespaceInfo* info = me->insertStrategyInfo<NamespaceInfo>(m_rttEstimatorOpts).first; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 109 | BOOST_ASSERT(info != nullptr); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 110 | return info; |
| 111 | } |
| 112 | |
| 113 | NamespaceInfo& |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 114 | AsfMeasurements::getOrCreateNamespaceInfo(const fib::Entry& fibEntry, const Name& prefix) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 115 | { |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 116 | auto* me = m_measurements.get(fibEntry); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 117 | |
| 118 | // If the FIB entry is not under the strategy's namespace, find a part of the prefix |
| 119 | // that falls under the strategy's namespace |
| 120 | for (size_t prefixLen = fibEntry.getPrefix().size() + 1; |
Saurab Dulal | 432be57 | 2021-01-26 12:09:29 -0600 | [diff] [blame] | 121 | me == nullptr && prefixLen <= prefix.size(); |
| 122 | ++prefixLen) { |
| 123 | me = m_measurements.get(prefix.getPrefix(prefixLen)); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | // Either the FIB entry or the Interest's name must be under this strategy's namespace |
| 127 | BOOST_ASSERT(me != nullptr); |
| 128 | |
| 129 | // Set or update entry lifetime |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 130 | extendLifetime(*me); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 131 | |
Davide Pesavento | a6f637a | 2019-08-28 23:23:20 -0400 | [diff] [blame] | 132 | NamespaceInfo* info = me->insertStrategyInfo<NamespaceInfo>(m_rttEstimatorOpts).first; |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 133 | BOOST_ASSERT(info != nullptr); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 134 | return *info; |
| 135 | } |
| 136 | |
| 137 | void |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 138 | AsfMeasurements::extendLifetime(measurements::Entry& me) |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 139 | { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 140 | m_measurements.extendLifetime(me, MEASUREMENTS_LIFETIME); |
Vince Lehman | 8a4c29e | 2016-07-11 08:49:35 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 143 | } // namespace nfd::fw::asf |