Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -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. |
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 | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 25 | |
| 26 | #include "fw/ncc-strategy.hpp" |
| 27 | #include "strategy-tester.hpp" |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 28 | #include "topology-tester.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 29 | #include "tests/daemon/face/dummy-face.hpp" |
| 30 | #include "tests/limited-io.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 31 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 32 | #include "tests/test-common.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 35 | namespace fw { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 36 | namespace tests { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 37 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 38 | using namespace nfd::tests; |
| 39 | |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 40 | typedef StrategyTester<NccStrategy> NccStrategyTester; |
| 41 | NFD_REGISTER_STRATEGY(NccStrategyTester); |
| 42 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 43 | BOOST_AUTO_TEST_SUITE(Fw) |
| 44 | BOOST_FIXTURE_TEST_SUITE(TestNccStrategy, UnitTestTimeFixture) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 45 | |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 46 | BOOST_AUTO_TEST_CASE(Registration) |
| 47 | { |
Junxiao Shi | 037f4ab | 2016-12-13 04:27:06 +0000 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(Strategy::listRegistered().count(NccStrategy::getStrategyName()), 1); |
Junxiao Shi | c34d167 | 2016-12-09 15:57:59 +0000 | [diff] [blame] | 49 | } |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 50 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 51 | // NccStrategy is fairly complex. |
| 52 | // The most important property is: |
| 53 | // it remembers which upstream is the fastest to return Data, |
| 54 | // and favors this upstream in subsequent Interests. |
| 55 | BOOST_AUTO_TEST_CASE(FavorRespondingUpstream) |
| 56 | { |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 57 | LimitedIo limitedIo(this); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 58 | Forwarder forwarder; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 59 | NccStrategyTester& strategy = choose<NccStrategyTester>(forwarder); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 60 | strategy.afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 61 | |
| 62 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 63 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 64 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 65 | forwarder.addFace(face1); |
| 66 | forwarder.addFace(face2); |
| 67 | forwarder.addFace(face3); |
| 68 | |
| 69 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 70 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 71 | fibEntry.addNextHop(*face1, 10); |
| 72 | fibEntry.addNextHop(*face2, 20); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 73 | |
| 74 | Pit& pit = forwarder.getPit(); |
| 75 | |
| 76 | // first Interest: strategy knows nothing and follows routing |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 77 | shared_ptr<Interest> interest1p = makeInterest("ndn:/0Jm1ajrW/%00"); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 78 | Interest& interest1 = *interest1p; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 79 | interest1.setInterestLifetime(time::milliseconds(8000)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 80 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(interest1).first; |
| 81 | |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 82 | pitEntry1->insertOrUpdateInRecord(*face3, interest1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 83 | strategy.afterReceiveInterest(*face3, interest1, pitEntry1); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 84 | |
| 85 | // forwards to face1 because routing says it's best |
Junxiao Shi | 1553910 | 2014-10-08 22:39:51 -0700 | [diff] [blame] | 86 | // (no io run here: afterReceiveInterest has already sent the Interest) |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 87 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 88 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId()); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 89 | |
| 90 | // forwards to face2 because face1 doesn't respond |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 91 | limitedIo.run(1, time::milliseconds(500), time::milliseconds(10)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 92 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 93 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face2->getId()); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 94 | |
| 95 | // face2 responds |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 96 | shared_ptr<Data> data1p = makeData("ndn:/0Jm1ajrW/%00"); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 97 | Data& data1 = *data1p; |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 98 | strategy.beforeSatisfyInterest(pitEntry1, *face2, data1); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 99 | this->advanceClocks(time::milliseconds(10), time::milliseconds(500)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 100 | |
| 101 | // second Interest: strategy knows face2 is best |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 102 | shared_ptr<Interest> interest2p = makeInterest("ndn:/0Jm1ajrW/%00%01"); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 103 | Interest& interest2 = *interest2p; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 104 | interest2.setInterestLifetime(time::milliseconds(8000)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 105 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(interest2).first; |
| 106 | |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 107 | pitEntry2->insertOrUpdateInRecord(*face3, interest2); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 108 | strategy.afterReceiveInterest(*face3, interest2, pitEntry2); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 109 | |
| 110 | // forwards to face2 because it responds previously |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 111 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 112 | BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 3); |
| 113 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face2->getId()); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 116 | BOOST_AUTO_TEST_CASE(Bug1853) |
| 117 | { |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 118 | Forwarder forwarder; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 119 | NccStrategyTester& strategy = choose<NccStrategyTester>(forwarder); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 120 | |
| 121 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 122 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 123 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 124 | forwarder.addFace(face1); |
| 125 | forwarder.addFace(face2); |
| 126 | forwarder.addFace(face3); |
| 127 | |
| 128 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 129 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 130 | fibEntry.addNextHop(*face1, 10); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 131 | |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 132 | Pit& pit = forwarder.getPit(); |
| 133 | |
| 134 | // first Interest: strategy follows routing and forwards to face1 |
| 135 | shared_ptr<Interest> interest1 = makeInterest("ndn:/nztwIvHX/%00"); |
| 136 | interest1->setInterestLifetime(time::milliseconds(8000)); |
| 137 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
| 138 | |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 139 | pitEntry1->insertOrUpdateInRecord(*face3, *interest1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 140 | strategy.afterReceiveInterest(*face3, *interest1, pitEntry1); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 141 | |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 142 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 143 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 144 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId()); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 145 | |
| 146 | // face1 responds |
| 147 | shared_ptr<Data> data1 = makeData("ndn:/nztwIvHX/%00"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 148 | strategy.beforeSatisfyInterest(pitEntry1, *face1, *data1); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 149 | this->advanceClocks(time::milliseconds(10), time::milliseconds(500)); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 150 | |
| 151 | // second Interest: bestFace is face1, nUpstreams becomes 0, |
| 152 | // therefore pitEntryInfo->maxInterval cannot be calculated from deferRange and nUpstreams |
| 153 | shared_ptr<Interest> interest2 = makeInterest("ndn:/nztwIvHX/%01"); |
| 154 | interest2->setInterestLifetime(time::milliseconds(8000)); |
| 155 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first; |
| 156 | |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 157 | pitEntry2->insertOrUpdateInRecord(*face3, *interest2); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 158 | strategy.afterReceiveInterest(*face3, *interest2, pitEntry2); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 159 | |
| 160 | // FIB entry is changed before doPropagate executes |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 161 | fibEntry.addNextHop(*face2, 20); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 162 | this->advanceClocks(time::milliseconds(10), time::milliseconds(1000));// should not crash |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 165 | BOOST_AUTO_TEST_CASE(Bug1961) |
| 166 | { |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 167 | LimitedIo limitedIo(this); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 168 | Forwarder forwarder; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 169 | NccStrategyTester& strategy = choose<NccStrategyTester>(forwarder); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 170 | strategy.afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 171 | |
| 172 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 173 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 174 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 175 | forwarder.addFace(face1); |
| 176 | forwarder.addFace(face2); |
| 177 | forwarder.addFace(face3); |
| 178 | |
| 179 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 180 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 181 | fibEntry.addNextHop(*face1, 10); |
| 182 | fibEntry.addNextHop(*face2, 20); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 183 | |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 184 | Pit& pit = forwarder.getPit(); |
| 185 | |
| 186 | // first Interest: strategy forwards to face1 and face2 |
| 187 | shared_ptr<Interest> interest1 = makeInterest("ndn:/seRMz5a6/%00"); |
| 188 | interest1->setInterestLifetime(time::milliseconds(2000)); |
| 189 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
| 190 | |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 191 | pitEntry1->insertOrUpdateInRecord(*face3, *interest1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 192 | strategy.afterReceiveInterest(*face3, *interest1, pitEntry1); |
| 193 | limitedIo.run(2 - strategy.sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 194 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 195 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 196 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face1->getId()); |
| 197 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face2->getId()); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 198 | |
| 199 | // face1 responds |
| 200 | shared_ptr<Data> data1 = makeData("ndn:/seRMz5a6/%00"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 201 | strategy.beforeSatisfyInterest(pitEntry1, *face1, *data1); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 202 | pitEntry1->clearInRecords(); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 203 | this->advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 204 | // face2 also responds |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 205 | strategy.beforeSatisfyInterest(pitEntry1, *face2, *data1); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 206 | this->advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 207 | |
| 208 | // second Interest: bestFace should be face 1 |
| 209 | shared_ptr<Interest> interest2 = makeInterest("ndn:/seRMz5a6/%01"); |
| 210 | interest2->setInterestLifetime(time::milliseconds(2000)); |
| 211 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first; |
| 212 | |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 213 | pitEntry2->insertOrUpdateInRecord(*face3, *interest2); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 214 | strategy.afterReceiveInterest(*face3, *interest2, pitEntry2); |
| 215 | limitedIo.run(3 - strategy.sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 216 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 217 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 218 | BOOST_REQUIRE_GE(strategy.sendInterestHistory.size(), 3); |
| 219 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[2].outFaceId, face1->getId()); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 220 | } |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 221 | |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 222 | BOOST_AUTO_TEST_CASE(Bug1971) |
| 223 | { |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 224 | LimitedIo limitedIo(this); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 225 | Forwarder forwarder; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 226 | NccStrategyTester& strategy = choose<NccStrategyTester>(forwarder); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 227 | strategy.afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo)); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 228 | |
| 229 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 230 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 231 | forwarder.addFace(face1); |
| 232 | forwarder.addFace(face2); |
| 233 | |
| 234 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 235 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 236 | fibEntry.addNextHop(*face2, 10); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 237 | |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 238 | Pit& pit = forwarder.getPit(); |
| 239 | |
| 240 | // first Interest: strategy forwards to face2 |
| 241 | shared_ptr<Interest> interest1 = makeInterest("ndn:/M4mBXCsd"); |
| 242 | interest1->setInterestLifetime(time::milliseconds(2000)); |
| 243 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
| 244 | |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 245 | pitEntry1->insertOrUpdateInRecord(*face1, *interest1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 246 | strategy.afterReceiveInterest(*face1, *interest1, pitEntry1); |
| 247 | limitedIo.run(1 - strategy.sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 248 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 249 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 250 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId()); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 251 | |
| 252 | // face2 responds |
| 253 | shared_ptr<Data> data1 = makeData("ndn:/M4mBXCsd"); |
| 254 | data1->setFreshnessPeriod(time::milliseconds(5)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 255 | strategy.beforeSatisfyInterest(pitEntry1, *face2, *data1); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 256 | pitEntry1->deleteOutRecord(*face2); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 257 | pitEntry1->clearInRecords(); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 258 | this->advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 259 | |
| 260 | // similar Interest: strategy should still forward it |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 261 | pitEntry1->insertOrUpdateInRecord(*face1, *interest1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 262 | strategy.afterReceiveInterest(*face1, *interest1, pitEntry1); |
| 263 | limitedIo.run(2 - strategy.sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 264 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 265 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 2); |
| 266 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[1].outFaceId, face2->getId()); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 269 | BOOST_AUTO_TEST_CASE(Bug1998) |
| 270 | { |
| 271 | Forwarder forwarder; |
Junxiao Shi | 890afe9 | 2016-12-15 14:34:34 +0000 | [diff] [blame] | 272 | NccStrategyTester& strategy = choose<NccStrategyTester>(forwarder); |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 273 | |
| 274 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 275 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 276 | forwarder.addFace(face1); |
| 277 | forwarder.addFace(face2); |
| 278 | |
| 279 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 280 | fib::Entry& fibEntry = *fib.insert(Name()).first; |
| 281 | fibEntry.addNextHop(*face1, 10); // face1 is top-ranked nexthop |
| 282 | fibEntry.addNextHop(*face2, 20); |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 283 | |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 284 | Pit& pit = forwarder.getPit(); |
| 285 | |
| 286 | // Interest comes from face1, which is sole downstream |
| 287 | shared_ptr<Interest> interest1 = makeInterest("ndn:/tFy5HzUzD4"); |
| 288 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 289 | pitEntry1->insertOrUpdateInRecord(*face1, *interest1); |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 290 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 291 | strategy.afterReceiveInterest(*face1, *interest1, pitEntry1); |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 292 | |
| 293 | // Interest shall go to face2, not loop back to face1 |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 294 | BOOST_REQUIRE_EQUAL(strategy.sendInterestHistory.size(), 1); |
| 295 | BOOST_CHECK_EQUAL(strategy.sendInterestHistory[0].outFaceId, face2->getId()); |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 298 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(PredictionAdjustment, 1) |
| 299 | BOOST_AUTO_TEST_CASE(PredictionAdjustment) // Bug 3411 |
| 300 | { |
| 301 | /* |
| 302 | * /----------\ |
| 303 | * | consumer | |
| 304 | * \----------/ |
| 305 | * | |
| 306 | * | |
| 307 | * +---+ 5ms +---+ |
| 308 | * | A |-------| B | |
| 309 | * +---+ +---+ |
| 310 | * | | |
| 311 | * | 5ms | 15ms/5ms |
| 312 | * | | |
| 313 | * +---+ +---+ |
| 314 | * | C |-------| D | |
| 315 | * +---+ 15ms +---+ |
| 316 | * /5ms | |
| 317 | * | |
| 318 | * /----------\ |
| 319 | * | producer | |
| 320 | * \----------/ |
| 321 | */ |
| 322 | |
| 323 | TopologyTester topo; |
| 324 | TopologyNode nodeA = topo.addForwarder("A"), |
| 325 | nodeB = topo.addForwarder("B"), |
| 326 | nodeC = topo.addForwarder("C"), |
| 327 | nodeD = topo.addForwarder("D"); |
| 328 | |
| 329 | for (TopologyNode node : {nodeA, nodeB, nodeC, nodeD}) { |
| 330 | topo.setStrategy<NccStrategy>(node); |
| 331 | } |
| 332 | |
| 333 | shared_ptr<TopologyLink> linkAB = topo.addLink("AB", time::milliseconds( 5), {nodeA, nodeB}), |
| 334 | linkAC = topo.addLink("AC", time::milliseconds( 5), {nodeA, nodeC}), |
| 335 | linkBD = topo.addLink("BD", time::milliseconds(15), {nodeB, nodeD}), |
| 336 | linkCD = topo.addLink("CD", time::milliseconds(15), {nodeC, nodeD}); |
| 337 | |
| 338 | topo.registerPrefix(nodeA, linkAB->getFace(nodeA), "ndn:/P"); |
| 339 | topo.registerPrefix(nodeA, linkAC->getFace(nodeA), "ndn:/P"); |
| 340 | topo.registerPrefix(nodeB, linkBD->getFace(nodeB), "ndn:/P"); |
| 341 | topo.registerPrefix(nodeC, linkCD->getFace(nodeC), "ndn:/P"); |
| 342 | |
| 343 | shared_ptr<TopologyAppLink> producer = topo.addAppFace("producer", nodeD, "ndn:/P"); |
| 344 | topo.addEchoProducer(producer->getClientFace()); |
| 345 | |
| 346 | shared_ptr<TopologyAppLink> consumer = topo.addAppFace("consumer", nodeA); |
| 347 | topo.addIntervalConsumer(consumer->getClientFace(), "ndn:/P", |
| 348 | time::milliseconds(100), 300); |
| 349 | |
Junxiao Shi | fc02186 | 2016-08-25 21:51:18 +0000 | [diff] [blame] | 350 | auto getMeInfo = [&] () -> NccStrategy::MeasurementsEntryInfo* { |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 351 | Measurements& measurements = topo.getForwarder(nodeA).getMeasurements(); |
Junxiao Shi | 80f9fcd | 2016-07-23 02:48:36 +0000 | [diff] [blame] | 352 | measurements::Entry* me = measurements.findExactMatch("ndn:/P"); |
Hila Ben Abraham | 39a79be | 2016-03-30 22:00:55 -0700 | [diff] [blame] | 353 | return me == nullptr ? nullptr : me->getStrategyInfo<NccStrategy::MeasurementsEntryInfo>(); |
| 354 | }; |
| 355 | |
| 356 | // NccStrategy starts with an exploration period when the algorithm adjusts |
| 357 | // its prediction to converge near the path RTT. |
| 358 | bool isExplorationFinished = false; |
| 359 | const time::milliseconds TRUE_RTT1(40); |
| 360 | bool isLastPredictionUnder = true; |
| 361 | int nPredictionCrossings = 0; |
| 362 | for (int i = 0; i < 10000; ++i) { |
| 363 | this->advanceClocks(time::milliseconds(5)); |
| 364 | auto meInfo = getMeInfo(); |
| 365 | if (meInfo == nullptr) { |
| 366 | continue; |
| 367 | } |
| 368 | |
| 369 | if ((isLastPredictionUnder && meInfo->prediction > TRUE_RTT1) || |
| 370 | (!isLastPredictionUnder && meInfo->prediction < TRUE_RTT1)) { |
| 371 | isLastPredictionUnder = !isLastPredictionUnder; |
| 372 | if (++nPredictionCrossings > 6) { |
| 373 | isExplorationFinished = true; |
| 374 | BOOST_TEST_MESSAGE("exploration finishes after " << (i * 5) << "ms"); |
| 375 | break; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | BOOST_REQUIRE_MESSAGE(isExplorationFinished, "exploration does not finish in 50000ms"); |
| 380 | |
| 381 | // NccStrategy has selected one path as the best. |
| 382 | // When we reduce the RTT of the other path, ideally it should be selected as the best face. |
| 383 | // However, this won't happen due to a weakness in NccStrategy. |
| 384 | // See http://redmine.named-data.net/issues/3411#note-4 |
| 385 | shared_ptr<Face> bestFace1 = getMeInfo()->bestFace.lock(); |
| 386 | if (bestFace1.get() == &linkAB->getFace(nodeA)) { |
| 387 | linkCD->setDelay(time::milliseconds(5)); |
| 388 | } |
| 389 | else if (bestFace1.get() == &linkAC->getFace(nodeA)) { |
| 390 | linkBD->setDelay(time::milliseconds(5)); |
| 391 | } |
| 392 | else { |
| 393 | BOOST_FAIL("unexpected best face"); |
| 394 | } |
| 395 | |
| 396 | bool isNewBestChosen = false; |
| 397 | for (int i = 0; i < 10000; ++i) { |
| 398 | this->advanceClocks(time::milliseconds(5)); |
| 399 | auto meInfo = getMeInfo(); |
| 400 | if (meInfo == nullptr) { |
| 401 | continue; |
| 402 | } |
| 403 | |
| 404 | if (meInfo->bestFace.lock() != bestFace1) { |
| 405 | isNewBestChosen = true; |
| 406 | BOOST_TEST_MESSAGE("new best face is found after " << (i * 5) << "ms"); |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | BOOST_CHECK_MESSAGE(isNewBestChosen, "new best face is not found in 50000ms"); // expected failure |
| 411 | } |
| 412 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 413 | BOOST_AUTO_TEST_SUITE_END() // TestNccStrategy |
| 414 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 415 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 416 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 417 | } // namespace fw |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 418 | } // namespace nfd |