Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 2 | /* |
Teng Liang | 6308644 | 2018-02-25 20:39:42 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [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 | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 25 | |
| 26 | #include "fw/forwarder.hpp" |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 27 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 29 | #include "tests/daemon/face/dummy-face.hpp" |
| 30 | #include "choose-strategy.hpp" |
| 31 | #include "dummy-strategy.hpp" |
| 32 | |
| 33 | #include <ndn-cxx/lp/tags.hpp> |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 36 | namespace tests { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 37 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 38 | BOOST_AUTO_TEST_SUITE(Fw) |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 39 | BOOST_FIXTURE_TEST_SUITE(TestForwarder, UnitTestTimeFixture) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 41 | BOOST_AUTO_TEST_CASE(SimpleExchange) |
| 42 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 43 | Forwarder forwarder; |
| 44 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 45 | shared_ptr<Interest> interestAB = makeInterest("/A/B"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 46 | interestAB->setInterestLifetime(time::seconds(4)); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 47 | shared_ptr<Data> dataABC = makeData("/A/B/C"); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 48 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 49 | auto face1 = make_shared<DummyFace>(); |
| 50 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 51 | forwarder.addFace(face1); |
| 52 | forwarder.addFace(face2); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 53 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 54 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 55 | fib.insert("/A").first->addNextHop(*face2, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 56 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 0); |
| 58 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 0); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 59 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0); |
| 60 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 61 | face1->receiveInterest(*interestAB); |
| 62 | this->advanceClocks(time::milliseconds(100), time::seconds(1)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 63 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 64 | BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), "/A/B"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 65 | BOOST_REQUIRE(face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 66 | BOOST_CHECK_EQUAL(*face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>(), face1->getId()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 67 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 1); |
| 68 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 1); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0); |
| 70 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 71 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 0); |
| 73 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 0); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 74 | face2->receiveData(*dataABC); |
| 75 | this->advanceClocks(time::milliseconds(100), time::seconds(1)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 76 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL(face1->sentData[0].getName(), "/A/B/C"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 78 | BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 79 | BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face2->getId()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 1); |
| 81 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 1); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 84 | BOOST_AUTO_TEST_CASE(CsMatched) |
| 85 | { |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 86 | Forwarder forwarder; |
| 87 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 88 | auto face1 = make_shared<DummyFace>(); |
| 89 | auto face2 = make_shared<DummyFace>(); |
| 90 | auto face3 = make_shared<DummyFace>(); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 91 | forwarder.addFace(face1); |
| 92 | forwarder.addFace(face2); |
| 93 | forwarder.addFace(face3); |
| 94 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 95 | shared_ptr<Interest> interestA = makeInterest("/A"); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 96 | interestA->setInterestLifetime(time::seconds(4)); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 97 | shared_ptr<Data> dataA = makeData("/A"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 98 | dataA->setTag(make_shared<lp::IncomingFaceIdTag>(face3->getId())); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 99 | |
| 100 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 101 | fib.insert("/A").first->addNextHop(*face2, 0); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 102 | |
| 103 | Pit& pit = forwarder.getPit(); |
| 104 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 105 | |
| 106 | Cs& cs = forwarder.getCs(); |
Minsheng Zhang | ffe8bbb | 2016-03-10 13:40:37 -0700 | [diff] [blame] | 107 | cs.insert(*dataA); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 108 | |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 109 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0); |
| 110 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 111 | face1->receiveInterest(*interestA); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 112 | this->advanceClocks(time::milliseconds(1), time::milliseconds(5)); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 113 | // Interest matching ContentStore should not be forwarded |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 114 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 0); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 115 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 1); |
| 116 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 117 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 118 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 119 | // IncomingFaceId field should be reset to represent CS |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 120 | BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 121 | BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face::FACEID_CONTENT_STORE); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 122 | |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 123 | this->advanceClocks(time::milliseconds(100), time::milliseconds(500)); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 124 | // PIT entry should not be left behind |
| 125 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 126 | } |
| 127 | |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 128 | BOOST_AUTO_TEST_CASE(OutgoingInterest) |
| 129 | { |
| 130 | Forwarder forwarder; |
| 131 | auto face1 = make_shared<DummyFace>(); |
| 132 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 133 | forwarder.addFace(face1); |
| 134 | forwarder.addFace(face2); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 135 | |
| 136 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 137 | auto interestA1 = makeInterest("/A"); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 138 | interestA1->setNonce(8378); |
| 139 | shared_ptr<pit::Entry> pitA = pit.insert(*interestA1).first; |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 140 | pitA->insertOrUpdateInRecord(*face1, *interestA1); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 141 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 142 | auto interestA2 = makeInterest("/A"); |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 143 | interestA2->setNonce(1698); |
| 144 | forwarder.onOutgoingInterest(pitA, *face2, *interestA2); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 145 | |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 146 | pit::OutRecordCollection::iterator outA2 = pitA->getOutRecord(*face2); |
| 147 | BOOST_REQUIRE(outA2 != pitA->out_end()); |
| 148 | BOOST_CHECK_EQUAL(outA2->getLastNonce(), 1698); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 149 | |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 150 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 151 | BOOST_CHECK_EQUAL(face2->sentInterests.back().getNonce(), 1698); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 154 | BOOST_AUTO_TEST_CASE(NextHopFaceId) |
| 155 | { |
| 156 | Forwarder forwarder; |
| 157 | |
| 158 | auto face1 = make_shared<DummyFace>(); |
| 159 | auto face2 = make_shared<DummyFace>(); |
| 160 | auto face3 = make_shared<DummyFace>(); |
| 161 | forwarder.addFace(face1); |
| 162 | forwarder.addFace(face2); |
| 163 | forwarder.addFace(face3); |
| 164 | |
| 165 | Fib& fib = forwarder.getFib(); |
| 166 | fib.insert("/A").first->addNextHop(*face3, 0); |
| 167 | |
| 168 | shared_ptr<Interest> interest = makeInterest("/A/B"); |
| 169 | interest->setTag(make_shared<lp::NextHopFaceIdTag>(face2->getId())); |
| 170 | |
| 171 | face1->receiveInterest(*interest); |
| 172 | this->advanceClocks(time::milliseconds(100), time::seconds(1)); |
| 173 | BOOST_CHECK_EQUAL(face3->sentInterests.size(), 0); |
| 174 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
| 175 | BOOST_CHECK_EQUAL(face2->sentInterests.front().getName(), "/A/B"); |
| 176 | } |
| 177 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 178 | class ScopeLocalhostIncomingTestForwarder : public Forwarder |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 179 | { |
| 180 | public: |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 181 | ScopeLocalhostIncomingTestForwarder() |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 182 | { |
| 183 | } |
| 184 | |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 185 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 186 | onDataUnsolicited(Face& inFace, const Data& data) override |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 187 | { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 188 | ++onDataUnsolicited_count; |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | protected: |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 192 | void |
Davide Pesavento | 87fc0f8 | 2018-04-11 23:43:51 -0400 | [diff] [blame] | 193 | dispatchToStrategy(pit::Entry&, std::function<void(fw::Strategy&)>) override |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 194 | { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 195 | ++dispatchToStrategy_count; |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | public: |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 199 | int dispatchToStrategy_count; |
| 200 | int onDataUnsolicited_count; |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 203 | BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 204 | { |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 205 | ScopeLocalhostIncomingTestForwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 206 | auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 207 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 208 | forwarder.addFace(face1); |
| 209 | forwarder.addFace(face2); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 210 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 211 | // local face, /localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 212 | forwarder.dispatchToStrategy_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 213 | shared_ptr<Interest> i1 = makeInterest("/localhost/A1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 214 | forwarder.onIncomingInterest(*face1, *i1); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 215 | BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 216 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 217 | // non-local face, /localhost: violate |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 218 | forwarder.dispatchToStrategy_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 219 | shared_ptr<Interest> i2 = makeInterest("/localhost/A2"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 220 | forwarder.onIncomingInterest(*face2, *i2); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 221 | BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 222 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 223 | // local face, non-/localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 224 | forwarder.dispatchToStrategy_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 225 | shared_ptr<Interest> i3 = makeInterest("/A3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 226 | forwarder.onIncomingInterest(*face1, *i3); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 228 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 229 | // non-local face, non-/localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 230 | forwarder.dispatchToStrategy_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 231 | shared_ptr<Interest> i4 = makeInterest("/A4"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 232 | forwarder.onIncomingInterest(*face2, *i4); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 233 | BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 234 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 235 | // local face, /localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 236 | forwarder.onDataUnsolicited_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 237 | shared_ptr<Data> d1 = makeData("/localhost/B1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 238 | forwarder.onIncomingData(*face1, *d1); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 239 | BOOST_CHECK_EQUAL(forwarder.onDataUnsolicited_count, 1); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 240 | |
| 241 | // non-local face, /localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 242 | forwarder.onDataUnsolicited_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 243 | shared_ptr<Data> d2 = makeData("/localhost/B2"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 244 | forwarder.onIncomingData(*face2, *d2); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(forwarder.onDataUnsolicited_count, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 246 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 247 | // local face, non-/localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 248 | forwarder.onDataUnsolicited_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 249 | shared_ptr<Data> d3 = makeData("/B3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 250 | forwarder.onIncomingData(*face1, *d3); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 251 | BOOST_CHECK_EQUAL(forwarder.onDataUnsolicited_count, 1); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 252 | |
| 253 | // non-local face, non-/localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 254 | forwarder.onDataUnsolicited_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 255 | shared_ptr<Data> d4 = makeData("/B4"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 256 | forwarder.onIncomingData(*face2, *d4); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 257 | BOOST_CHECK_EQUAL(forwarder.onDataUnsolicited_count, 1); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 260 | BOOST_AUTO_TEST_CASE(IncomingInterestStrategyDispatch) |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 261 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 262 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 263 | auto face1 = make_shared<DummyFace>(); |
| 264 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 265 | forwarder.addFace(face1); |
| 266 | forwarder.addFace(face2); |
| 267 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 268 | DummyStrategy& strategyA = choose<DummyStrategy>(forwarder, "ndn:/", DummyStrategy::getStrategyName()); |
| 269 | DummyStrategy& strategyB = choose<DummyStrategy>(forwarder, "ndn:/B", DummyStrategy::getStrategyName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 270 | |
| 271 | shared_ptr<Interest> interest1 = makeInterest("ndn:/A/1"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 272 | strategyA.afterReceiveInterest_count = 0; |
| 273 | strategyA.interestOutFace = face2; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 274 | forwarder.startProcessInterest(*face1, *interest1); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 275 | BOOST_CHECK_EQUAL(strategyA.afterReceiveInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 276 | |
| 277 | shared_ptr<Interest> interest2 = makeInterest("ndn:/B/2"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 278 | strategyB.afterReceiveInterest_count = 0; |
| 279 | strategyB.interestOutFace = face2; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 280 | forwarder.startProcessInterest(*face1, *interest2); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 281 | BOOST_CHECK_EQUAL(strategyB.afterReceiveInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 282 | |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 283 | this->advanceClocks(time::milliseconds(1), time::milliseconds(5)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 284 | |
| 285 | shared_ptr<Data> data1 = makeData("ndn:/A/1/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 286 | strategyA.beforeSatisfyInterest_count = 0; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 287 | forwarder.startProcessData(*face2, *data1); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 288 | BOOST_CHECK_EQUAL(strategyA.beforeSatisfyInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 289 | |
| 290 | shared_ptr<Data> data2 = makeData("ndn:/B/2/b"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 291 | strategyB.beforeSatisfyInterest_count = 0; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 292 | forwarder.startProcessData(*face2, *data2); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 293 | BOOST_CHECK_EQUAL(strategyB.beforeSatisfyInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 294 | |
| 295 | shared_ptr<Interest> interest3 = makeInterest("ndn:/A/3"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 296 | interest3->setInterestLifetime(time::milliseconds(30)); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 297 | forwarder.startProcessInterest(*face1, *interest3); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 298 | shared_ptr<Interest> interest4 = makeInterest("ndn:/B/4"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 299 | interest4->setInterestLifetime(time::milliseconds(5000)); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 300 | forwarder.startProcessInterest(*face1, *interest4); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 303 | BOOST_AUTO_TEST_CASE(IncomingData) |
| 304 | { |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 305 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 306 | auto face1 = make_shared<DummyFace>(); |
| 307 | auto face2 = make_shared<DummyFace>(); |
| 308 | auto face3 = make_shared<DummyFace>(); |
| 309 | auto face4 = make_shared<DummyFace>(); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 310 | forwarder.addFace(face1); |
| 311 | forwarder.addFace(face2); |
Junxiao Shi | 223271b | 2014-07-03 22:06:13 -0700 | [diff] [blame] | 312 | forwarder.addFace(face3); |
| 313 | forwarder.addFace(face4); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 314 | |
| 315 | Pit& pit = forwarder.getPit(); |
| 316 | shared_ptr<Interest> interest0 = makeInterest("ndn:/"); |
| 317 | shared_ptr<pit::Entry> pit0 = pit.insert(*interest0).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 318 | pit0->insertOrUpdateInRecord(*face1, *interest0); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 319 | shared_ptr<Interest> interestA = makeInterest("ndn:/A"); |
| 320 | shared_ptr<pit::Entry> pitA = pit.insert(*interestA).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 321 | pitA->insertOrUpdateInRecord(*face1, *interestA); |
| 322 | pitA->insertOrUpdateInRecord(*face2, *interestA); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 323 | shared_ptr<Interest> interestC = makeInterest("ndn:/A/B/C"); |
| 324 | shared_ptr<pit::Entry> pitC = pit.insert(*interestC).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 325 | pitC->insertOrUpdateInRecord(*face3, *interestC); |
| 326 | pitC->insertOrUpdateInRecord(*face4, *interestC); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 327 | |
| 328 | shared_ptr<Data> dataD = makeData("ndn:/A/B/C/D"); |
| 329 | forwarder.onIncomingData(*face3, *dataD); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 330 | this->advanceClocks(time::milliseconds(1), time::milliseconds(5)); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 331 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 332 | BOOST_CHECK_EQUAL(face1->sentData.size(), 1); |
| 333 | BOOST_CHECK_EQUAL(face2->sentData.size(), 1); |
| 334 | BOOST_CHECK_EQUAL(face3->sentData.size(), 0); |
| 335 | BOOST_CHECK_EQUAL(face4->sentData.size(), 1); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 338 | BOOST_AUTO_TEST_CASE(IncomingNack) |
| 339 | { |
| 340 | Forwarder forwarder; |
| 341 | auto face1 = make_shared<DummyFace>(); |
| 342 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 343 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", |
| 344 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 345 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 346 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 347 | forwarder.addFace(face1); |
| 348 | forwarder.addFace(face2); |
| 349 | forwarder.addFace(face3); |
| 350 | |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 351 | DummyStrategy& strategyA = choose<DummyStrategy>(forwarder, "ndn:/", DummyStrategy::getStrategyName()); |
| 352 | DummyStrategy& strategyB = choose<DummyStrategy>(forwarder, "ndn:/B", DummyStrategy::getStrategyName()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 353 | |
| 354 | Pit& pit = forwarder.getPit(); |
| 355 | |
| 356 | // dispatch to the correct strategy |
| 357 | shared_ptr<Interest> interest1 = makeInterest("/A/AYJqayrzF", 562); |
| 358 | shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 359 | pit1->insertOrUpdateOutRecord(*face1, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 360 | shared_ptr<Interest> interest2 = makeInterest("/B/EVyP73ru", 221); |
| 361 | shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 362 | pit2->insertOrUpdateOutRecord(*face1, *interest2); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 363 | |
| 364 | lp::Nack nack1 = makeNack("/A/AYJqayrzF", 562, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 365 | strategyA.afterReceiveNack_count = 0; |
| 366 | strategyB.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 367 | forwarder.onIncomingNack(*face1, nack1); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 368 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 1); |
| 369 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 370 | |
| 371 | lp::Nack nack2 = makeNack("/B/EVyP73ru", 221, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 372 | strategyA.afterReceiveNack_count = 0; |
| 373 | strategyB.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 374 | forwarder.onIncomingNack(*face1, nack2); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 375 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 376 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 377 | |
| 378 | // record Nack on PIT out-record |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 379 | pit::OutRecordCollection::iterator outRecord1 = pit1->getOutRecord(*face1); |
| 380 | BOOST_REQUIRE(outRecord1 != pit1->out_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 381 | BOOST_REQUIRE(outRecord1->getIncomingNack() != nullptr); |
| 382 | BOOST_CHECK_EQUAL(outRecord1->getIncomingNack()->getReason(), lp::NackReason::CONGESTION); |
| 383 | |
| 384 | // drop if no PIT entry |
| 385 | lp::Nack nack3 = makeNack("/yEcw5HhdM", 243, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 386 | strategyA.afterReceiveNack_count = 0; |
| 387 | strategyB.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 388 | forwarder.onIncomingNack(*face1, nack3); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 389 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 390 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 391 | |
| 392 | // drop if no out-record |
| 393 | shared_ptr<Interest> interest4 = makeInterest("/Etab4KpY", 157); |
| 394 | shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 395 | pit4->insertOrUpdateOutRecord(*face1, *interest4); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 396 | |
| 397 | lp::Nack nack4a = makeNack("/Etab4KpY", 157, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 398 | strategyA.afterReceiveNack_count = 0; |
| 399 | strategyB.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 400 | forwarder.onIncomingNack(*face2, nack4a); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 401 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 402 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 403 | |
| 404 | // drop if Nonce does not match out-record |
| 405 | lp::Nack nack4b = makeNack("/Etab4KpY", 294, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 406 | strategyA.afterReceiveNack_count = 0; |
| 407 | strategyB.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 408 | forwarder.onIncomingNack(*face1, nack4b); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 409 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 410 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 411 | |
| 412 | // drop if inFace is multi-access |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 413 | pit4->insertOrUpdateOutRecord(*face3, *interest4); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 414 | strategyA.afterReceiveNack_count = 0; |
| 415 | strategyB.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 416 | forwarder.onIncomingNack(*face3, nack4a); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 417 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 418 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | BOOST_AUTO_TEST_CASE(OutgoingNack) |
| 422 | { |
| 423 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 424 | auto face1 = make_shared<DummyFace>(); |
| 425 | auto face2 = make_shared<DummyFace>(); |
| 426 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", |
| 427 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 428 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 429 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 430 | forwarder.addFace(face1); |
| 431 | forwarder.addFace(face2); |
| 432 | forwarder.addFace(face3); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 433 | |
| 434 | Pit& pit = forwarder.getPit(); |
| 435 | |
| 436 | lp::NackHeader nackHeader; |
| 437 | nackHeader.setReason(lp::NackReason::CONGESTION); |
| 438 | |
| 439 | // don't send Nack if there's no in-record |
| 440 | shared_ptr<Interest> interest1 = makeInterest("/fM5IVEtC", 719); |
| 441 | shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 442 | pit1->insertOrUpdateInRecord(*face1, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 443 | |
| 444 | face2->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 445 | forwarder.onOutgoingNack(pit1, *face2, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 446 | BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0); |
| 447 | |
| 448 | // send Nack with correct Nonce |
| 449 | shared_ptr<Interest> interest2a = makeInterest("/Vi8tRm9MG3", 152); |
| 450 | shared_ptr<pit::Entry> pit2 = pit.insert(*interest2a).first; |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 451 | pit2->insertOrUpdateInRecord(*face1, *interest2a); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 452 | shared_ptr<Interest> interest2b = makeInterest("/Vi8tRm9MG3", 808); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 453 | pit2->insertOrUpdateInRecord(*face2, *interest2b); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 454 | |
| 455 | face1->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 456 | forwarder.onOutgoingNack(pit2, *face1, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 457 | BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1); |
| 458 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::CONGESTION); |
| 459 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest().getNonce(), 152); |
| 460 | |
| 461 | // erase in-record |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 462 | pit::InRecordCollection::iterator inRecord2a = pit2->getInRecord(*face1); |
| 463 | BOOST_CHECK(inRecord2a == pit2->in_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 464 | |
| 465 | // send Nack with correct Nonce |
| 466 | face2->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 467 | forwarder.onOutgoingNack(pit2, *face2, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 468 | BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1); |
| 469 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::CONGESTION); |
| 470 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest().getNonce(), 808); |
| 471 | |
| 472 | // erase in-record |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 473 | pit::InRecordCollection::iterator inRecord2b = pit2->getInRecord(*face1); |
| 474 | BOOST_CHECK(inRecord2b == pit2->in_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 475 | |
| 476 | // don't send Nack to multi-access face |
| 477 | shared_ptr<Interest> interest2c = makeInterest("/Vi8tRm9MG3", 228); |
Junxiao Shi | 9cff779 | 2016-08-01 21:45:11 +0000 | [diff] [blame] | 478 | pit2->insertOrUpdateInRecord(*face3, *interest2c); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 479 | |
| 480 | face3->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 481 | forwarder.onOutgoingNack(pit1, *face3, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 482 | BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0); |
| 483 | } |
| 484 | |
| 485 | BOOST_AUTO_TEST_CASE(InterestLoopNack) |
| 486 | { |
| 487 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 488 | auto face1 = make_shared<DummyFace>(); |
| 489 | auto face2 = make_shared<DummyFace>(); |
| 490 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", |
| 491 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 492 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 493 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 494 | auto face4 = make_shared<DummyFace>(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 495 | forwarder.addFace(face1); |
| 496 | forwarder.addFace(face2); |
| 497 | forwarder.addFace(face3); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 498 | forwarder.addFace(face4); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 499 | |
| 500 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 501 | fib.insert("/zT4XwK0Hnx").first->addNextHop(*face4, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 502 | |
| 503 | // receive Interest on face1 |
| 504 | face1->sentNacks.clear(); |
| 505 | shared_ptr<Interest> interest1a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 506 | face1->receiveInterest(*interest1a); |
| 507 | BOOST_CHECK(face1->sentNacks.empty()); |
| 508 | |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 509 | // receive Interest with duplicate Nonce on face1: legit retransmission |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 510 | face1->sentNacks.clear(); |
| 511 | shared_ptr<Interest> interest1b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 512 | face1->receiveInterest(*interest1b); |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 513 | BOOST_CHECK(face1->sentNacks.empty()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 514 | |
| 515 | // receive Interest with duplicate Nonce on face2 |
| 516 | face2->sentNacks.clear(); |
| 517 | shared_ptr<Interest> interest2a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 518 | face2->receiveInterest(*interest2a); |
| 519 | BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1); |
| 520 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest(), *interest2a); |
| 521 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::DUPLICATE); |
| 522 | |
| 523 | // receive Interest with new Nonce on face2 |
| 524 | face2->sentNacks.clear(); |
| 525 | shared_ptr<Interest> interest2b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 944); |
| 526 | face2->receiveInterest(*interest2b); |
| 527 | BOOST_CHECK(face2->sentNacks.empty()); |
| 528 | |
| 529 | // receive Interest with duplicate Nonce on face3, don't send Nack to multi-access face |
| 530 | face3->sentNacks.clear(); |
| 531 | shared_ptr<Interest> interest3a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 532 | face3->receiveInterest(*interest3a); |
| 533 | BOOST_CHECK(face3->sentNacks.empty()); |
| 534 | } |
| 535 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 536 | BOOST_FIXTURE_TEST_CASE(InterestLoopWithShortLifetime, UnitTestTimeFixture) // Bug 1953 |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 537 | { |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 538 | Forwarder forwarder; |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 539 | auto face1 = make_shared<DummyFace>(); |
| 540 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 541 | forwarder.addFace(face1); |
| 542 | forwarder.addFace(face2); |
| 543 | |
| 544 | // cause an Interest sent out of face2 to loop back into face1 after a delay |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 545 | face2->afterSend.connect([face1, face2] (uint32_t pktType) { |
| 546 | if (pktType == tlv::Interest) { |
| 547 | auto interest = make_shared<Interest>(face2->sentInterests.back()); |
| 548 | scheduler::schedule(time::milliseconds(170), [face1, interest] { face1->receiveInterest(*interest); }); |
| 549 | } |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 550 | }); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 551 | |
| 552 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 553 | fib.insert("/A").first->addNextHop(*face2, 0); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 554 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 555 | // receive an Interest |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 556 | shared_ptr<Interest> interest = makeInterest("ndn:/A/1"); |
| 557 | interest->setNonce(82101183); |
| 558 | interest->setInterestLifetime(time::milliseconds(50)); |
| 559 | face1->receiveInterest(*interest); |
| 560 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 561 | // interest should be forwarded only once, as long as Nonce is in Dead Nonce List |
| 562 | BOOST_ASSERT(time::milliseconds(25) * 40 < forwarder.getDeadNonceList().getLifetime()); |
| 563 | this->advanceClocks(time::milliseconds(25), 40); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 564 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 565 | BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 566 | |
| 567 | // It's unnecessary to check that Interest with duplicate Nonce can be forwarded again |
| 568 | // after it's gone from Dead Nonce List, because the entry lifetime of Dead Nonce List |
| 569 | // is an implementation decision. NDN protocol requires Name+Nonce to be unique, |
| 570 | // without specifying when Name+Nonce could repeat. Forwarder is permitted to suppress |
| 571 | // an Interest if its Name+Nonce has appeared any point in the past. |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 574 | BOOST_AUTO_TEST_CASE(PitLeak) // Bug 3484 |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 575 | { |
| 576 | Forwarder forwarder; |
| 577 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 578 | forwarder.addFace(face1); |
| 579 | |
| 580 | shared_ptr<Interest> interest = makeInterest("ndn:/hcLSAsQ9A"); |
| 581 | interest->setNonce(61883075); |
| 582 | interest->setInterestLifetime(time::seconds(2)); |
| 583 | |
| 584 | DeadNonceList& dnl = forwarder.getDeadNonceList(); |
| 585 | dnl.add(interest->getName(), interest->getNonce()); |
| 586 | Pit& pit = forwarder.getPit(); |
| 587 | BOOST_REQUIRE_EQUAL(pit.size(), 0); |
| 588 | |
| 589 | forwarder.startProcessInterest(*face1, *interest); |
| 590 | this->advanceClocks(time::milliseconds(100), time::seconds(20)); |
| 591 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 592 | } |
| 593 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 594 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 595 | BOOST_AUTO_TEST_SUITE_END() |
| 596 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 597 | } // namespace tests |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 598 | } // namespace nfd |