Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | af6569a | 2014-06-14 00:01:34 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 25 | |
| 26 | #include "ncc-strategy.hpp" |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 27 | #include "pit-algorithm.hpp" |
Junxiao Shi | af6569a | 2014-06-14 00:01:34 -0700 | [diff] [blame] | 28 | #include "core/random.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
| 31 | namespace fw { |
| 32 | |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 33 | const Name NccStrategy::STRATEGY_NAME("ndn:/localhost/nfd/strategy/ncc/%FD%01"); |
Junxiao Shi | faf3eb0 | 2015-02-16 10:50:36 -0700 | [diff] [blame] | 34 | NFD_REGISTER_STRATEGY(NccStrategy); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 35 | |
| 36 | NccStrategy::NccStrategy(Forwarder& forwarder, const Name& name) |
| 37 | : Strategy(forwarder, name) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 41 | const time::microseconds NccStrategy::DEFER_FIRST_WITHOUT_BEST_FACE = time::microseconds(4000); |
| 42 | const time::microseconds NccStrategy::DEFER_RANGE_WITHOUT_BEST_FACE = time::microseconds(75000); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 43 | const time::nanoseconds NccStrategy::MEASUREMENTS_LIFETIME = time::seconds(16); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 44 | |
| 45 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 46 | NccStrategy::afterReceiveInterest(const Face& inFace, const Interest& interest, |
| 47 | const shared_ptr<pit::Entry>& pitEntry) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 48 | { |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 49 | const fib::Entry& fibEntry = this->lookupFib(*pitEntry); |
| 50 | const fib::NextHopList& nexthops = fibEntry.getNextHops(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 51 | if (nexthops.size() == 0) { |
| 52 | this->rejectPendingInterest(pitEntry); |
| 53 | return; |
| 54 | } |
| 55 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 56 | PitEntryInfo* pitEntryInfo = pitEntry->insertStrategyInfo<PitEntryInfo>().first; |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 57 | bool isNewPitEntry = !hasPendingOutRecords(*pitEntry); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 58 | if (!isNewPitEntry) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 59 | return; |
| 60 | } |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 62 | MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 63 | |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 64 | time::microseconds deferFirst = DEFER_FIRST_WITHOUT_BEST_FACE; |
| 65 | time::microseconds deferRange = DEFER_RANGE_WITHOUT_BEST_FACE; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 66 | size_t nUpstreams = nexthops.size(); |
| 67 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 68 | shared_ptr<Face> bestFace = meInfo.getBestFace(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 69 | if (bestFace != nullptr && fibEntry.hasNextHop(*bestFace) && |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 70 | canForwardToLegacy(*pitEntry, *bestFace)) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 71 | // TODO Should we use `randlow = 100 + nrand48(h->seed) % 4096U;` ? |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 72 | deferFirst = meInfo.prediction; |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 73 | deferRange = time::microseconds((deferFirst.count() + 1) / 2); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 74 | --nUpstreams; |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 75 | this->sendInterest(pitEntry, *bestFace); |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 76 | pitEntryInfo->bestFaceTimeout = scheduler::schedule( |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 77 | meInfo.prediction, |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 78 | bind(&NccStrategy::timeoutOnBestFace, this, weak_ptr<pit::Entry>(pitEntry))); |
| 79 | } |
| 80 | else { |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 81 | // use first eligible nexthop |
| 82 | auto firstEligibleNexthop = std::find_if(nexthops.begin(), nexthops.end(), |
| 83 | [&pitEntry] (const fib::NextHop& nexthop) { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 84 | return canForwardToLegacy(*pitEntry, nexthop.getFace()); |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 85 | }); |
| 86 | if (firstEligibleNexthop != nexthops.end()) { |
| 87 | this->sendInterest(pitEntry, firstEligibleNexthop->getFace()); |
| 88 | } |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 91 | shared_ptr<Face> previousFace = meInfo.previousFace.lock(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 92 | if (previousFace != nullptr && fibEntry.hasNextHop(*previousFace) && |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 93 | canForwardToLegacy(*pitEntry, *previousFace)) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 94 | --nUpstreams; |
| 95 | } |
| 96 | |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 97 | if (nUpstreams > 0) { |
| 98 | pitEntryInfo->maxInterval = std::max(time::microseconds(1), |
| 99 | time::microseconds((2 * deferRange.count() + nUpstreams - 1) / nUpstreams)); |
| 100 | } |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 101 | else { |
| 102 | // Normally, maxInterval is unused if there aren't any face beyond best and previousBest. |
| 103 | // However, in case FIB entry gains a new nexthop before doPropagate executes (bug 1853), |
| 104 | // this maxInterval would be used to determine when the next doPropagate would happen. |
| 105 | pitEntryInfo->maxInterval = deferFirst; |
| 106 | } |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 107 | pitEntryInfo->propagateTimer = scheduler::schedule(deferFirst, |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 108 | bind(&NccStrategy::doPropagate, this, weak_ptr<pit::Entry>(pitEntry))); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 112 | NccStrategy::doPropagate(weak_ptr<pit::Entry> pitEntryWeak) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 113 | { |
| 114 | shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock(); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 115 | if (pitEntry == nullptr) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 116 | return; |
| 117 | } |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 118 | const fib::Entry& fibEntry = this->lookupFib(*pitEntry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 119 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 120 | PitEntryInfo* pitEntryInfo = pitEntry->getStrategyInfo<PitEntryInfo>(); |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 121 | // pitEntryInfo is guaranteed to exist here, because doPropagate is triggered |
| 122 | // from a timer set by NccStrategy. |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 123 | BOOST_ASSERT(pitEntryInfo != nullptr); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 124 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 125 | MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 126 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 127 | shared_ptr<Face> previousFace = meInfo.previousFace.lock(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 128 | if (previousFace != nullptr && fibEntry.hasNextHop(*previousFace) && |
Junxiao Shi | fef73e4 | 2016-03-29 14:15:05 -0700 | [diff] [blame] | 129 | canForwardToLegacy(*pitEntry, *previousFace)) { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 130 | this->sendInterest(pitEntry, *previousFace); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 133 | const fib::NextHopList& nexthops = fibEntry.getNextHops(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 134 | bool isForwarded = false; |
| 135 | for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 136 | Face& face = it->getFace(); |
| 137 | if (canForwardToLegacy(*pitEntry, face)) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 138 | isForwarded = true; |
| 139 | this->sendInterest(pitEntry, face); |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (isForwarded) { |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 145 | std::uniform_int_distribution<time::nanoseconds::rep> dist(0, pitEntryInfo->maxInterval.count() - 1); |
Junxiao Shi | af6569a | 2014-06-14 00:01:34 -0700 | [diff] [blame] | 146 | time::nanoseconds deferNext = time::nanoseconds(dist(getGlobalRng())); |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 147 | pitEntryInfo->propagateTimer = scheduler::schedule(deferNext, |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 148 | bind(&NccStrategy::doPropagate, this, weak_ptr<pit::Entry>(pitEntry))); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | NccStrategy::timeoutOnBestFace(weak_ptr<pit::Entry> pitEntryWeak) |
| 154 | { |
| 155 | shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock(); |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 156 | if (pitEntry == nullptr) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 157 | return; |
| 158 | } |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 159 | measurements::Entry* measurementsEntry = this->getMeasurements().get(*pitEntry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 160 | |
| 161 | for (int i = 0; i < UPDATE_MEASUREMENTS_N_LEVELS; ++i) { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 162 | if (measurementsEntry == nullptr) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 163 | // going out of this strategy's namespace |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 164 | break; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 165 | } |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 166 | this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 167 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 168 | MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(measurementsEntry); |
| 169 | meInfo.adjustPredictUp(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 170 | |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 171 | measurementsEntry = this->getMeasurements().getParent(*measurementsEntry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
| 175 | void |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 176 | NccStrategy::beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry, |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 177 | const Face& inFace, const Data& data) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 178 | { |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 179 | if (!pitEntry->hasInRecords()) { |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 180 | // PIT entry has already been satisfied (and is now waiting for straggler timer to expire) |
| 181 | // NCC does not collect measurements for non-best face |
| 182 | return; |
| 183 | } |
| 184 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 185 | measurements::Entry* measurementsEntry = this->getMeasurements().get(*pitEntry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 186 | |
| 187 | for (int i = 0; i < UPDATE_MEASUREMENTS_N_LEVELS; ++i) { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 188 | if (measurementsEntry == nullptr) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 189 | // going out of this strategy's namespace |
| 190 | return; |
| 191 | } |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 192 | this->getMeasurements().extendLifetime(*measurementsEntry, MEASUREMENTS_LIFETIME); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 193 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 194 | MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(measurementsEntry); |
| 195 | meInfo.updateBestFace(inFace); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 196 | |
Junxiao Shi | e368d99 | 2014-12-02 23:44:31 -0700 | [diff] [blame] | 197 | measurementsEntry = this->getMeasurements().getParent(*measurementsEntry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 200 | PitEntryInfo* pitEntryInfo = pitEntry->getStrategyInfo<PitEntryInfo>(); |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 201 | if (pitEntryInfo != nullptr) { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 202 | scheduler::cancel(pitEntryInfo->propagateTimer); |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 203 | |
| 204 | // Verify that the best face satisfied the interest before canceling the timeout call |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 205 | MeasurementsEntryInfo& meInfo = this->getMeasurementsEntryInfo(pitEntry); |
| 206 | shared_ptr<Face> bestFace = meInfo.getBestFace(); |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 207 | |
| 208 | if (bestFace.get() == &inFace) |
| 209 | scheduler::cancel(pitEntryInfo->bestFaceTimeout); |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 210 | } |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 213 | NccStrategy::MeasurementsEntryInfo& |
Junxiao Shi | 15e98b0 | 2016-08-12 11:21:44 +0000 | [diff] [blame] | 214 | NccStrategy::getMeasurementsEntryInfo(const shared_ptr<pit::Entry>& entry) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 215 | { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 216 | measurements::Entry* measurementsEntry = this->getMeasurements().get(*entry); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 217 | return this->getMeasurementsEntryInfo(measurementsEntry); |
| 218 | } |
| 219 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 220 | NccStrategy::MeasurementsEntryInfo& |
| 221 | NccStrategy::getMeasurementsEntryInfo(measurements::Entry* entry) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 222 | { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 223 | BOOST_ASSERT(entry != nullptr); |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 224 | MeasurementsEntryInfo* info = nullptr; |
| 225 | bool isNew = false; |
| 226 | std::tie(info, isNew) = entry->insertStrategyInfo<MeasurementsEntryInfo>(); |
| 227 | if (!isNew) { |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 228 | return *info; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 231 | measurements::Entry* parentEntry = this->getMeasurements().getParent(*entry); |
| 232 | if (parentEntry != nullptr) { |
| 233 | MeasurementsEntryInfo& parentInfo = this->getMeasurementsEntryInfo(parentEntry); |
| 234 | info->inheritFrom(parentInfo); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 237 | return *info; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 240 | const time::microseconds NccStrategy::MeasurementsEntryInfo::INITIAL_PREDICTION = time::microseconds(8192); |
| 241 | const time::microseconds NccStrategy::MeasurementsEntryInfo::MIN_PREDICTION = time::microseconds(127); |
| 242 | const time::microseconds NccStrategy::MeasurementsEntryInfo::MAX_PREDICTION = time::milliseconds(160); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 243 | |
| 244 | NccStrategy::MeasurementsEntryInfo::MeasurementsEntryInfo() |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 245 | : prediction(INITIAL_PREDICTION) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 246 | { |
| 247 | } |
| 248 | |
| 249 | void |
| 250 | NccStrategy::MeasurementsEntryInfo::inheritFrom(const MeasurementsEntryInfo& other) |
| 251 | { |
| 252 | this->operator=(other); |
| 253 | } |
| 254 | |
| 255 | shared_ptr<Face> |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 256 | NccStrategy::MeasurementsEntryInfo::getBestFace() |
| 257 | { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 258 | shared_ptr<Face> best = this->bestFace.lock(); |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 259 | if (best != nullptr) { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 260 | return best; |
| 261 | } |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 262 | this->bestFace = best = this->previousFace.lock(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 263 | return best; |
| 264 | } |
| 265 | |
| 266 | void |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 267 | NccStrategy::MeasurementsEntryInfo::updateBestFace(const Face& face) |
| 268 | { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 269 | if (this->bestFace.expired()) { |
| 270 | this->bestFace = const_cast<Face&>(face).shared_from_this(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 271 | return; |
| 272 | } |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 273 | shared_ptr<Face> bestFace = this->bestFace.lock(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 274 | if (bestFace.get() == &face) { |
| 275 | this->adjustPredictDown(); |
| 276 | } |
| 277 | else { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 278 | this->previousFace = this->bestFace; |
| 279 | this->bestFace = const_cast<Face&>(face).shared_from_this(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
| 283 | void |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 284 | NccStrategy::MeasurementsEntryInfo::adjustPredictDown() |
| 285 | { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 286 | prediction = std::max(MIN_PREDICTION, |
| 287 | time::microseconds(prediction.count() - (prediction.count() >> ADJUST_PREDICT_DOWN_SHIFT))); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 291 | NccStrategy::MeasurementsEntryInfo::adjustPredictUp() |
| 292 | { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 293 | prediction = std::min(MAX_PREDICTION, |
| 294 | time::microseconds(prediction.count() + (prediction.count() >> ADJUST_PREDICT_UP_SHIFT))); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void |
Davide Pesavento | 5f47aa6 | 2016-10-07 22:09:09 +0200 | [diff] [blame^] | 298 | NccStrategy::MeasurementsEntryInfo::ageBestFace() |
| 299 | { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 300 | this->previousFace = this->bestFace; |
| 301 | this->bestFace.reset(); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 304 | NccStrategy::PitEntryInfo::~PitEntryInfo() |
| 305 | { |
Junxiao Shi | 1391d61 | 2014-03-27 22:27:20 -0700 | [diff] [blame] | 306 | scheduler::cancel(this->bestFaceTimeout); |
| 307 | scheduler::cancel(this->propagateTimer); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | } // namespace fw |
| 311 | } // namespace nfd |