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