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 | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [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 "table/strategy-choice.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 27 | |
| 28 | #include "tests/test-common.hpp" |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 29 | #include "../fw/dummy-strategy.hpp" |
| 30 | #include "../fw/install-strategy.hpp" |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 35 | class StrategyChoiceFixture : public BaseFixture |
| 36 | { |
| 37 | protected: |
| 38 | StrategyChoiceFixture() |
| 39 | : sc(forwarder.getStrategyChoice()) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | Name |
| 44 | insertAndGet(const Name& prefix, const Name& strategyName) |
| 45 | { |
| 46 | BOOST_REQUIRE(sc.insert(prefix, strategyName)); |
| 47 | bool isFound; |
| 48 | Name foundName; |
| 49 | std::tie(isFound, foundName) = sc.get(prefix); |
| 50 | BOOST_REQUIRE(isFound); |
| 51 | return foundName; |
| 52 | } |
| 53 | |
| 54 | protected: |
| 55 | Forwarder forwarder; |
| 56 | StrategyChoice& sc; |
| 57 | }; |
| 58 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 59 | BOOST_AUTO_TEST_SUITE(Table) |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 60 | BOOST_FIXTURE_TEST_SUITE(TestStrategyChoice, StrategyChoiceFixture) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 61 | |
| 62 | using fw::Strategy; |
| 63 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 64 | BOOST_AUTO_TEST_CASE(Parameters) |
| 65 | { |
| 66 | const Name strategyName("/strategy-choice-test-parameters/%FD%01"); |
| 67 | DummyStrategy::registerAs(strategyName); |
| 68 | |
| 69 | // no parameters |
| 70 | BOOST_CHECK_EQUAL(this->insertAndGet("/A", strategyName), strategyName); |
| 71 | |
| 72 | // one parameter |
| 73 | Name oneParamName = Name(strategyName).append("param"); |
| 74 | BOOST_CHECK_EQUAL(this->insertAndGet("/B", oneParamName), oneParamName); |
| 75 | |
| 76 | // two parameters |
| 77 | Name twoParamName = Name(strategyName).append("x").append("y"); |
| 78 | BOOST_CHECK_EQUAL(this->insertAndGet("/C", twoParamName), twoParamName); |
| 79 | |
| 80 | // parameter without version is disallowed |
| 81 | Name oneParamUnversioned = strategyName.getPrefix(-1).append("param"); |
| 82 | BOOST_CHECK_EQUAL(sc.insert("/D", oneParamUnversioned), false); |
| 83 | } |
| 84 | |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 85 | BOOST_AUTO_TEST_CASE(Get) |
| 86 | { |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 87 | Name nameP("ndn:/strategy/P"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 88 | install<DummyStrategy>(forwarder, nameP); |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 89 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 90 | BOOST_CHECK(sc.insert("ndn:/", nameP)); |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 91 | // { '/'=>P } |
| 92 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 93 | auto getRoot = sc.get("ndn:/"); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(getRoot.first, true); |
| 95 | BOOST_CHECK_EQUAL(getRoot.second, nameP); |
| 96 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 97 | auto getA = sc.get("ndn:/A"); |
Junxiao Shi | 838c4f1 | 2014-11-03 18:55:24 -0700 | [diff] [blame] | 98 | BOOST_CHECK_EQUAL(getA.first, false); |
Steve DiBenedetto | 77c8751 | 2014-10-06 14:18:22 -0600 | [diff] [blame] | 99 | } |
| 100 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 101 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategy) |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 102 | { |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 103 | Name nameP("ndn:/strategy/P"); |
| 104 | Name nameQ("ndn:/strategy/Q"); |
| 105 | Name nameZ("ndn:/strategy/Z"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 106 | install<DummyStrategy>(forwarder, nameP); |
| 107 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 108 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 109 | BOOST_CHECK(sc.insert("ndn:/", nameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 110 | // { '/'=>P } |
| 111 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 112 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 113 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 114 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 115 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 116 | BOOST_CHECK(sc.insert("ndn:/A/B", nameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 117 | // { '/'=>P, '/A/B'=>P } |
| 118 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 119 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 120 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 121 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 122 | // same instance |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 123 | BOOST_CHECK_EQUAL(&sc.findEffectiveStrategy("ndn:/"), |
| 124 | &sc.findEffectiveStrategy("ndn:/A/B")); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 125 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 126 | sc.erase("ndn:/A"); // no effect |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 127 | // { '/'=>P, '/A/B'=>P } |
| 128 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 129 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 130 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 131 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 132 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 133 | BOOST_CHECK(sc.insert("ndn:/A", nameQ)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 134 | // { '/'=>P, '/A/B'=>P, '/A'=>Q } |
| 135 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 136 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 137 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameQ); |
| 138 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 139 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 140 | sc.erase("ndn:/A/B"); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 141 | // { '/'=>P, '/A'=>Q } |
| 142 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 143 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameP); |
| 144 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameQ); |
| 145 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameQ); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 146 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 147 | BOOST_CHECK(!sc.insert("ndn:/", nameZ)); // non existent strategy |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 148 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 149 | BOOST_CHECK(sc.insert("ndn:/", nameQ)); |
| 150 | BOOST_CHECK(sc.insert("ndn:/A", nameP)); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 151 | // { '/'=>Q, '/A'=>P } |
| 152 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 153 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/") .getName(), nameQ); |
| 154 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A") .getName(), nameP); |
| 155 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/A/B").getName(), nameP); |
| 156 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/D") .getName(), nameQ); |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 159 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithPitEntry) |
| 160 | { |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 161 | Name nameP("ndn:/strategy/P"); |
| 162 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 163 | install<DummyStrategy>(forwarder, nameP); |
| 164 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 165 | |
| 166 | shared_ptr<Data> dataABC = makeData("/A/B/C"); |
| 167 | Name fullName = dataABC->getFullName(); |
| 168 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 169 | BOOST_CHECK(sc.insert("/A", nameP)); |
| 170 | BOOST_CHECK(sc.insert(fullName, nameQ)); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 171 | |
| 172 | Pit& pit = forwarder.getPit(); |
| 173 | shared_ptr<Interest> interestAB = makeInterest("/A/B"); |
| 174 | shared_ptr<pit::Entry> pitAB = pit.insert(*interestAB).first; |
| 175 | shared_ptr<Interest> interestFull = makeInterest(fullName); |
| 176 | shared_ptr<pit::Entry> pitFull = pit.insert(*interestFull).first; |
| 177 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 178 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(*pitAB).getName(), nameP); |
| 179 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(*pitFull).getName(), nameQ); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | BOOST_AUTO_TEST_CASE(FindEffectiveStrategyWithMeasurementsEntry) |
| 183 | { |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 184 | Name nameP("ndn:/strategy/P"); |
| 185 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 186 | install<DummyStrategy>(forwarder, nameP); |
| 187 | install<DummyStrategy>(forwarder, nameQ); |
| 188 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 189 | BOOST_CHECK(sc.insert("/A", nameP)); |
| 190 | BOOST_CHECK(sc.insert("/A/B/C", nameQ)); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 191 | |
| 192 | Measurements& measurements = forwarder.getMeasurements(); |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 193 | measurements::Entry& mAB = measurements.get("/A/B"); |
| 194 | measurements::Entry& mABCD = measurements.get("/A/B/C/D"); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 195 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 196 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(mAB).getName(), nameP); |
| 197 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy(mABCD).getName(), nameQ); |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 200 | //XXX BOOST_CONCEPT_ASSERT((ForwardIterator<std::vector<int>::iterator>)) |
| 201 | // is also failing. There might be a problem with ForwardIterator concept checking. |
| 202 | //BOOST_CONCEPT_ASSERT((ForwardIterator<StrategyChoice::const_iterator>)); |
| 203 | |
| 204 | BOOST_AUTO_TEST_CASE(Enumerate) |
| 205 | { |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 206 | Name nameP("ndn:/strategy/P"); |
| 207 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 208 | install<DummyStrategy>(forwarder, nameP); |
| 209 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 210 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 211 | sc.insert("ndn:/", nameP); |
| 212 | sc.insert("ndn:/A/B", nameQ); |
| 213 | sc.insert("ndn:/A/B/C", nameP); |
| 214 | sc.insert("ndn:/D", nameP); |
| 215 | sc.insert("ndn:/E", nameQ); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 216 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 217 | BOOST_CHECK_EQUAL(sc.size(), 5); |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 218 | |
| 219 | std::map<Name, Name> map; // namespace=>strategyName |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 220 | for (StrategyChoice::const_iterator it = sc.begin(); it != sc.end(); ++it) { |
Junxiao Shi | b5888d2 | 2014-05-26 07:35:22 -0700 | [diff] [blame] | 221 | map[it->getPrefix()] = it->getStrategyName(); |
| 222 | } |
| 223 | BOOST_CHECK_EQUAL(map.size(), 5); |
| 224 | BOOST_CHECK_EQUAL(map["ndn:/"], nameP); |
| 225 | BOOST_CHECK_EQUAL(map["ndn:/A/B"], nameQ); |
| 226 | BOOST_CHECK_EQUAL(map["ndn:/A/B/C"], nameP); |
| 227 | BOOST_CHECK_EQUAL(map["ndn:/D"], nameP); |
| 228 | BOOST_CHECK_EQUAL(map["ndn:/E"], nameQ); |
| 229 | BOOST_CHECK_EQUAL(map.size(), 5); |
| 230 | } |
| 231 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 232 | class PStrategyInfo : public fw::StrategyInfo |
| 233 | { |
Junxiao Shi | 39ef261 | 2014-11-29 20:35:19 -0700 | [diff] [blame] | 234 | public: |
| 235 | static constexpr int |
| 236 | getTypeId() |
| 237 | { |
| 238 | return 10; |
| 239 | } |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | BOOST_AUTO_TEST_CASE(ClearStrategyInfo) |
| 243 | { |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 244 | Name nameP("ndn:/strategy/P"); |
| 245 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 246 | install<DummyStrategy>(forwarder, nameP); |
| 247 | install<DummyStrategy>(forwarder, nameQ); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 248 | |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 249 | Measurements& measurements = forwarder.getMeasurements(); |
| 250 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 251 | BOOST_CHECK(sc.insert("ndn:/", nameP)); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 252 | // { '/'=>P } |
Junxiao Shi | 5b3feb6 | 2016-08-19 01:51:41 +0000 | [diff] [blame] | 253 | measurements.get("ndn:/").insertStrategyInfo<PStrategyInfo>(); |
| 254 | measurements.get("ndn:/A").insertStrategyInfo<PStrategyInfo>(); |
| 255 | measurements.get("ndn:/A/B").insertStrategyInfo<PStrategyInfo>(); |
| 256 | measurements.get("ndn:/A/C").insertStrategyInfo<PStrategyInfo>(); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 257 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 258 | BOOST_CHECK(sc.insert("ndn:/A/B", nameP)); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 259 | // { '/'=>P, '/A/B'=>P } |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 260 | BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 261 | BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 262 | BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 263 | BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() != nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 264 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 265 | BOOST_CHECK(sc.insert("ndn:/A", nameQ)); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 266 | // { '/'=>P, '/A/B'=>P, '/A'=>Q } |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 267 | BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 268 | BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() == nullptr); |
| 269 | BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 270 | BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() == nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 271 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 272 | sc.erase("ndn:/A/B"); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 273 | // { '/'=>P, '/A'=>Q } |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 274 | BOOST_CHECK(measurements.get("ndn:/").getStrategyInfo<PStrategyInfo>() != nullptr); |
| 275 | BOOST_CHECK(measurements.get("ndn:/A").getStrategyInfo<PStrategyInfo>() == nullptr); |
| 276 | BOOST_CHECK(measurements.get("ndn:/A/B").getStrategyInfo<PStrategyInfo>() == nullptr); |
| 277 | BOOST_CHECK(measurements.get("ndn:/A/C").getStrategyInfo<PStrategyInfo>() == nullptr); |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 280 | BOOST_AUTO_TEST_CASE(EraseNameTreeEntry) |
| 281 | { |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 282 | Name nameP("ndn:/strategy/P"); |
| 283 | Name nameQ("ndn:/strategy/Q"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 284 | install<DummyStrategy>(forwarder, nameP); |
| 285 | install<DummyStrategy>(forwarder, nameQ); |
| 286 | |
| 287 | NameTree& nameTree = forwarder.getNameTree(); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 288 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 289 | sc.insert("ndn:/", nameP); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 290 | |
| 291 | size_t nNameTreeEntriesBefore = nameTree.size(); |
| 292 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 293 | sc.insert("ndn:/A/B", nameQ); |
| 294 | sc.erase("ndn:/A/B"); |
Junxiao Shi | ee5a444 | 2014-07-27 17:13:43 -0700 | [diff] [blame] | 295 | BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore); |
| 296 | } |
| 297 | |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 298 | BOOST_AUTO_TEST_CASE(Versioning) |
| 299 | { |
| 300 | Forwarder forwarder; |
| 301 | Name nameP("ndn:/strategy/P"); |
| 302 | Name nameP1("ndn:/strategy/P/%FD%01"); |
| 303 | Name nameP2("ndn:/strategy/P/%FD%02"); |
| 304 | Name name3("ndn:/%FD%03"); |
| 305 | Name name4("ndn:/%FD%04"); |
| 306 | Name nameQ("ndn:/strategy/Q"); |
| 307 | Name nameQ5("ndn:/strategy/Q/%FD%05"); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 308 | |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 309 | // install |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 310 | auto strategyP1 = make_unique<DummyStrategy>(ref(forwarder), nameP1); |
| 311 | Strategy* instanceP1 = strategyP1.get(); |
| 312 | auto strategyP1b = make_unique<DummyStrategy>(ref(forwarder), nameP1); |
| 313 | auto strategyP2 = make_unique<DummyStrategy>(ref(forwarder), nameP2); |
| 314 | auto strategy3 = make_unique<DummyStrategy>(ref(forwarder), name3); |
| 315 | auto strategy4 = make_unique<DummyStrategy>(ref(forwarder), name4); |
| 316 | auto strategyQ = make_unique<DummyStrategy>(ref(forwarder), nameQ); |
| 317 | auto strategyQ5 = make_unique<DummyStrategy>(ref(forwarder), nameQ5); |
| 318 | |
| 319 | bool isInstalled = false; |
| 320 | Strategy* installed = nullptr; |
| 321 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 322 | std::tie(isInstalled, installed) = sc.install(std::move(strategyP1)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 323 | BOOST_CHECK_EQUAL(isInstalled, true); |
| 324 | BOOST_CHECK_EQUAL(installed, instanceP1); |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 325 | std::tie(isInstalled, installed) = sc.install(std::move(strategyP1b)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 326 | BOOST_CHECK_EQUAL(isInstalled, false); |
| 327 | BOOST_CHECK_EQUAL(installed, instanceP1); |
| 328 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 329 | BOOST_CHECK_EQUAL(sc.hasStrategy(nameP, false), true); |
| 330 | BOOST_CHECK_EQUAL(sc.hasStrategy(nameP, true), false); |
| 331 | BOOST_CHECK_EQUAL(sc.hasStrategy(nameP1, true), true); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 332 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 333 | BOOST_CHECK_EQUAL(sc.install(std::move(strategyP2)).first, true); |
| 334 | BOOST_CHECK_EQUAL(sc.install(std::move(strategy3)).first, true); |
| 335 | BOOST_CHECK_EQUAL(sc.install(std::move(strategy4)).first, true); |
| 336 | BOOST_CHECK_EQUAL(sc.install(std::move(strategyQ)).first, true); |
| 337 | BOOST_CHECK_EQUAL(sc.install(std::move(strategyQ5)).first, true); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 338 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 339 | BOOST_CHECK(sc.insert("ndn:/", nameQ)); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 340 | // exact match, { '/'=>Q } |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 341 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameQ); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 342 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 343 | BOOST_CHECK(sc.insert("ndn:/", nameQ)); |
| 344 | BOOST_CHECK(sc.insert("ndn:/", nameP)); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 345 | // { '/'=>P2 } |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 346 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameP2); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 347 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 348 | BOOST_CHECK(sc.insert("ndn:/", nameQ)); |
| 349 | BOOST_CHECK(sc.insert("ndn:/", nameP1)); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 350 | // { '/'=>P1 } |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 351 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameP1); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 352 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 353 | BOOST_CHECK(sc.insert("ndn:/", nameQ)); |
| 354 | BOOST_CHECK(sc.insert("ndn:/", nameP2)); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 355 | // { '/'=>P2 } |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 356 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameP2); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 357 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 358 | BOOST_CHECK(sc.insert("ndn:/", nameQ)); |
| 359 | BOOST_CHECK(! sc.insert("ndn:/", "ndn:/strategy/A")); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 360 | // not installed |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 361 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameQ); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 362 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 363 | BOOST_CHECK(sc.insert("ndn:/", nameQ)); |
| 364 | BOOST_CHECK(! sc.insert("ndn:/", "ndn:/strategy/Z")); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 365 | // not installed |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 366 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), nameQ); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 367 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 368 | BOOST_CHECK(sc.insert("ndn:/", nameP1)); |
| 369 | BOOST_CHECK(sc.insert("ndn:/", "ndn:/")); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 370 | // match one component longer only, { '/'=>4 } |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame^] | 371 | BOOST_CHECK_EQUAL(sc.findEffectiveStrategy("ndn:/").getName(), name4); |
Junxiao Shi | e93d6a3 | 2014-09-07 16:13:22 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Junxiao Shi | 4370fde | 2016-02-24 12:20:46 -0700 | [diff] [blame] | 374 | BOOST_AUTO_TEST_SUITE_END() // TestStrategyChoice |
| 375 | BOOST_AUTO_TEST_SUITE_END() // Table |
Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [diff] [blame] | 376 | |
| 377 | } // namespace tests |
| 378 | } // namespace nfd |