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