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