Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 28 | #include "tests/daemon/face/dummy-face.hpp" |
| 29 | #include "tests/limited-io.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 31 | #include "tests/test-common.hpp" |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 34 | namespace fw { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 35 | namespace tests { |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 36 | |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 37 | using namespace nfd::tests; |
| 38 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 39 | BOOST_AUTO_TEST_SUITE(Fw) |
| 40 | BOOST_FIXTURE_TEST_SUITE(TestNccStrategy, UnitTestTimeFixture) |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 41 | |
| 42 | // NccStrategy is fairly complex. |
| 43 | // The most important property is: |
| 44 | // it remembers which upstream is the fastest to return Data, |
| 45 | // and favors this upstream in subsequent Interests. |
| 46 | BOOST_AUTO_TEST_CASE(FavorRespondingUpstream) |
| 47 | { |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 48 | LimitedIo limitedIo(this); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 49 | Forwarder forwarder; |
| 50 | typedef StrategyTester<fw::NccStrategy> NccStrategyTester; |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 51 | shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [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>(); |
| 57 | forwarder.addFace(face1); |
| 58 | forwarder.addFace(face2); |
| 59 | forwarder.addFace(face3); |
| 60 | |
| 61 | Fib& fib = forwarder.getFib(); |
| 62 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 63 | fibEntry->addNextHop(face1, 10); |
| 64 | fibEntry->addNextHop(face2, 20); |
| 65 | |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 66 | StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 67 | strategyChoice.install(strategy); |
| 68 | strategyChoice.insert(Name(), strategy->getName()); |
| 69 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 70 | Pit& pit = forwarder.getPit(); |
| 71 | |
| 72 | // first Interest: strategy knows nothing and follows routing |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 73 | shared_ptr<Interest> interest1p = makeInterest("ndn:/0Jm1ajrW/%00"); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 74 | Interest& interest1 = *interest1p; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 75 | interest1.setInterestLifetime(time::milliseconds(8000)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 76 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(interest1).first; |
| 77 | |
| 78 | pitEntry1->insertOrUpdateInRecord(face3, interest1); |
| 79 | strategy->afterReceiveInterest(*face3, interest1, fibEntry, pitEntry1); |
| 80 | |
| 81 | // forwards to face1 because routing says it's best |
Junxiao Shi | 1553910 | 2014-10-08 22:39:51 -0700 | [diff] [blame] | 82 | // (no io run here: afterReceiveInterest has already sent the Interest) |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 83 | BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1); |
| 84 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId()); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 85 | |
| 86 | // forwards to face2 because face1 doesn't respond |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 87 | limitedIo.run(1, time::milliseconds(500), time::milliseconds(10)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 88 | BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2); |
| 89 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId()); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 90 | |
| 91 | // face2 responds |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 92 | shared_ptr<Data> data1p = makeData("ndn:/0Jm1ajrW/%00"); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 93 | Data& data1 = *data1p; |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 94 | strategy->beforeSatisfyInterest(pitEntry1, *face2, data1); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 95 | this->advanceClocks(time::milliseconds(10), time::milliseconds(500)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 96 | |
| 97 | // second Interest: strategy knows face2 is best |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 98 | shared_ptr<Interest> interest2p = makeInterest("ndn:/0Jm1ajrW/%00%01"); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 99 | Interest& interest2 = *interest2p; |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 100 | interest2.setInterestLifetime(time::milliseconds(8000)); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 101 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(interest2).first; |
| 102 | |
| 103 | pitEntry2->insertOrUpdateInRecord(face3, interest2); |
| 104 | strategy->afterReceiveInterest(*face3, interest2, fibEntry, pitEntry2); |
| 105 | |
| 106 | // forwards to face2 because it responds previously |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 107 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 108 | BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3); |
| 109 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face2->getId()); |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 112 | BOOST_AUTO_TEST_CASE(Bug1853) |
| 113 | { |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 114 | Forwarder forwarder; |
| 115 | typedef StrategyTester<fw::NccStrategy> NccStrategyTester; |
| 116 | shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder)); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 117 | |
| 118 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 119 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 120 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 121 | forwarder.addFace(face1); |
| 122 | forwarder.addFace(face2); |
| 123 | forwarder.addFace(face3); |
| 124 | |
| 125 | Fib& fib = forwarder.getFib(); |
| 126 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 127 | fibEntry->addNextHop(face1, 10); |
| 128 | |
| 129 | StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 130 | strategyChoice.install(strategy); |
| 131 | strategyChoice.insert(Name(), strategy->getName()); |
| 132 | |
| 133 | Pit& pit = forwarder.getPit(); |
| 134 | |
| 135 | // first Interest: strategy follows routing and forwards to face1 |
| 136 | shared_ptr<Interest> interest1 = makeInterest("ndn:/nztwIvHX/%00"); |
| 137 | interest1->setInterestLifetime(time::milliseconds(8000)); |
| 138 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
| 139 | |
| 140 | pitEntry1->insertOrUpdateInRecord(face3, *interest1); |
| 141 | strategy->afterReceiveInterest(*face3, *interest1, fibEntry, pitEntry1); |
| 142 | |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 143 | this->advanceClocks(time::milliseconds(1)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 144 | BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1); |
| 145 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId()); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 146 | |
| 147 | // face1 responds |
| 148 | shared_ptr<Data> data1 = makeData("ndn:/nztwIvHX/%00"); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 149 | strategy->beforeSatisfyInterest(pitEntry1, *face1, *data1); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 150 | this->advanceClocks(time::milliseconds(10), time::milliseconds(500)); |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 151 | |
| 152 | // second Interest: bestFace is face1, nUpstreams becomes 0, |
| 153 | // therefore pitEntryInfo->maxInterval cannot be calculated from deferRange and nUpstreams |
| 154 | shared_ptr<Interest> interest2 = makeInterest("ndn:/nztwIvHX/%01"); |
| 155 | interest2->setInterestLifetime(time::milliseconds(8000)); |
| 156 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first; |
| 157 | |
| 158 | pitEntry2->insertOrUpdateInRecord(face3, *interest2); |
| 159 | strategy->afterReceiveInterest(*face3, *interest2, fibEntry, pitEntry2); |
| 160 | |
| 161 | // FIB entry is changed before doPropagate executes |
| 162 | fibEntry->addNextHop(face2, 20); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 163 | this->advanceClocks(time::milliseconds(10), time::milliseconds(1000));// should not crash |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 166 | BOOST_AUTO_TEST_CASE(Bug1961) |
| 167 | { |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 168 | LimitedIo limitedIo(this); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 169 | Forwarder forwarder; |
| 170 | typedef StrategyTester<fw::NccStrategy> NccStrategyTester; |
| 171 | shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 172 | strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 173 | |
| 174 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 175 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 176 | shared_ptr<DummyFace> face3 = make_shared<DummyFace>(); |
| 177 | forwarder.addFace(face1); |
| 178 | forwarder.addFace(face2); |
| 179 | forwarder.addFace(face3); |
| 180 | |
| 181 | Fib& fib = forwarder.getFib(); |
| 182 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 183 | fibEntry->addNextHop(face1, 10); |
| 184 | fibEntry->addNextHop(face2, 20); |
| 185 | |
| 186 | StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 187 | strategyChoice.install(strategy); |
| 188 | strategyChoice.insert(Name(), strategy->getName()); |
| 189 | |
| 190 | Pit& pit = forwarder.getPit(); |
| 191 | |
| 192 | // first Interest: strategy forwards to face1 and face2 |
| 193 | shared_ptr<Interest> interest1 = makeInterest("ndn:/seRMz5a6/%00"); |
| 194 | interest1->setInterestLifetime(time::milliseconds(2000)); |
| 195 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
| 196 | |
| 197 | pitEntry1->insertOrUpdateInRecord(face3, *interest1); |
| 198 | strategy->afterReceiveInterest(*face3, *interest1, fibEntry, pitEntry1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 199 | limitedIo.run(2 - strategy->sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 200 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 201 | BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2); |
| 202 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face1->getId()); |
| 203 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId()); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 204 | |
| 205 | // face1 responds |
| 206 | shared_ptr<Data> data1 = makeData("ndn:/seRMz5a6/%00"); |
| 207 | strategy->beforeSatisfyInterest(pitEntry1, *face1, *data1); |
| 208 | pitEntry1->deleteInRecords(); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 209 | this->advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 210 | // face2 also responds |
| 211 | strategy->beforeSatisfyInterest(pitEntry1, *face2, *data1); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 212 | this->advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 213 | |
| 214 | // second Interest: bestFace should be face 1 |
| 215 | shared_ptr<Interest> interest2 = makeInterest("ndn:/seRMz5a6/%01"); |
| 216 | interest2->setInterestLifetime(time::milliseconds(2000)); |
| 217 | shared_ptr<pit::Entry> pitEntry2 = pit.insert(*interest2).first; |
| 218 | |
| 219 | pitEntry2->insertOrUpdateInRecord(face3, *interest2); |
| 220 | strategy->afterReceiveInterest(*face3, *interest2, fibEntry, pitEntry2); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 221 | limitedIo.run(3 - strategy->sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 222 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 223 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 224 | BOOST_REQUIRE_GE(strategy->sendInterestHistory.size(), 3); |
| 225 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[2].outFaceId, face1->getId()); |
Junxiao Shi | 82e7f58 | 2014-09-07 15:15:40 -0700 | [diff] [blame] | 226 | } |
Junxiao Shi | cbb490a | 2014-08-13 12:24:24 -0700 | [diff] [blame] | 227 | |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 228 | BOOST_AUTO_TEST_CASE(Bug1971) |
| 229 | { |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 230 | LimitedIo limitedIo(this); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 231 | Forwarder forwarder; |
| 232 | typedef StrategyTester<fw::NccStrategy> NccStrategyTester; |
| 233 | shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 234 | strategy->afterAction.connect(bind(&LimitedIo::afterOp, &limitedIo)); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 235 | |
| 236 | shared_ptr<DummyFace> face1 = make_shared<DummyFace>(); |
| 237 | shared_ptr<DummyFace> face2 = make_shared<DummyFace>(); |
| 238 | forwarder.addFace(face1); |
| 239 | forwarder.addFace(face2); |
| 240 | |
| 241 | Fib& fib = forwarder.getFib(); |
| 242 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 243 | fibEntry->addNextHop(face2, 10); |
| 244 | |
| 245 | StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 246 | strategyChoice.install(strategy); |
| 247 | strategyChoice.insert(Name(), strategy->getName()); |
| 248 | |
| 249 | Pit& pit = forwarder.getPit(); |
| 250 | |
| 251 | // first Interest: strategy forwards to face2 |
| 252 | shared_ptr<Interest> interest1 = makeInterest("ndn:/M4mBXCsd"); |
| 253 | interest1->setInterestLifetime(time::milliseconds(2000)); |
| 254 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
| 255 | |
| 256 | pitEntry1->insertOrUpdateInRecord(face1, *interest1); |
| 257 | strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 258 | limitedIo.run(1 - strategy->sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 259 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 260 | BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1); |
| 261 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId()); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 262 | |
| 263 | // face2 responds |
| 264 | shared_ptr<Data> data1 = makeData("ndn:/M4mBXCsd"); |
| 265 | data1->setFreshnessPeriod(time::milliseconds(5)); |
| 266 | strategy->beforeSatisfyInterest(pitEntry1, *face2, *data1); |
Junxiao Shi | b2bcbcd | 2014-11-08 09:30:28 -0700 | [diff] [blame] | 267 | pitEntry1->deleteOutRecord(*face2); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 268 | pitEntry1->deleteInRecords(); |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 269 | this->advanceClocks(time::milliseconds(10)); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 270 | |
| 271 | // similar Interest: strategy should still forward it |
| 272 | pitEntry1->insertOrUpdateInRecord(face1, *interest1); |
| 273 | strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 274 | limitedIo.run(2 - strategy->sendInterestHistory.size(), |
Junxiao Shi | 3cb4fc6 | 2014-12-25 22:17:39 -0700 | [diff] [blame] | 275 | time::milliseconds(2000), time::milliseconds(10)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 276 | BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 2); |
| 277 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[1].outFaceId, face2->getId()); |
Junxiao Shi | 8bfd56d | 2014-10-08 10:06:00 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 280 | BOOST_AUTO_TEST_CASE(Bug1998) |
| 281 | { |
| 282 | Forwarder forwarder; |
| 283 | typedef StrategyTester<fw::NccStrategy> NccStrategyTester; |
| 284 | shared_ptr<NccStrategyTester> strategy = make_shared<NccStrategyTester>(ref(forwarder)); |
| 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(); |
| 292 | shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first; |
| 293 | fibEntry->addNextHop(face1, 10); // face1 is top-ranked nexthop |
| 294 | fibEntry->addNextHop(face2, 20); |
| 295 | |
| 296 | StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 297 | strategyChoice.install(strategy); |
| 298 | strategyChoice.insert(Name(), strategy->getName()); |
| 299 | |
| 300 | Pit& pit = forwarder.getPit(); |
| 301 | |
| 302 | // Interest comes from face1, which is sole downstream |
| 303 | shared_ptr<Interest> interest1 = makeInterest("ndn:/tFy5HzUzD4"); |
| 304 | shared_ptr<pit::Entry> pitEntry1 = pit.insert(*interest1).first; |
| 305 | pitEntry1->insertOrUpdateInRecord(face1, *interest1); |
| 306 | |
| 307 | strategy->afterReceiveInterest(*face1, *interest1, fibEntry, pitEntry1); |
| 308 | |
| 309 | // Interest shall go to face2, not loop back to face1 |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 310 | BOOST_REQUIRE_EQUAL(strategy->sendInterestHistory.size(), 1); |
| 311 | BOOST_CHECK_EQUAL(strategy->sendInterestHistory[0].outFaceId, face2->getId()); |
Junxiao Shi | 6316220 | 2015-01-14 22:27:33 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 314 | BOOST_AUTO_TEST_SUITE_END() // TestNccStrategy |
| 315 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 316 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 317 | } // namespace tests |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 318 | } // namespace fw |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 319 | } // namespace nfd |