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