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