Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 4e837f8 | 2017-10-02 22:14:43 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [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 | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 25 | |
| 26 | #include "strategy-choice.hpp" |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 27 | #include "measurements-entry.hpp" |
| 28 | #include "pit-entry.hpp" |
Davide Pesavento | 2cae8ca | 2019-04-18 20:48:05 -0400 | [diff] [blame] | 29 | |
| 30 | #include "common/logger.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 31 | #include "fw/strategy.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | 981db80 | 2018-04-10 18:05:04 -0400 | [diff] [blame] | 33 | #include <ndn-cxx/util/concepts.hpp> |
| 34 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 35 | namespace nfd { |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 36 | namespace strategy_choice { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 37 | |
Davide Pesavento | 981db80 | 2018-04-10 18:05:04 -0400 | [diff] [blame] | 38 | NDN_CXX_ASSERT_FORWARD_ITERATOR(StrategyChoice::const_iterator); |
Junxiao Shi | 3aba754 | 2016-12-24 02:42:52 +0000 | [diff] [blame] | 39 | |
Davide Pesavento | a314808 | 2018-04-12 18:21:54 -0400 | [diff] [blame] | 40 | NFD_LOG_INIT(StrategyChoice); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 41 | |
Davide Pesavento | 981db80 | 2018-04-10 18:05:04 -0400 | [diff] [blame] | 42 | using fw::Strategy; |
| 43 | |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 44 | static inline bool |
| 45 | nteHasStrategyChoiceEntry(const name_tree::Entry& nte) |
| 46 | { |
| 47 | return nte.getStrategyChoiceEntry() != nullptr; |
| 48 | } |
| 49 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 50 | StrategyChoice::StrategyChoice(Forwarder& forwarder) |
| 51 | : m_forwarder(forwarder) |
| 52 | , m_nameTree(m_forwarder.getNameTree()) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 53 | { |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void |
| 57 | StrategyChoice::setDefaultStrategy(const Name& strategyName) |
| 58 | { |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 59 | auto entry = make_unique<Entry>(Name()); |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame] | 60 | entry->setStrategy(Strategy::create(strategyName, m_forwarder)); |
Junxiao Shi | 4cb7431 | 2016-12-25 20:48:47 +0000 | [diff] [blame] | 61 | NFD_LOG_INFO("setDefaultStrategy " << entry->getStrategyInstanceName()); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 62 | |
| 63 | // don't use .insert here, because it will invoke findEffectiveStrategy |
| 64 | // which expects an existing root entry |
| 65 | name_tree::Entry& nte = m_nameTree.lookup(Name()); |
| 66 | nte.setStrategyChoiceEntry(std::move(entry)); |
| 67 | ++m_nItems; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 70 | StrategyChoice::InsertResult |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 71 | StrategyChoice::insert(const Name& prefix, const Name& strategyName) |
| 72 | { |
Junxiao Shi | 4e837f8 | 2017-10-02 22:14:43 +0000 | [diff] [blame] | 73 | if (prefix.size() > NameTree::getMaxDepth()) { |
| 74 | return InsertResult::DEPTH_EXCEEDED; |
| 75 | } |
| 76 | |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 77 | unique_ptr<Strategy> strategy; |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 78 | try { |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 79 | strategy = Strategy::create(strategyName, m_forwarder); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 80 | } |
| 81 | catch (const std::invalid_argument& e) { |
| 82 | NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") cannot create strategy: " << e.what()); |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 83 | return InsertResult(InsertResult::EXCEPTION, e.what()); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 86 | if (strategy == nullptr) { |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 87 | NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") strategy not registered"); |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 88 | return InsertResult::NOT_REGISTERED; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Junxiao Shi | 057d149 | 2018-03-20 17:14:18 +0000 | [diff] [blame] | 91 | name_tree::Entry& nte = m_nameTree.lookup(prefix); |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 92 | Entry* entry = nte.getStrategyChoiceEntry(); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 93 | Strategy* oldStrategy = nullptr; |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 94 | if (entry != nullptr) { |
Junxiao Shi | 4cb7431 | 2016-12-25 20:48:47 +0000 | [diff] [blame] | 95 | if (entry->getStrategyInstanceName() == strategy->getInstanceName()) { |
| 96 | NFD_LOG_TRACE("insert(" << prefix << ") not changing " << strategy->getInstanceName()); |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 97 | return InsertResult::OK; |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 98 | } |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 99 | oldStrategy = &entry->getStrategy(); |
Junxiao Shi | 4cb7431 | 2016-12-25 20:48:47 +0000 | [diff] [blame] | 100 | NFD_LOG_TRACE("insert(" << prefix << ") changing from " << oldStrategy->getInstanceName() << |
| 101 | " to " << strategy->getInstanceName()); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 102 | } |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame] | 103 | else { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 104 | oldStrategy = &this->findEffectiveStrategy(prefix); |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 105 | auto newEntry = make_unique<Entry>(prefix); |
| 106 | entry = newEntry.get(); |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 107 | nte.setStrategyChoiceEntry(std::move(newEntry)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 108 | ++m_nItems; |
Junxiao Shi | 4cb7431 | 2016-12-25 20:48:47 +0000 | [diff] [blame] | 109 | NFD_LOG_TRACE("insert(" << prefix << ") new entry " << strategy->getInstanceName()); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 112 | this->changeStrategy(*entry, *oldStrategy, *strategy); |
Junxiao Shi | 7f566dd | 2016-12-27 02:28:31 +0000 | [diff] [blame] | 113 | entry->setStrategy(std::move(strategy)); |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 114 | return InsertResult::OK; |
| 115 | } |
| 116 | |
| 117 | StrategyChoice::InsertResult::InsertResult(Status status, const std::string& exceptionMessage) |
| 118 | : m_status(status) |
| 119 | , m_exceptionMessage(exceptionMessage) |
| 120 | { |
| 121 | } |
| 122 | |
| 123 | std::ostream& |
| 124 | operator<<(std::ostream& os, const StrategyChoice::InsertResult& res) |
| 125 | { |
| 126 | switch (res.m_status) { |
| 127 | case StrategyChoice::InsertResult::OK: |
| 128 | return os << "OK"; |
| 129 | case StrategyChoice::InsertResult::NOT_REGISTERED: |
| 130 | return os << "Strategy not registered"; |
| 131 | case StrategyChoice::InsertResult::EXCEPTION: |
| 132 | return os << "Error instantiating strategy: " << res.m_exceptionMessage; |
Junxiao Shi | 4e837f8 | 2017-10-02 22:14:43 +0000 | [diff] [blame] | 133 | case StrategyChoice::InsertResult::DEPTH_EXCEEDED: |
| 134 | return os << "Prefix has too many components (limit is " |
| 135 | << to_string(NameTree::getMaxDepth()) << ")"; |
Junxiao Shi | 530cf00 | 2017-01-03 14:43:16 +0000 | [diff] [blame] | 136 | } |
| 137 | return os; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void |
| 141 | StrategyChoice::erase(const Name& prefix) |
| 142 | { |
| 143 | BOOST_ASSERT(prefix.size() > 0); |
| 144 | |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 145 | name_tree::Entry* nte = m_nameTree.findExactMatch(prefix); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 146 | if (nte == nullptr) { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 150 | Entry* entry = nte->getStrategyChoiceEntry(); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 151 | if (entry == nullptr) { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 152 | return; |
| 153 | } |
| 154 | |
| 155 | Strategy& oldStrategy = entry->getStrategy(); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 156 | |
| 157 | Strategy& parentStrategy = this->findEffectiveStrategy(prefix.getPrefix(-1)); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 158 | this->changeStrategy(*entry, oldStrategy, parentStrategy); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 159 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 160 | nte->setStrategyChoiceEntry(nullptr); |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 161 | m_nameTree.eraseIfEmpty(nte); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 162 | --m_nItems; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 165 | std::pair<bool, Name> |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 166 | StrategyChoice::get(const Name& prefix) const |
| 167 | { |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 168 | name_tree::Entry* nte = m_nameTree.findExactMatch(prefix); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 169 | if (nte == nullptr) { |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 170 | return {false, {}}; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 173 | Entry* entry = nte->getStrategyChoiceEntry(); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 174 | if (entry == nullptr) { |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 175 | return {false, {}}; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Junxiao Shi | 4cb7431 | 2016-12-25 20:48:47 +0000 | [diff] [blame] | 178 | return {true, entry->getStrategyInstanceName()}; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 181 | template<typename K> |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 182 | Strategy& |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 183 | StrategyChoice::findEffectiveStrategyImpl(const K& key) const |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 184 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 185 | const name_tree::Entry* nte = m_nameTree.findLongestPrefixMatch(key, &nteHasStrategyChoiceEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 186 | BOOST_ASSERT(nte != nullptr); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 187 | return nte->getStrategyChoiceEntry()->getStrategy(); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | Strategy& |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 191 | StrategyChoice::findEffectiveStrategy(const Name& prefix) const |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 192 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 193 | return this->findEffectiveStrategyImpl(prefix); |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | Strategy& |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 197 | StrategyChoice::findEffectiveStrategy(const pit::Entry& pitEntry) const |
| 198 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 199 | return this->findEffectiveStrategyImpl(pitEntry); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 202 | Strategy& |
| 203 | StrategyChoice::findEffectiveStrategy(const measurements::Entry& measurementsEntry) const |
| 204 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 205 | return this->findEffectiveStrategyImpl(measurementsEntry); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 208 | static inline void |
| 209 | clearStrategyInfo(const name_tree::Entry& nte) |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 210 | { |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 211 | NFD_LOG_TRACE("clearStrategyInfo " << nte.getName()); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 212 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 213 | for (const auto& pitEntry : nte.getPitEntries()) { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 214 | pitEntry->clearStrategyInfo(); |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 215 | for (const auto& inRecord : pitEntry->getInRecords()) { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 216 | const_cast<pit::InRecord&>(inRecord).clearStrategyInfo(); |
| 217 | } |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 218 | for (const auto& outRecord : pitEntry->getOutRecords()) { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 219 | const_cast<pit::OutRecord&>(outRecord).clearStrategyInfo(); |
| 220 | } |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 221 | } |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 222 | if (nte.getMeasurementsEntry() != nullptr) { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 223 | nte.getMeasurementsEntry()->clearStrategyInfo(); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 227 | void |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 228 | StrategyChoice::changeStrategy(Entry& entry, Strategy& oldStrategy, Strategy& newStrategy) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 229 | { |
Junxiao Shi | 55e21b9 | 2017-01-23 03:27:47 +0000 | [diff] [blame] | 230 | const Name& oldInstanceName = oldStrategy.getInstanceName(); |
| 231 | const Name& newInstanceName = newStrategy.getInstanceName(); |
| 232 | if (Strategy::areSameType(oldInstanceName, newInstanceName)) { |
| 233 | // same Strategy subclass type: no need to clear StrategyInfo |
| 234 | NFD_LOG_INFO("changeStrategy(" << entry.getPrefix() << ") " |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 235 | << oldInstanceName << " -> " << newInstanceName << " same-type"); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | |
Junxiao Shi | 55e21b9 | 2017-01-23 03:27:47 +0000 | [diff] [blame] | 239 | NFD_LOG_INFO("changeStrategy(" << entry.getPrefix() << ") " |
| 240 | << oldInstanceName << " -> " << newInstanceName); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 241 | |
| 242 | // reset StrategyInfo on a portion of NameTree, |
| 243 | // where entry's effective strategy is covered by the changing StrategyChoice entry |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 244 | const name_tree::Entry* rootNte = m_nameTree.getEntry(entry); |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 245 | BOOST_ASSERT(rootNte != nullptr); |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 246 | const auto& ntChanged = m_nameTree.partialEnumerate(entry.getPrefix(), |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 247 | [&rootNte] (const name_tree::Entry& nte) -> std::pair<bool, bool> { |
| 248 | if (&nte == rootNte) { |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 249 | return {true, true}; |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 250 | } |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 251 | if (nte.getStrategyChoiceEntry() != nullptr) { |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 252 | return {false, false}; |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 253 | } |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 254 | return {true, true}; |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 255 | }); |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 256 | for (const auto& nte : ntChanged) { |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 257 | clearStrategyInfo(nte); |
| 258 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 261 | StrategyChoice::Range |
| 262 | StrategyChoice::getRange() const |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 263 | { |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 264 | return m_nameTree.fullEnumerate(&nteHasStrategyChoiceEntry) | |
| 265 | boost::adaptors::transformed(name_tree::GetTableEntry<Entry>( |
| 266 | &name_tree::Entry::getStrategyChoiceEntry)); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 269 | } // namespace strategy_choice |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 270 | } // namespace nfd |