Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | 192af1f | 2015-01-13 23:19:39 -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. |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "fw/best-route-strategy2.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 27 | |
| 28 | #include "tests/test-common.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 29 | #include "tests/daemon/face/dummy-face.hpp" |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 30 | #include "strategy-tester.hpp" |
| 31 | #include "topology-tester.hpp" |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 34 | namespace fw { |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 35 | namespace tests { |
| 36 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 37 | using namespace nfd::tests; |
| 38 | |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 39 | typedef StrategyTester<BestRouteStrategy2> BestRouteStrategy2Tester; |
| 40 | NFD_REGISTER_STRATEGY(BestRouteStrategy2Tester); |
| 41 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 42 | BOOST_AUTO_TEST_SUITE(Fw) |
| 43 | |
| 44 | class BestRouteStrategy2Fixture : public UnitTestTimeFixture |
| 45 | { |
| 46 | protected: |
| 47 | BestRouteStrategy2Fixture() |
| 48 | : strategy(forwarder) |
| 49 | , fib(forwarder.getFib()) |
| 50 | , pit(forwarder.getPit()) |
| 51 | , face1(make_shared<DummyFace>()) |
| 52 | , face2(make_shared<DummyFace>()) |
| 53 | , face3(make_shared<DummyFace>()) |
| 54 | , face4(make_shared<DummyFace>()) |
| 55 | , face5(make_shared<DummyFace>()) |
| 56 | { |
| 57 | forwarder.addFace(face1); |
| 58 | forwarder.addFace(face2); |
| 59 | forwarder.addFace(face3); |
| 60 | forwarder.addFace(face4); |
| 61 | forwarder.addFace(face5); |
| 62 | } |
| 63 | |
| 64 | public: |
| 65 | Forwarder forwarder; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 66 | BestRouteStrategy2Tester strategy; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 67 | Fib& fib; |
| 68 | Pit& pit; |
| 69 | |
| 70 | shared_ptr<DummyFace> face1; |
| 71 | shared_ptr<DummyFace> face2; |
| 72 | shared_ptr<DummyFace> face3; |
| 73 | shared_ptr<DummyFace> face4; |
| 74 | shared_ptr<DummyFace> face5; |
| 75 | }; |
| 76 | |
| 77 | BOOST_FIXTURE_TEST_SUITE(TestBestRouteStrategy2, BestRouteStrategy2Fixture) |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 79 | BOOST_AUTO_TEST_CASE(Registration) |
| 80 | { |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(Strategy::listRegistered().count(BestRouteStrategy2::getStrategyName()), 1); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Junxiao Shi | 18739c4 | 2016-12-22 08:03:00 +0000 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(InstanceName) |
| 85 | { |
| 86 | Forwarder forwarder; |
| 87 | BOOST_REQUIRE(BestRouteStrategy2::getStrategyName().at(-1).isVersion()); |
| 88 | BOOST_CHECK_EQUAL( |
| 89 | BestRouteStrategy2(forwarder, BestRouteStrategy2::getStrategyName().getPrefix(-1)).getInstanceName(), |
| 90 | BestRouteStrategy2::getStrategyName()); |
| 91 | BOOST_CHECK_THROW( |
| 92 | BestRouteStrategy2(forwarder, Name(BestRouteStrategy2::getStrategyName()).append("param")), |
| 93 | std::invalid_argument); |
| 94 | } |
| 95 | |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 96 | BOOST_AUTO_TEST_CASE(Forward) |
| 97 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 98 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 99 | fibEntry.addNextHop(*face1, 10); |
| 100 | fibEntry.addNextHop(*face2, 20); |
| 101 | fibEntry.addNextHop(*face3, 30); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 102 | |
| 103 | shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA"); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 104 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 105 | |
Junxiao Shi | 584a569 | 2014-12-13 21:55:28 -0700 | [diff] [blame] | 106 | const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>( |
Junxiao Shi | 52e8540 | 2015-11-11 06:06:58 -0700 | [diff] [blame] | 107 | BestRouteStrategy2::RETX_SUPPRESSION_INITIAL * 0.1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 108 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 109 | // first Interest goes to nexthop with lowest FIB cost, |
| 110 | // however face1 is downstream so it cannot be used |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 111 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 112 | strategy.afterReceiveInterest(*face1, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 113 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 114 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 115 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 116 | // downstream retransmits frequently, but the strategy should not send Interests |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 117 | // more often than DEFAULT_MIN_RETX_INTERVAL |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 118 | scheduler::EventId retxFrom4Evt; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 119 | size_t nSentLast = strategy.sendInterestHistory.size(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 120 | time::steady_clock::TimePoint timeSentLast = time::steady_clock::now(); |
Junxiao Shi | 913806d | 2014-11-14 11:43:52 -0700 | [diff] [blame] | 121 | function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
| 122 | periodicalRetxFrom4 = [&] { |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 123 | pitEntry->insertOrUpdateInRecord(*face4, *interest); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 124 | strategy.afterReceiveInterest(*face4, *interest, pitEntry); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 125 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 126 | size_t nSent = strategy.sendInterestHistory.size(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 127 | if (nSent > nSentLast) { |
| 128 | BOOST_CHECK_EQUAL(nSent - nSentLast, 1); |
| 129 | time::steady_clock::TimePoint timeSent = time::steady_clock::now(); |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 130 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 131 | nSentLast = nSent; |
| 132 | timeSentLast = timeSent; |
| 133 | } |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 134 | |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 135 | retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 136 | }; |
| 137 | periodicalRetxFrom4(); |
Junxiao Shi | 52e8540 | 2015-11-11 06:06:58 -0700 | [diff] [blame] | 138 | this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 16); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 139 | scheduler::cancel(retxFrom4Evt); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 140 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 141 | // nexthops for accepted retransmissions: follow FIB cost, |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 142 | // later forward to an eligible upstream with earliest out-record |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 143 | BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6); |
| 144 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId()); |
| 145 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId()); |
| 146 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId()); |
| 147 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId()); |
| 148 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 149 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 150 | fibEntry.removeNextHop(*face1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 151 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 152 | strategy.sendInterestHistory.clear(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 153 | for (int i = 0; i < 3; ++i) { |
Junxiao Shi | 52e8540 | 2015-11-11 06:06:58 -0700 | [diff] [blame] | 154 | this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 2); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 155 | pitEntry->insertOrUpdateInRecord(*face5, *interest); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 156 | strategy.afterReceiveInterest(*face5, *interest, pitEntry); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 157 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 158 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3); |
| 159 | BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId()); |
| 160 | BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId()); |
| 161 | BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 162 | // face1 cannot be used because it's gone from FIB entry |
| 163 | } |
| 164 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 165 | BOOST_AUTO_TEST_SUITE(NoRouteNack) // send Nack-NoRoute if there's no usable FIB nexthop |
| 166 | |
| 167 | class EmptyNextHopList |
| 168 | { |
| 169 | public: |
| 170 | Name |
| 171 | getInterestName() |
| 172 | { |
| 173 | return "/P"; |
| 174 | } |
| 175 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 176 | void |
| 177 | insertFibEntry(BestRouteStrategy2Fixture* fixture) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 178 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 179 | fixture->fib.insert(Name()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 180 | } |
| 181 | }; |
| 182 | |
| 183 | class NextHopIsDownstream |
| 184 | { |
| 185 | public: |
| 186 | Name |
| 187 | getInterestName() |
| 188 | { |
| 189 | return "/P"; |
| 190 | } |
| 191 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 192 | void |
| 193 | insertFibEntry(BestRouteStrategy2Fixture* fixture) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 194 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 195 | fixture->fib.insert(Name()).first->addNextHop(*fixture->face1, 10); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 196 | } |
| 197 | }; |
| 198 | |
| 199 | class NextHopViolatesScope |
| 200 | { |
| 201 | public: |
| 202 | Name |
| 203 | getInterestName() |
| 204 | { |
| 205 | return "/localhop/P"; |
| 206 | } |
| 207 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 208 | void |
| 209 | insertFibEntry(BestRouteStrategy2Fixture* fixture) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 210 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 211 | fixture->fib.insert("/localhop").first->addNextHop(*fixture->face2, 10); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 212 | // face1 and face2 are both non-local; Interest from face1 cannot be forwarded to face2 |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 213 | } |
| 214 | }; |
| 215 | |
| 216 | typedef boost::mpl::vector<EmptyNextHopList, NextHopIsDownstream, NextHopViolatesScope> NoRouteScenarios; |
| 217 | |
| 218 | BOOST_AUTO_TEST_CASE_TEMPLATE(IncomingInterest, Scenario, NoRouteScenarios) |
| 219 | { |
| 220 | Scenario scenario; |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 221 | scenario.insertFibEntry(this); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 222 | |
| 223 | shared_ptr<Interest> interest = makeInterest(scenario.getInterestName()); |
| 224 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 225 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 226 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 227 | strategy.afterReceiveInterest(*face1, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 228 | |
| 229 | BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 230 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 231 | |
| 232 | BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 233 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 234 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId()); |
| 235 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE); |
| 236 | } |
| 237 | |
| 238 | BOOST_AUTO_TEST_SUITE_END() // NoRouteNack |
| 239 | |
| 240 | BOOST_AUTO_TEST_SUITE(IncomingNack) |
| 241 | |
| 242 | BOOST_AUTO_TEST_CASE(OneUpstream) // one upstream, send Nack when Nack arrives |
| 243 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 244 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 245 | fibEntry.addNextHop(*face3, 10); |
| 246 | fibEntry.addNextHop(*face4, 20); |
| 247 | fibEntry.addNextHop(*face5, 30); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 248 | |
| 249 | shared_ptr<Interest> interest1 = makeInterest("/McQYjMbm", 992); |
| 250 | shared_ptr<Interest> interest2 = makeInterest("/McQYjMbm", 114); |
| 251 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 252 | pitEntry->insertOrUpdateInRecord(*face1, *interest1); |
| 253 | pitEntry->insertOrUpdateInRecord(*face2, *interest2); |
| 254 | pitEntry->insertOrUpdateOutRecord(*face3, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 255 | |
| 256 | lp::Nack nack3 = makeNack("/McQYjMbm", 992, lp::NackReason::CONGESTION); |
| 257 | pitEntry->getOutRecord(*face3)->setIncomingNack(nack3); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 258 | strategy.afterReceiveNack(*face3, nack3, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 259 | |
| 260 | BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 2); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 261 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 262 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 264 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[1].header.getReason(), lp::NackReason::CONGESTION); |
| 265 | std::unordered_set<FaceId> nackFaceIds{strategy.sendNackHistory[0].outFaceId, |
| 266 | strategy.sendNackHistory[1].outFaceId}; |
| 267 | std::unordered_set<FaceId> expectedNackFaceIds{face1->getId(), face2->getId()}; |
| 268 | BOOST_CHECK_EQUAL_COLLECTIONS(nackFaceIds.begin(), nackFaceIds.end(), |
| 269 | expectedNackFaceIds.begin(), expectedNackFaceIds.end()); |
| 270 | } |
| 271 | |
| 272 | BOOST_AUTO_TEST_CASE(TwoUpstreams) // two upstreams, send Nack when both Nacks arrive |
| 273 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 274 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 275 | fibEntry.addNextHop(*face3, 10); |
| 276 | fibEntry.addNextHop(*face4, 20); |
| 277 | fibEntry.addNextHop(*face5, 30); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 278 | |
| 279 | shared_ptr<Interest> interest1 = makeInterest("/aS9FAyUV19", 286); |
| 280 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 281 | pitEntry->insertOrUpdateInRecord(*face1, *interest1); |
| 282 | pitEntry->insertOrUpdateOutRecord(*face3, *interest1); |
| 283 | pitEntry->insertOrUpdateOutRecord(*face4, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 284 | |
| 285 | lp::Nack nack3 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION); |
| 286 | pitEntry->getOutRecord(*face3)->setIncomingNack(nack3); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 287 | strategy.afterReceiveNack(*face3, nack3, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 288 | |
| 289 | BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0); // don't send Nack until all upstreams have Nacked |
| 290 | |
| 291 | lp::Nack nack4 = makeNack("/aS9FAyUV19", 286, lp::NackReason::CONGESTION); |
| 292 | pitEntry->getOutRecord(*face4)->setIncomingNack(nack4); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 293 | strategy.afterReceiveNack(*face4, nack4, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 294 | |
| 295 | BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 296 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 297 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId()); |
| 298 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::CONGESTION); |
| 299 | } |
| 300 | |
| 301 | BOOST_AUTO_TEST_CASE(Timeout) // two upstreams, one times out, don't send Nack |
| 302 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 303 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 304 | fibEntry.addNextHop(*face3, 10); |
| 305 | fibEntry.addNextHop(*face4, 20); |
| 306 | fibEntry.addNextHop(*face5, 30); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 307 | |
| 308 | shared_ptr<Interest> interest1 = makeInterest("/sIYw0TXWDj", 115); |
| 309 | interest1->setInterestLifetime(time::milliseconds(400)); |
| 310 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 311 | pitEntry->insertOrUpdateInRecord(*face1, *interest1); |
| 312 | pitEntry->insertOrUpdateOutRecord(*face3, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 313 | |
| 314 | this->advanceClocks(time::milliseconds(300)); |
| 315 | shared_ptr<Interest> interest2 = makeInterest("/sIYw0TXWDj", 223); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 316 | pitEntry->insertOrUpdateInRecord(*face1, *interest2); |
| 317 | pitEntry->insertOrUpdateOutRecord(*face4, *interest2); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 318 | |
| 319 | this->advanceClocks(time::milliseconds(200)); // face3 has timed out |
| 320 | |
| 321 | lp::Nack nack4 = makeNack("/sIYw0TXWDj", 223, lp::NackReason::CONGESTION); |
| 322 | pitEntry->getOutRecord(*face4)->setIncomingNack(nack4); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 323 | strategy.afterReceiveNack(*face4, nack4, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 324 | |
| 325 | BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0); |
| 326 | } |
| 327 | |
| 328 | BOOST_FIXTURE_TEST_CASE(LiveDeadlock, UnitTestTimeFixture) // #3033 note-7 |
| 329 | { |
| 330 | /* |
| 331 | * /----------\ |
| 332 | * | producer | |
| 333 | * \----------/ |
| 334 | * | |
| 335 | * +---+ |
| 336 | * | P | |
| 337 | * +---+ |
| 338 | * | |
| 339 | * failed link |
| 340 | * | |
| 341 | * +---+ |
| 342 | * | R | |
| 343 | * +---+ |
| 344 | * ^ ^ |
| 345 | * / \ |
| 346 | * / \ |
| 347 | * +---+ +---+ |
| 348 | * | B | <---> | C | |
| 349 | * +---+ +---+ |
| 350 | * ^ ^ |
| 351 | * | | |
| 352 | * | | |
| 353 | * +---+ +---+ |
| 354 | * | A | | D | |
| 355 | * +---+ +---+ |
| 356 | * ^ ^ |
| 357 | * | | |
| 358 | * /----------\ /----------\ |
| 359 | * | consumer | | consumer | |
| 360 | * \----------/ \----------/ |
| 361 | */ |
| 362 | |
| 363 | TopologyTester topo; |
| 364 | TopologyNode nodeP = topo.addForwarder("P"), |
| 365 | nodeR = topo.addForwarder("R"), |
| 366 | nodeA = topo.addForwarder("A"), |
| 367 | nodeB = topo.addForwarder("B"), |
| 368 | nodeC = topo.addForwarder("C"), |
| 369 | nodeD = topo.addForwarder("D"); |
| 370 | |
| 371 | for (TopologyNode node : {nodeP, nodeR, nodeA, nodeB, nodeC, nodeD}) { |
| 372 | topo.setStrategy<BestRouteStrategy2>(node); |
| 373 | } |
| 374 | |
| 375 | const time::milliseconds LINK_DELAY(10); |
| 376 | shared_ptr<TopologyLink> linkPR = topo.addLink("PR", LINK_DELAY, {nodeP, nodeR}), |
| 377 | linkRB = topo.addLink("RB", LINK_DELAY, {nodeR, nodeB}), |
| 378 | linkRC = topo.addLink("RC", LINK_DELAY, {nodeR, nodeC}), |
| 379 | linkBC = topo.addLink("BC", LINK_DELAY, {nodeB, nodeC}), |
| 380 | linkBA = topo.addLink("BA", LINK_DELAY, {nodeB, nodeA}), |
| 381 | linkCD = topo.addLink("CD", LINK_DELAY, {nodeC, nodeD}); |
| 382 | |
| 383 | // TODO register the prefix on R->P but then set the face DOWN |
| 384 | // topo.registerPrefix(nodeR, linkPR->getFace(nodeR), "ndn:/P", 10); |
| 385 | topo.registerPrefix(nodeB, linkRB->getFace(nodeB), "ndn:/P", 20); |
| 386 | topo.registerPrefix(nodeB, linkBC->getFace(nodeB), "ndn:/P", 30); |
| 387 | topo.registerPrefix(nodeC, linkRC->getFace(nodeC), "ndn:/P", 20); |
| 388 | topo.registerPrefix(nodeC, linkBC->getFace(nodeC), "ndn:/P", 30); |
| 389 | topo.registerPrefix(nodeA, linkBA->getFace(nodeA), "ndn:/P", 30); |
| 390 | topo.registerPrefix(nodeD, linkCD->getFace(nodeD), "ndn:/P", 30); |
| 391 | |
| 392 | ndn::Face& appA = topo.addAppFace("A", nodeA)->getClientFace(); |
| 393 | ndn::Face& appD = topo.addAppFace("D", nodeD)->getClientFace(); |
| 394 | |
| 395 | int nNacksA = 0, nNacksD = 0; |
| 396 | appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{})); |
| 397 | appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{})); |
| 398 | this->advanceClocks(time::milliseconds(1), time::milliseconds(5)); |
| 399 | appA.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksA]{ ++nNacksA; }), bind([]{})); |
| 400 | appD.expressInterest(Interest("/P/1"), bind([]{}), bind([&nNacksD]{ ++nNacksD; }), bind([]{})); |
| 401 | this->advanceClocks(time::milliseconds(1), time::milliseconds(100)); |
| 402 | |
| 403 | // As long as at least one Nack arrives at each client, strategy behavior is correct. |
| 404 | // Whether both Interests are Nacked is a client face behavior, not strategy behavior. |
| 405 | BOOST_CHECK_GT(nNacksA, 0); |
| 406 | BOOST_CHECK_GT(nNacksD, 0); |
| 407 | } |
| 408 | |
| 409 | template<lp::NackReason X, lp::NackReason Y, lp::NackReason R> |
| 410 | struct NackReasonCombination |
| 411 | { |
| 412 | lp::NackReason |
| 413 | getX() const |
| 414 | { |
| 415 | return X; |
| 416 | } |
| 417 | |
| 418 | lp::NackReason |
| 419 | getY() const |
| 420 | { |
| 421 | return Y; |
| 422 | } |
| 423 | |
| 424 | lp::NackReason |
| 425 | getExpectedResult() const |
| 426 | { |
| 427 | return R; |
| 428 | } |
| 429 | }; |
| 430 | |
| 431 | typedef boost::mpl::vector< |
| 432 | NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>, |
| 433 | NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION>, |
| 434 | NackReasonCombination<lp::NackReason::CONGESTION, lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION>, |
| 435 | NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>, |
| 436 | NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>, |
| 437 | NackReasonCombination<lp::NackReason::DUPLICATE, lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE>, |
| 438 | NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::CONGESTION, lp::NackReason::CONGESTION>, |
| 439 | NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::DUPLICATE, lp::NackReason::DUPLICATE>, |
| 440 | NackReasonCombination<lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE, lp::NackReason::NO_ROUTE> |
| 441 | > NackReasonCombinations; |
| 442 | |
| 443 | BOOST_AUTO_TEST_CASE_TEMPLATE(CombineReasons, Combination, NackReasonCombinations) |
| 444 | { |
| 445 | Combination combination; |
| 446 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 447 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 448 | fibEntry.addNextHop(*face3, 10); |
| 449 | fibEntry.addNextHop(*face4, 20); |
| 450 | fibEntry.addNextHop(*face5, 30); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 451 | |
| 452 | shared_ptr<Interest> interest1 = makeInterest("/F6sEwB24I", 282); |
| 453 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 454 | pitEntry->insertOrUpdateInRecord(*face1, *interest1); |
| 455 | pitEntry->insertOrUpdateOutRecord(*face3, *interest1); |
| 456 | pitEntry->insertOrUpdateOutRecord(*face4, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 457 | |
| 458 | lp::Nack nack3 = makeNack("/F6sEwB24I", 282, combination.getX()); |
| 459 | pitEntry->getOutRecord(*face3)->setIncomingNack(nack3); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 460 | strategy.afterReceiveNack(*face3, nack3, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 461 | |
| 462 | BOOST_CHECK_EQUAL(strategy.sendNackHistory.size(), 0); |
| 463 | |
| 464 | lp::Nack nack4 = makeNack("/F6sEwB24I", 282, combination.getY()); |
| 465 | pitEntry->getOutRecord(*face4)->setIncomingNack(nack4); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 466 | strategy.afterReceiveNack(*face4, nack4, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 467 | |
| 468 | BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 469 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 470 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId()); |
| 471 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), combination.getExpectedResult()); |
| 472 | } |
| 473 | |
| 474 | BOOST_AUTO_TEST_SUITE_END() // IncomingNack |
| 475 | |
| 476 | BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy2 |
| 477 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 478 | |
| 479 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 480 | } // namespace fw |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 481 | } // namespace nfd |