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