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