Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -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, |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [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 "access-strategy.hpp" |
Junxiao Shi | 00dc914 | 2016-11-21 14:23:12 +0000 | [diff] [blame] | 27 | #include "algorithm.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 28 | #include "common/global.hpp" |
| 29 | #include "common/logger.hpp" |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 31 | namespace nfd::fw { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 33 | NFD_LOG_INIT(AccessStrategy); |
Junxiao Shi | faf3eb0 | 2015-02-16 10:50:36 -0700 | [diff] [blame] | 34 | NFD_REGISTER_STRATEGY(AccessStrategy); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 35 | |
| 36 | AccessStrategy::AccessStrategy(Forwarder& forwarder, const Name& name) |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 37 | : Strategy(forwarder) |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 38 | , m_rttEstimatorOpts(make_shared<RttEstimator::Options>()) // use the default options |
| 39 | , m_removeFaceConn(beforeRemoveFace.connect([this] (const Face& face) { m_fit.erase(face.getId()); })) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 40 | { |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 41 | ParsedInstanceName parsed = parseInstanceName(name); |
| 42 | if (!parsed.parameters.empty()) { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 43 | NDN_THROW(std::invalid_argument("AccessStrategy does not accept parameters")); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 44 | } |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 45 | if (parsed.version && *parsed.version != getStrategyName()[-1].toVersion()) { |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 46 | NDN_THROW(std::invalid_argument("AccessStrategy does not support version " + to_string(*parsed.version))); |
Junxiao Shi | 91f6ee0 | 2016-12-29 21:44:44 +0000 | [diff] [blame] | 47 | } |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 48 | this->setInstanceName(makeInstanceName(name, getStrategyName())); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 51 | const Name& |
| 52 | AccessStrategy::getStrategyName() |
| 53 | { |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 54 | static const auto strategyName = Name("/localhost/nfd/strategy/access").appendVersion(1); |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 55 | return strategyName; |
| 56 | } |
| 57 | |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 58 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 59 | AccessStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 60 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 61 | { |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 62 | switch (auto res = m_retxSuppression.decidePerPitEntry(*pitEntry); res) { |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 63 | case RetxSuppressionResult::NEW: |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 64 | return afterReceiveNewInterest(interest, ingress, pitEntry); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 65 | case RetxSuppressionResult::FORWARD: |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 66 | return afterReceiveRetxInterest(interest, ingress, pitEntry); |
Ashlesh Gawande | 9001599 | 2017-07-11 17:25:48 -0500 | [diff] [blame] | 67 | case RetxSuppressionResult::SUPPRESS: |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 68 | NFD_LOG_DEBUG(interest << " interestFrom " << ingress << " retx-suppress"); |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 69 | return; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 74 | AccessStrategy::afterReceiveNewInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 75 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 76 | { |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 77 | const auto& fibEntry = this->lookupFib(*pitEntry); |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 78 | auto [miName, mi] = this->findPrefixMeasurements(*pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 79 | |
| 80 | // has measurements for Interest Name? |
| 81 | if (mi != nullptr) { |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 82 | NFD_LOG_DEBUG(interest << " interestFrom " << ingress << " new-interest mi=" << miName); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 83 | |
| 84 | // send to last working nexthop |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 85 | bool isSentToLastNexthop = this->sendToLastNexthop(interest, ingress, pitEntry, *mi, fibEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 86 | if (isSentToLastNexthop) { |
| 87 | return; |
| 88 | } |
| 89 | } |
| 90 | else { |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 91 | NFD_LOG_DEBUG(interest << " interestFrom " << ingress << " new-interest no-mi"); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // no measurements, or last working nexthop unavailable |
| 95 | |
Junxiao Shi | 965d3a4 | 2015-06-01 06:55:23 -0700 | [diff] [blame] | 96 | // multicast to all nexthops except incoming face |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 97 | size_t nMulticastSent = this->multicast(interest, ingress.face, pitEntry, fibEntry); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 98 | |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 99 | if (nMulticastSent == 0) { |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 100 | this->rejectPendingInterest(pitEntry); |
| 101 | } |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 105 | AccessStrategy::afterReceiveRetxInterest(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 106 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 107 | { |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 108 | const auto& fibEntry = this->lookupFib(*pitEntry); |
| 109 | NFD_LOG_DEBUG(interest << " interestFrom " << ingress << " retx-forward"); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 110 | this->multicast(interest, ingress.face, pitEntry, fibEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | bool |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 114 | AccessStrategy::sendToLastNexthop(const Interest& interest, const FaceEndpoint& ingress, |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 115 | const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi, |
| 116 | const fib::Entry& fibEntry) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 117 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 118 | if (mi.lastNexthop == face::INVALID_FACEID) { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 119 | NFD_LOG_DEBUG(pitEntry->getInterest() << " no-last-nexthop"); |
| 120 | return false; |
| 121 | } |
| 122 | |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 123 | if (mi.lastNexthop == ingress.face.getId()) { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 124 | NFD_LOG_DEBUG(pitEntry->getInterest() << " last-nexthop-is-downstream"); |
| 125 | return false; |
| 126 | } |
| 127 | |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 128 | Face* outFace = this->getFace(mi.lastNexthop); |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 129 | if (outFace == nullptr || !fibEntry.hasNextHop(*outFace)) { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 130 | NFD_LOG_DEBUG(pitEntry->getInterest() << " last-nexthop-gone"); |
| 131 | return false; |
| 132 | } |
| 133 | |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 134 | if (wouldViolateScope(ingress.face, interest, *outFace)) { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 135 | NFD_LOG_DEBUG(pitEntry->getInterest() << " last-nexthop-violates-scope"); |
| 136 | return false; |
| 137 | } |
| 138 | |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 139 | auto rto = mi.rtt.getEstimatedRto(); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 140 | NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << mi.lastNexthop |
| 141 | << " last-nexthop rto=" << time::duration_cast<time::microseconds>(rto).count()); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 142 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 143 | if (!this->sendInterest(interest, *outFace, pitEntry)) { |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 144 | return false; |
| 145 | } |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 146 | |
| 147 | // schedule RTO timeout |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 148 | PitInfo* pi = pitEntry->insertStrategyInfo<PitInfo>().first; |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 149 | pi->rtoTimer = getScheduler().schedule(rto, |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 150 | [this, pitWeak = weak_ptr<pit::Entry>(pitEntry), face = ingress.face.getId(), nh = mi.lastNexthop] { |
| 151 | afterRtoTimeout(pitWeak, face, nh); |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 152 | }); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 153 | |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | void |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 158 | AccessStrategy::afterRtoTimeout(const weak_ptr<pit::Entry>& pitWeak, |
Teng Liang | ebc20f6 | 2020-06-23 16:55:20 -0700 | [diff] [blame] | 159 | FaceId inFaceId, FaceId firstOutFaceId) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 160 | { |
| 161 | shared_ptr<pit::Entry> pitEntry = pitWeak.lock(); |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 162 | // if PIT entry is gone, RTO timer should have been cancelled |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 163 | BOOST_ASSERT(pitEntry != nullptr); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 164 | |
| 165 | Face* inFace = this->getFace(inFaceId); |
| 166 | if (inFace == nullptr) { |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 167 | NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFaceId |
| 168 | << " inFace-gone " << inFaceId); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 169 | return; |
| 170 | } |
| 171 | |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 172 | auto inRecord = pitEntry->getInRecord(*inFace); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 173 | // in-record is erased only if Interest is satisfied, and RTO timer should have been cancelled |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 174 | // note: if this strategy is extended to send Nacks, that would also erase the in-record, |
| 175 | // and the RTO timer should be cancelled in that case as well |
| 176 | BOOST_ASSERT(inRecord != pitEntry->in_end()); |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 177 | |
| 178 | const Interest& interest = inRecord->getInterest(); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 179 | const fib::Entry& fibEntry = this->lookupFib(*pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 180 | |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 181 | NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFaceId |
| 182 | << " multicast-except " << firstOutFaceId); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 183 | this->multicast(interest, *inFace, pitEntry, fibEntry, firstOutFaceId); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 186 | size_t |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 187 | AccessStrategy::multicast(const Interest& interest, const Face& inFace, |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 188 | const shared_ptr<pit::Entry>& pitEntry, const fib::Entry& fibEntry, |
| 189 | FaceId exceptFace) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 190 | { |
Davide Pesavento | 17c172b | 2019-03-23 15:11:44 -0400 | [diff] [blame] | 191 | size_t nSent = 0; |
| 192 | for (const auto& nexthop : fibEntry.getNextHops()) { |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 193 | Face& outFace = nexthop.getFace(); |
| 194 | if (&outFace == &inFace || outFace.getId() == exceptFace || |
| 195 | wouldViolateScope(inFace, interest, outFace)) { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 196 | continue; |
| 197 | } |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 198 | NFD_LOG_DEBUG(pitEntry->getInterest() << " interestTo " << outFace.getId() << " multicast"); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 199 | if (this->sendInterest(interest, outFace, pitEntry)) { |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 200 | ++nSent; |
| 201 | } |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 202 | } |
Junxiao Shi | a7f9a29 | 2016-11-22 16:31:38 +0000 | [diff] [blame] | 203 | return nSent; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 207 | AccessStrategy::beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress, |
| 208 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 209 | { |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 210 | PitInfo* pi = pitEntry->getStrategyInfo<PitInfo>(); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 211 | if (pi != nullptr) { |
| 212 | pi->rtoTimer.cancel(); |
| 213 | } |
| 214 | |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 215 | if (!pitEntry->hasInRecords()) { // already satisfied by another upstream |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 216 | NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << ingress << " not-fastest"); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 217 | return; |
| 218 | } |
| 219 | |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 220 | auto outRecord = pitEntry->getOutRecord(ingress.face); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 221 | if (outRecord == pitEntry->out_end()) { // no out-record |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 222 | NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << ingress << " no-out-record"); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 223 | return; |
| 224 | } |
| 225 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 226 | auto rtt = time::steady_clock::now() - outRecord->getLastRenewed(); |
ashiqopu | c707948 | 2019-02-20 05:34:37 +0000 | [diff] [blame] | 227 | NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << ingress |
| 228 | << " rtt=" << time::duration_cast<time::microseconds>(rtt).count()); |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 229 | this->updateMeasurements(ingress.face, data, rtt); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 233 | AccessStrategy::updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt) |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 234 | { |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 235 | FaceInfo& fi = m_fit.try_emplace(inFace.getId(), m_rttEstimatorOpts).first->second; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 236 | fi.rtt.addMeasurement(rtt); |
| 237 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 238 | MtInfo* mi = this->addPrefixMeasurements(data); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 239 | if (mi->lastNexthop != inFace.getId()) { |
| 240 | mi->lastNexthop = inFace.getId(); |
| 241 | mi->rtt = fi.rtt; |
| 242 | } |
| 243 | else { |
| 244 | mi->rtt.addMeasurement(rtt); |
| 245 | } |
| 246 | } |
| 247 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 248 | std::tuple<Name, AccessStrategy::MtInfo*> |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 249 | AccessStrategy::findPrefixMeasurements(const pit::Entry& pitEntry) |
| 250 | { |
Davide Pesavento | 0bba81d | 2020-10-05 17:50:28 -0400 | [diff] [blame] | 251 | auto me = this->getMeasurements().findLongestPrefixMatch(pitEntry); |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 252 | if (me == nullptr) { |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 253 | return {Name{}, nullptr}; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Davide Pesavento | 0bba81d | 2020-10-05 17:50:28 -0400 | [diff] [blame] | 256 | auto mi = me->getStrategyInfo<MtInfo>(); |
| 257 | // TODO: after a runtime strategy change, it's possible that a measurements::Entry exists but |
| 258 | // the corresponding MtInfo doesn't exist (mi == nullptr); this case needs another longest |
| 259 | // prefix match until an MtInfo is found. |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 260 | return {me->getName(), mi}; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 263 | AccessStrategy::MtInfo* |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 264 | AccessStrategy::addPrefixMeasurements(const Data& data) |
| 265 | { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 266 | measurements::Entry* me = nullptr; |
| 267 | if (!data.getName().empty()) { |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 268 | me = this->getMeasurements().get(data.getName().getPrefix(-1)); |
| 269 | } |
| 270 | if (me == nullptr) { // parent of Data Name is not in this strategy, or Data Name is empty |
| 271 | me = this->getMeasurements().get(data.getName()); |
| 272 | // Data Name must be in this strategy |
| 273 | BOOST_ASSERT(me != nullptr); |
| 274 | } |
| 275 | |
Davide Pesavento | e4b2238 | 2018-06-10 14:37:24 -0400 | [diff] [blame] | 276 | this->getMeasurements().extendLifetime(*me, 8_s); |
Davide Pesavento | eb7b7ab | 2019-08-14 19:00:15 -0400 | [diff] [blame] | 277 | return me->insertStrategyInfo<MtInfo>(m_rttEstimatorOpts).first; |
Junxiao Shi | 80ee7cb | 2014-12-14 10:53:05 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 280 | } // namespace nfd::fw |