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