Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
| 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" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 29 | #include "core/logger.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 30 | #include "fw/strategy.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 33 | namespace strategy_choice { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 34 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 35 | using fw::Strategy; |
| 36 | |
| 37 | NFD_LOG_INIT("StrategyChoice"); |
| 38 | |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 39 | static inline bool |
| 40 | nteHasStrategyChoiceEntry(const name_tree::Entry& nte) |
| 41 | { |
| 42 | return nte.getStrategyChoiceEntry() != nullptr; |
| 43 | } |
| 44 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 45 | StrategyChoice::StrategyChoice(Forwarder& forwarder) |
| 46 | : m_forwarder(forwarder) |
| 47 | , m_nameTree(m_forwarder.getNameTree()) |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 48 | , m_nItems(0) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 49 | { |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void |
| 53 | StrategyChoice::setDefaultStrategy(const Name& strategyName) |
| 54 | { |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 55 | auto entry = make_unique<Entry>(Name()); |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 56 | entry->setStrategy(Strategy::create(strategyName, m_forwarder)); |
| 57 | NFD_LOG_INFO("setDefaultStrategy " << entry->getStrategyName()); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 58 | |
| 59 | // don't use .insert here, because it will invoke findEffectiveStrategy |
| 60 | // which expects an existing root entry |
| 61 | name_tree::Entry& nte = m_nameTree.lookup(Name()); |
| 62 | nte.setStrategyChoiceEntry(std::move(entry)); |
| 63 | ++m_nItems; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | bool |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 67 | StrategyChoice::hasStrategy(const Name& strategyName, bool isExact) const |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 68 | { |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 69 | if (isExact) { |
| 70 | return m_strategyInstances.count(strategyName) > 0; |
| 71 | } |
| 72 | else { |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 73 | return Strategy::canCreate(strategyName) || |
| 74 | this->getStrategy(strategyName) != nullptr; |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 75 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 78 | std::pair<bool, Strategy*> |
| 79 | StrategyChoice::install(unique_ptr<Strategy> strategy) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 80 | { |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 81 | /// \todo #3868 |
| 82 | /// Strategy instance should always be created from Strategy::create; |
| 83 | /// m_strategyInstances, install, getStrategy, hasStrategy should be eliminated. |
| 84 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 85 | BOOST_ASSERT(strategy != nullptr); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 86 | Name strategyName = strategy->getName(); |
| 87 | // copying Name, so that strategyName remains available even if strategy is deallocated |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 88 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 89 | bool isInserted = false; |
| 90 | StrategyInstanceTable::iterator it; |
| 91 | std::tie(it, isInserted) = m_strategyInstances.emplace(strategyName, std::move(strategy)); |
| 92 | |
| 93 | if (!isInserted) { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 94 | NFD_LOG_ERROR("install(" << strategyName << ") duplicate strategyName"); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 95 | } |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 96 | return std::make_pair(isInserted, it->second.get()); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 99 | Strategy* |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 100 | StrategyChoice::getStrategy(const Name& strategyName) const |
| 101 | { |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 102 | Strategy* candidate = nullptr; |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 103 | for (auto it = m_strategyInstances.lower_bound(strategyName); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 104 | it != m_strategyInstances.end() && strategyName.isPrefixOf(it->first); ++it) { |
| 105 | switch (it->first.size() - strategyName.size()) { |
| 106 | case 0: // exact match |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 107 | return it->second.get(); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 108 | case 1: // unversioned strategyName matches versioned strategy |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 109 | candidate = it->second.get(); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 110 | break; |
| 111 | } |
| 112 | } |
| 113 | return candidate; |
| 114 | } |
| 115 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 116 | bool |
| 117 | StrategyChoice::insert(const Name& prefix, const Name& strategyName) |
| 118 | { |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 119 | unique_ptr<Strategy> createdStrategy = Strategy::create(strategyName, m_forwarder); |
| 120 | Strategy* strategy = createdStrategy.get(); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 121 | if (strategy == nullptr) { |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 122 | strategy = this->getStrategy(strategyName); |
| 123 | if (strategy == nullptr) { |
| 124 | NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") strategy not registered or installed"); |
| 125 | return false; |
| 126 | } |
| 127 | NFD_LOG_WARN("insert(" << prefix << "," << strategyName << ") using shared strategy instance"); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 130 | name_tree::Entry& nte = m_nameTree.lookup(prefix); |
| 131 | Entry* entry = nte.getStrategyChoiceEntry(); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 132 | Strategy* oldStrategy = nullptr; |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 133 | if (entry != nullptr) { |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 134 | if (entry->getStrategyName() == strategy->getName()) { |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 135 | NFD_LOG_TRACE("insert(" << prefix << ") not changing " << strategy->getName()); |
| 136 | return true; |
| 137 | } |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 138 | oldStrategy = &entry->getStrategy(); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 139 | NFD_LOG_TRACE("insert(" << prefix << ") changing from " << oldStrategy->getName() << |
| 140 | " to " << strategy->getName()); |
| 141 | } |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 142 | else { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 143 | oldStrategy = &this->findEffectiveStrategy(prefix); |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 144 | auto newEntry = make_unique<Entry>(prefix); |
| 145 | entry = newEntry.get(); |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 146 | nte.setStrategyChoiceEntry(std::move(newEntry)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 147 | ++m_nItems; |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 148 | NFD_LOG_TRACE("insert(" << prefix << ") new entry " << strategy->getName()); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 151 | this->changeStrategy(*entry, *oldStrategy, *strategy); |
Junxiao Shi | f15058a | 2016-12-11 20:15:05 +0000 | [diff] [blame^] | 152 | if (createdStrategy != nullptr) { |
| 153 | entry->setStrategy(std::move(createdStrategy)); |
| 154 | } |
| 155 | else { |
| 156 | entry->setStrategy(*strategy); |
| 157 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | |
| 161 | void |
| 162 | StrategyChoice::erase(const Name& prefix) |
| 163 | { |
| 164 | BOOST_ASSERT(prefix.size() > 0); |
| 165 | |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 166 | name_tree::Entry* nte = m_nameTree.findExactMatch(prefix); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 167 | if (nte == nullptr) { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 168 | return; |
| 169 | } |
| 170 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 171 | Entry* entry = nte->getStrategyChoiceEntry(); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 172 | if (entry == nullptr) { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
| 176 | Strategy& oldStrategy = entry->getStrategy(); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 177 | |
| 178 | Strategy& parentStrategy = this->findEffectiveStrategy(prefix.getPrefix(-1)); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 179 | this->changeStrategy(*entry, oldStrategy, parentStrategy); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 180 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 181 | nte->setStrategyChoiceEntry(nullptr); |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 182 | m_nameTree.eraseIfEmpty(nte); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 183 | --m_nItems; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 186 | std::pair<bool, Name> |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 187 | StrategyChoice::get(const Name& prefix) const |
| 188 | { |
Junxiao Shi | 811c010 | 2016-08-10 04:12:45 +0000 | [diff] [blame] | 189 | name_tree::Entry* nte = m_nameTree.findExactMatch(prefix); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 190 | if (nte == nullptr) { |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 191 | return {false, Name()}; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 194 | Entry* entry = nte->getStrategyChoiceEntry(); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 195 | if (entry == nullptr) { |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 196 | return {false, Name()}; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 199 | return {true, entry->getStrategy().getName()}; |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 202 | template<typename K> |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 203 | Strategy& |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 204 | StrategyChoice::findEffectiveStrategyImpl(const K& key) const |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 205 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 206 | const name_tree::Entry* nte = m_nameTree.findLongestPrefixMatch(key, &nteHasStrategyChoiceEntry); |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 207 | BOOST_ASSERT(nte != nullptr); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 208 | return nte->getStrategyChoiceEntry()->getStrategy(); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | Strategy& |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 212 | StrategyChoice::findEffectiveStrategy(const Name& prefix) const |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 213 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 214 | return this->findEffectiveStrategyImpl(prefix); |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | Strategy& |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 218 | StrategyChoice::findEffectiveStrategy(const pit::Entry& pitEntry) const |
| 219 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 220 | return this->findEffectiveStrategyImpl(pitEntry); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 223 | Strategy& |
| 224 | StrategyChoice::findEffectiveStrategy(const measurements::Entry& measurementsEntry) const |
| 225 | { |
Junxiao Shi | dd8f661 | 2016-08-12 15:42:52 +0000 | [diff] [blame] | 226 | return this->findEffectiveStrategyImpl(measurementsEntry); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 229 | static inline void |
| 230 | clearStrategyInfo(const name_tree::Entry& nte) |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 231 | { |
Junxiao Shi | e3cf285 | 2016-08-09 03:50:56 +0000 | [diff] [blame] | 232 | NFD_LOG_TRACE("clearStrategyInfo " << nte.getName()); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 233 | |
| 234 | for (const shared_ptr<pit::Entry>& pitEntry : nte.getPitEntries()) { |
| 235 | pitEntry->clearStrategyInfo(); |
| 236 | for (const pit::InRecord& inRecord : pitEntry->getInRecords()) { |
| 237 | const_cast<pit::InRecord&>(inRecord).clearStrategyInfo(); |
| 238 | } |
| 239 | for (const pit::OutRecord& outRecord : pitEntry->getOutRecords()) { |
| 240 | const_cast<pit::OutRecord&>(outRecord).clearStrategyInfo(); |
| 241 | } |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 242 | } |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 243 | if (nte.getMeasurementsEntry() != nullptr) { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 244 | nte.getMeasurementsEntry()->clearStrategyInfo(); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 248 | void |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 249 | StrategyChoice::changeStrategy(Entry& entry, Strategy& oldStrategy, Strategy& newStrategy) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 250 | { |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 251 | if (&oldStrategy == &newStrategy) { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 252 | return; |
| 253 | } |
| 254 | |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 255 | NFD_LOG_INFO("changeStrategy(" << entry.getPrefix() << ")" |
| 256 | << " from " << oldStrategy.getName() |
| 257 | << " to " << newStrategy.getName()); |
| 258 | |
| 259 | // reset StrategyInfo on a portion of NameTree, |
| 260 | // where entry's effective strategy is covered by the changing StrategyChoice entry |
Junxiao Shi | 7f35843 | 2016-08-11 17:06:33 +0000 | [diff] [blame] | 261 | const name_tree::Entry* rootNte = m_nameTree.getEntry(entry); |
Junxiao Shi | f2420fc | 2016-08-11 13:18:21 +0000 | [diff] [blame] | 262 | BOOST_ASSERT(rootNte != nullptr); |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 263 | auto&& ntChanged = m_nameTree.partialEnumerate(entry.getPrefix(), |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 264 | [&rootNte] (const name_tree::Entry& nte) -> std::pair<bool, bool> { |
| 265 | if (&nte == rootNte) { |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 266 | return {true, true}; |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 267 | } |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 268 | if (nte.getStrategyChoiceEntry() != nullptr) { |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 269 | return {false, false}; |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 270 | } |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 271 | return {true, true}; |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 272 | }); |
Junxiao Shi | 60607c7 | 2014-11-26 22:40:36 -0700 | [diff] [blame] | 273 | for (const name_tree::Entry& nte : ntChanged) { |
| 274 | clearStrategyInfo(nte); |
| 275 | } |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 278 | StrategyChoice::Range |
| 279 | StrategyChoice::getRange() const |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 280 | { |
Junxiao Shi | b30863e | 2016-08-15 21:32:01 +0000 | [diff] [blame] | 281 | return m_nameTree.fullEnumerate(&nteHasStrategyChoiceEntry) | |
| 282 | boost::adaptors::transformed(name_tree::GetTableEntry<Entry>( |
| 283 | &name_tree::Entry::getStrategyChoiceEntry)); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Junxiao Shi | ff10da6 | 2016-07-13 17:57:43 +0000 | [diff] [blame] | 286 | } // namespace strategy_choice |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 287 | } // namespace nfd |