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