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 | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, 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 | |
| 79 | BOOST_AUTO_TEST_CASE(Forward) |
| 80 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 81 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 82 | fibEntry.addNextHop(*face1, 10); |
| 83 | fibEntry.addNextHop(*face2, 20); |
| 84 | fibEntry.addNextHop(*face3, 30); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 85 | |
| 86 | shared_ptr<Interest> interest = makeInterest("ndn:/BzgFBchqA"); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 87 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
| 88 | |
Junxiao Shi | 584a569 | 2014-12-13 21:55:28 -0700 | [diff] [blame] | 89 | const time::nanoseconds TICK = time::duration_cast<time::nanoseconds>( |
Junxiao Shi | 52e8540 | 2015-11-11 06:06:58 -0700 | [diff] [blame] | 90 | BestRouteStrategy2::RETX_SUPPRESSION_INITIAL * 0.1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 91 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 92 | // first Interest goes to nexthop with lowest FIB cost, |
| 93 | // however face1 is downstream so it cannot be used |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 94 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 95 | strategy.afterReceiveInterest(*face1, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 96 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 97 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory.back().outFaceId, face2->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 98 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 99 | // downstream retransmits frequently, but the strategy should not send Interests |
Junxiao Shi | a788e25 | 2015-01-28 17:06:25 -0700 | [diff] [blame] | 100 | // more often than DEFAULT_MIN_RETX_INTERVAL |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 101 | scheduler::EventId retxFrom4Evt; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 102 | size_t nSentLast = strategy.sendInterestHistory.size(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 103 | time::steady_clock::TimePoint timeSentLast = time::steady_clock::now(); |
Junxiao Shi | 913806d | 2014-11-14 11:43:52 -0700 | [diff] [blame] | 104 | function<void()> periodicalRetxFrom4; // let periodicalRetxFrom4 lambda capture itself |
| 105 | periodicalRetxFrom4 = [&] { |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 106 | pitEntry->insertOrUpdateInRecord(*face4, *interest); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 107 | strategy.afterReceiveInterest(*face4, *interest, pitEntry); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 108 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 109 | size_t nSent = strategy.sendInterestHistory.size(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 110 | if (nSent > nSentLast) { |
| 111 | BOOST_CHECK_EQUAL(nSent - nSentLast, 1); |
| 112 | time::steady_clock::TimePoint timeSent = time::steady_clock::now(); |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 113 | BOOST_CHECK_GE(timeSent - timeSentLast, TICK * 8); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 114 | nSentLast = nSent; |
| 115 | timeSentLast = timeSent; |
| 116 | } |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 117 | |
Junxiao Shi | 684fa0f | 2015-02-23 21:39:57 -0700 | [diff] [blame] | 118 | retxFrom4Evt = scheduler::schedule(TICK * 5, periodicalRetxFrom4); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 119 | }; |
| 120 | periodicalRetxFrom4(); |
Junxiao Shi | 52e8540 | 2015-11-11 06:06:58 -0700 | [diff] [blame] | 121 | this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 16); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 122 | scheduler::cancel(retxFrom4Evt); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 123 | |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 124 | // nexthops for accepted retransmissions: follow FIB cost, |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 125 | // later forward to an eligible upstream with earliest out-record |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 126 | BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 6); |
| 127 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face1->getId()); |
| 128 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face3->getId()); |
| 129 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[3].outFaceId, face2->getId()); |
| 130 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[4].outFaceId, face1->getId()); |
| 131 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[5].outFaceId, face3->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 132 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 133 | fibEntry.removeNextHop(*face1); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 134 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 135 | strategy.sendInterestHistory.clear(); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 136 | for (int i = 0; i < 3; ++i) { |
Junxiao Shi | 52e8540 | 2015-11-11 06:06:58 -0700 | [diff] [blame] | 137 | this->advanceClocks(TICK, BestRouteStrategy2::RETX_SUPPRESSION_MAX * 2); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 138 | pitEntry->insertOrUpdateInRecord(*face5, *interest); |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 139 | strategy.afterReceiveInterest(*face5, *interest, pitEntry); |
Junxiao Shi | 1f30aac | 2014-11-04 18:45:56 -0700 | [diff] [blame] | 140 | } |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 141 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 3); |
| 142 | BOOST_CHECK_NE(strategy.sendInterestHistory[0].outFaceId, face1->getId()); |
| 143 | BOOST_CHECK_NE(strategy.sendInterestHistory[1].outFaceId, face1->getId()); |
| 144 | BOOST_CHECK_NE(strategy.sendInterestHistory[2].outFaceId, face1->getId()); |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 145 | // face1 cannot be used because it's gone from FIB entry |
| 146 | } |
| 147 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 148 | BOOST_AUTO_TEST_SUITE(NoRouteNack) // send Nack-NoRoute if there's no usable FIB nexthop |
| 149 | |
| 150 | class EmptyNextHopList |
| 151 | { |
| 152 | public: |
| 153 | Name |
| 154 | getInterestName() |
| 155 | { |
| 156 | return "/P"; |
| 157 | } |
| 158 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 159 | void |
| 160 | insertFibEntry(BestRouteStrategy2Fixture* fixture) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 161 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 162 | fixture->fib.insert(Name()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 163 | } |
| 164 | }; |
| 165 | |
| 166 | class NextHopIsDownstream |
| 167 | { |
| 168 | public: |
| 169 | Name |
| 170 | getInterestName() |
| 171 | { |
| 172 | return "/P"; |
| 173 | } |
| 174 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 175 | void |
| 176 | insertFibEntry(BestRouteStrategy2Fixture* fixture) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 177 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 178 | fixture->fib.insert(Name()).first->addNextHop(*fixture->face1, 10); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 179 | } |
| 180 | }; |
| 181 | |
| 182 | class NextHopViolatesScope |
| 183 | { |
| 184 | public: |
| 185 | Name |
| 186 | getInterestName() |
| 187 | { |
| 188 | return "/localhop/P"; |
| 189 | } |
| 190 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 191 | void |
| 192 | insertFibEntry(BestRouteStrategy2Fixture* fixture) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 193 | { |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 194 | fixture->fib.insert("/localhop").first->addNextHop(*fixture->face2, 10); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 195 | // 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] | 196 | } |
| 197 | }; |
| 198 | |
| 199 | typedef boost::mpl::vector<EmptyNextHopList, NextHopIsDownstream, NextHopViolatesScope> NoRouteScenarios; |
| 200 | |
| 201 | BOOST_AUTO_TEST_CASE_TEMPLATE(IncomingInterest, Scenario, NoRouteScenarios) |
| 202 | { |
| 203 | Scenario scenario; |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 204 | scenario.insertFibEntry(this); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 205 | |
| 206 | shared_ptr<Interest> interest = makeInterest(scenario.getInterestName()); |
| 207 | shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 208 | pitEntry->insertOrUpdateInRecord(*face1, *interest); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 209 | |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 210 | strategy.afterReceiveInterest(*face1, *interest, pitEntry); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 211 | |
| 212 | BOOST_REQUIRE_EQUAL(strategy.rejectPendingInterestHistory.size(), 1); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 213 | BOOST_CHECK_EQUAL(strategy.rejectPendingInterestHistory[0].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 214 | |
| 215 | BOOST_REQUIRE_EQUAL(strategy.sendNackHistory.size(), 1); |
Junxiao Shi | 8ff0a86 | 2016-08-13 04:50:50 +0000 | [diff] [blame] | 216 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].pitInterest, pitEntry->getInterest()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 217 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].outFaceId, face1->getId()); |
| 218 | BOOST_CHECK_EQUAL(strategy.sendNackHistory[0].header.getReason(), lp::NackReason::NO_ROUTE); |
| 219 | } |
| 220 | |
| 221 | BOOST_AUTO_TEST_SUITE_END() // NoRouteNack |
| 222 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 223 | BOOST_AUTO_TEST_SUITE_END() // TestBestRouteStrategy2 |
| 224 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 225 | |
| 226 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 227 | } // namespace fw |
Junxiao Shi | 986b849 | 2014-08-20 12:07:14 -0700 | [diff] [blame] | 228 | } // namespace nfd |