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