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