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