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 | /* |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, 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 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | namespace nfd::tests { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 38 | |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 39 | class ForwarderFixture : public GlobalIoTimeFixture |
| 40 | { |
| 41 | protected: |
| 42 | template<typename ...Args> |
| 43 | shared_ptr<DummyFace> |
| 44 | addFace(Args&&... args) |
| 45 | { |
| 46 | auto face = make_shared<DummyFace>(std::forward<Args>(args)...); |
| 47 | faceTable.add(face); |
| 48 | return face; |
| 49 | } |
| 50 | |
| 51 | protected: |
| 52 | FaceTable faceTable; |
| 53 | Forwarder forwarder{faceTable}; |
| 54 | }; |
| 55 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 56 | BOOST_AUTO_TEST_SUITE(Fw) |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 57 | BOOST_FIXTURE_TEST_SUITE(TestForwarder, ForwarderFixture) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 59 | BOOST_AUTO_TEST_CASE(SimpleExchange) |
| 60 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 61 | auto face1 = addFace(); |
| 62 | auto face2 = addFace(); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 63 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 64 | Fib& fib = forwarder.getFib(); |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 65 | fib::Entry* entry = fib.insert("/A").first; |
| 66 | fib.addOrUpdateNextHop(*entry, *face2, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 67 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 0); |
| 69 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 0); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0); |
| 71 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 72 | face1->receiveInterest(*makeInterest("/A/B")); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 73 | this->advanceClocks(100_ms, 1_s); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 74 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), "/A/B"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 76 | BOOST_REQUIRE(face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 77 | BOOST_CHECK_EQUAL(*face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>(), face1->getId()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 78 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 1); |
| 79 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 1); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0); |
| 81 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 1); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(forwarder.getCounters().nSatisfiedInterests, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 83 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 0); |
| 85 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 0); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 86 | face2->receiveData(*makeData("/A/B")); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 87 | this->advanceClocks(100_ms, 1_s); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 88 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(face1->sentData[0].getName(), "/A/B"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 90 | BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 91 | BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face2->getId()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 92 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 1); |
| 93 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 1); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInNacks, 0); |
| 95 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutNacks, 0); |
| 96 | BOOST_CHECK_EQUAL(forwarder.getCounters().nSatisfiedInterests, 1); |
| 97 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 0); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 100 | BOOST_AUTO_TEST_CASE(CsMatched) |
| 101 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 102 | auto face1 = addFace(); |
| 103 | auto face2 = addFace(); |
| 104 | auto face3 = addFace(); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 105 | |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 106 | Fib& fib = forwarder.getFib(); |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 107 | fib::Entry* entry = fib.insert("/A").first; |
| 108 | fib.addOrUpdateNextHop(*entry, *face2, 0); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 109 | |
| 110 | Pit& pit = forwarder.getPit(); |
| 111 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 112 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 113 | auto data = makeData("/A/B"); |
| 114 | data->setTag(make_shared<lp::IncomingFaceIdTag>(face3->getId())); |
| 115 | forwarder.getCs().insert(*data); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 116 | |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 117 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 0); |
| 118 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 119 | face1->receiveInterest(*makeInterest("/A", true)); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 120 | this->advanceClocks(1_ms, 5_ms); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 121 | // Interest matching ContentStore should not be forwarded |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 122 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 0); |
Junxiao Shi | 06a1eab | 2017-09-04 13:13:02 +0000 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsHits, 1); |
| 124 | BOOST_CHECK_EQUAL(forwarder.getCounters().nCsMisses, 0); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 125 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 126 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 127 | // IncomingFaceId field should be reset to represent CS |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(face1->sentData[0].getName(), "/A/B"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 129 | BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 130 | 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] | 131 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 132 | this->advanceClocks(100_ms, 500_ms); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 133 | // PIT entry should not be left behind |
| 134 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 135 | } |
| 136 | |
Eric Newberry | fdc0645 | 2020-06-23 22:40:16 -0700 | [diff] [blame] | 137 | BOOST_AUTO_TEST_CASE(InterestWithoutNonce) |
| 138 | { |
| 139 | auto face1 = addFace(); |
| 140 | auto face2 = addFace(); |
| 141 | |
| 142 | Fib& fib = forwarder.getFib(); |
| 143 | fib::Entry* entry = fib.insert("/A").first; |
| 144 | fib.addOrUpdateNextHop(*entry, *face2, 0); |
| 145 | |
| 146 | auto interest = makeInterest("/A"); |
| 147 | BOOST_CHECK_EQUAL(interest->hasNonce(), false); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 148 | face1->receiveInterest(*interest); |
Eric Newberry | fdc0645 | 2020-06-23 22:40:16 -0700 | [diff] [blame] | 149 | |
| 150 | // Ensure Nonce added if incoming packet did not have Nonce |
| 151 | BOOST_REQUIRE_EQUAL(face2->getCounters().nOutInterests, 1); |
| 152 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
| 153 | BOOST_CHECK_EQUAL(face2->sentInterests.back().hasNonce(), true); |
| 154 | } |
| 155 | |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 156 | BOOST_AUTO_TEST_CASE(OutgoingInterest) |
| 157 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 158 | auto face1 = addFace(); |
| 159 | auto face2 = addFace(); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 160 | |
| 161 | Pit& pit = forwarder.getPit(); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 162 | auto interestA1 = makeInterest("/A", false, std::nullopt, 8378); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 163 | auto pitA = pit.insert(*interestA1).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 164 | pitA->insertOrUpdateInRecord(*face1, *interestA1); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 165 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 166 | auto interestA2 = makeInterest("/A", false, std::nullopt, 1698); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 167 | auto outA2 = forwarder.onOutgoingInterest(*interestA2, *face2, pitA); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 168 | BOOST_REQUIRE(outA2 != nullptr); |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 169 | BOOST_CHECK_EQUAL(outA2->getLastNonce(), 1698); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 170 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 171 | // This packet will be dropped because HopLimit=0 |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 172 | auto interestA3 = makeInterest("/A", false, std::nullopt, 9876); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 173 | interestA3->setHopLimit(0); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 174 | auto outA3 = forwarder.onOutgoingInterest(*interestA3, *face2, pitA); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 175 | BOOST_CHECK(outA3 == nullptr); |
| 176 | |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 177 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | c5f651f | 2016-11-17 22:58:12 +0000 | [diff] [blame] | 178 | BOOST_CHECK_EQUAL(face2->sentInterests.back().getNonce(), 1698); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 181 | BOOST_AUTO_TEST_CASE(NextHopFaceId) |
| 182 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 183 | auto face1 = addFace(); |
| 184 | auto face2 = addFace(); |
| 185 | auto face3 = addFace(); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 186 | |
| 187 | Fib& fib = forwarder.getFib(); |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 188 | fib::Entry* entry = fib.insert("/A").first; |
| 189 | fib.addOrUpdateNextHop(*entry, *face3, 0); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 190 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 191 | auto interest = makeInterest("/A/B"); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 192 | interest->setTag(make_shared<lp::NextHopFaceIdTag>(face2->getId())); |
| 193 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 194 | face1->receiveInterest(*interest); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 195 | this->advanceClocks(100_ms, 1_s); |
Junxiao Shi | e342e8d | 2016-09-18 16:48:00 +0000 | [diff] [blame] | 196 | BOOST_CHECK_EQUAL(face3->sentInterests.size(), 0); |
| 197 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
| 198 | BOOST_CHECK_EQUAL(face2->sentInterests.front().getName(), "/A/B"); |
| 199 | } |
| 200 | |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame] | 201 | BOOST_AUTO_TEST_CASE(HopLimit) |
| 202 | { |
| 203 | auto faceIn = addFace(); |
| 204 | auto faceRemote = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 205 | auto faceLocal = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 206 | Fib& fib = forwarder.getFib(); |
| 207 | fib::Entry* entryRemote = fib.insert("/remote").first; |
| 208 | fib.addOrUpdateNextHop(*entryRemote, *faceRemote, 0); |
| 209 | fib::Entry* entryLocal = fib.insert("/local").first; |
| 210 | fib.addOrUpdateNextHop(*entryLocal, *faceLocal, 0); |
| 211 | |
| 212 | // Incoming interest w/o HopLimit will not be dropped on send or receive paths |
| 213 | auto interestNoHopLimit = makeInterest("/remote/abcdefgh"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 214 | faceIn->receiveInterest(*interestNoHopLimit); |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame] | 215 | this->advanceClocks(100_ms, 1_s); |
| 216 | BOOST_CHECK_EQUAL(faceRemote->sentInterests.size(), 1); |
| 217 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nInHopLimitZero, 0); |
| 218 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 0); |
| 219 | BOOST_REQUIRE_EQUAL(faceRemote->sentInterests.size(), 1); |
| 220 | BOOST_CHECK(!faceRemote->sentInterests.back().getHopLimit()); |
| 221 | |
| 222 | // Incoming interest w/ HopLimit > 1 will not be dropped on send/receive |
| 223 | auto interestHopLimit2 = makeInterest("/remote/ijklmnop"); |
| 224 | interestHopLimit2->setHopLimit(2); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 225 | faceIn->receiveInterest(*interestHopLimit2); |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame] | 226 | this->advanceClocks(100_ms, 1_s); |
| 227 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutInterests, 2); |
| 228 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nInHopLimitZero, 0); |
| 229 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 0); |
| 230 | BOOST_REQUIRE_EQUAL(faceRemote->sentInterests.size(), 2); |
| 231 | BOOST_REQUIRE(faceRemote->sentInterests.back().getHopLimit()); |
| 232 | BOOST_CHECK_EQUAL(*faceRemote->sentInterests.back().getHopLimit(), 1); |
| 233 | |
| 234 | // Incoming interest w/ HopLimit == 1 will be dropped on send path if going out on remote face |
| 235 | auto interestHopLimit1Remote = makeInterest("/remote/qrstuvwx"); |
| 236 | interestHopLimit1Remote->setHopLimit(1); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 237 | faceIn->receiveInterest(*interestHopLimit1Remote); |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame] | 238 | this->advanceClocks(100_ms, 1_s); |
| 239 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutInterests, 2); |
| 240 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nInHopLimitZero, 0); |
| 241 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 1); |
| 242 | BOOST_CHECK_EQUAL(faceRemote->sentInterests.size(), 2); |
| 243 | |
| 244 | // Incoming interest w/ HopLimit == 1 will not be dropped on send path if going out on local face |
| 245 | auto interestHopLimit1Local = makeInterest("/local/abcdefgh"); |
| 246 | interestHopLimit1Local->setHopLimit(1); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 247 | faceIn->receiveInterest(*interestHopLimit1Local); |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame] | 248 | this->advanceClocks(100_ms, 1_s); |
| 249 | BOOST_CHECK_EQUAL(faceLocal->getCounters().nOutInterests, 1); |
| 250 | BOOST_CHECK_EQUAL(faceLocal->getCounters().nInHopLimitZero, 0); |
| 251 | BOOST_CHECK_EQUAL(faceLocal->getCounters().nOutHopLimitZero, 0); |
| 252 | BOOST_REQUIRE_EQUAL(faceLocal->sentInterests.size(), 1); |
| 253 | BOOST_REQUIRE(faceLocal->sentInterests.back().getHopLimit()); |
| 254 | BOOST_CHECK_EQUAL(*faceLocal->sentInterests.back().getHopLimit(), 0); |
| 255 | |
| 256 | // Interest w/ HopLimit == 0 will be dropped on receive path |
| 257 | auto interestHopLimit0 = makeInterest("/remote/yzabcdef"); |
| 258 | interestHopLimit0->setHopLimit(0); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 259 | faceIn->receiveInterest(*interestHopLimit0); |
Eric Newberry | 9d283ad | 2020-04-12 23:37:17 -0700 | [diff] [blame] | 260 | this->advanceClocks(100_ms, 1_s); |
| 261 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutInterests, 2); |
| 262 | BOOST_CHECK_EQUAL(faceIn->getCounters().nInHopLimitZero, 1); |
| 263 | BOOST_CHECK_EQUAL(faceRemote->getCounters().nOutHopLimitZero, 1); |
| 264 | BOOST_CHECK_EQUAL(faceRemote->sentInterests.size(), 2); |
| 265 | } |
| 266 | |
Philipp Moll | a103334 | 2021-06-14 09:34:21 +0200 | [diff] [blame] | 267 | BOOST_AUTO_TEST_CASE(AddDefaultHopLimit) |
| 268 | { |
| 269 | auto face = addFace(); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 270 | auto faceEndpoint = FaceEndpoint(*face); |
Philipp Moll | a103334 | 2021-06-14 09:34:21 +0200 | [diff] [blame] | 271 | Pit& pit = forwarder.getPit(); |
| 272 | auto i1 = makeInterest("/A"); |
| 273 | auto pitA = pit.insert(*i1).first; |
| 274 | |
| 275 | // By default, no HopLimit should be added |
| 276 | auto i2 = makeInterest("/A"); |
| 277 | BOOST_TEST(!i2->getHopLimit().has_value()); |
| 278 | forwarder.onContentStoreMiss(*i2, faceEndpoint, pitA); |
| 279 | BOOST_TEST(!i2->getHopLimit().has_value()); |
| 280 | |
| 281 | // Change config value to 10 |
| 282 | forwarder.m_config.defaultHopLimit = 10; |
| 283 | |
| 284 | // HopLimit should be set to 10 now |
| 285 | auto i3 = makeInterest("/A"); |
| 286 | BOOST_TEST(!i3->getHopLimit().has_value()); |
| 287 | forwarder.onContentStoreMiss(*i3, faceEndpoint, pitA); |
| 288 | BOOST_REQUIRE(i3->getHopLimit().has_value()); |
| 289 | BOOST_TEST(*i3->getHopLimit() == 10); |
| 290 | |
| 291 | // An existing HopLimit should be preserved |
| 292 | auto i4 = makeInterest("/A"); |
| 293 | i4->setHopLimit(50); |
| 294 | forwarder.onContentStoreMiss(*i4, faceEndpoint, pitA); |
| 295 | BOOST_REQUIRE(i4->getHopLimit().has_value()); |
| 296 | BOOST_TEST(*i4->getHopLimit() == 50); |
| 297 | } |
| 298 | |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 299 | BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 300 | { |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 301 | auto face1 = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 302 | auto face2 = addFace(); // default is non-local |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 303 | |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 304 | auto& strategy = choose<DummyStrategy>(forwarder, "/", DummyStrategy::getStrategyName()); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 305 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 306 | // local face, /localhost: OK |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 307 | strategy.afterReceiveInterest_count = 0; |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 308 | auto i1 = makeInterest("/localhost/A1"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 309 | forwarder.onIncomingInterest(*i1, FaceEndpoint(*face1)); |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 310 | BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 311 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 312 | // non-local face, /localhost: violate |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 313 | strategy.afterReceiveInterest_count = 0; |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 314 | auto i2 = makeInterest("/localhost/A2"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 315 | forwarder.onIncomingInterest(*i2, FaceEndpoint(*face2)); |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 316 | BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 317 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 318 | // local face, non-/localhost: OK |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 319 | strategy.afterReceiveInterest_count = 0; |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 320 | auto i3 = makeInterest("/A3"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 321 | forwarder.onIncomingInterest(*i3, FaceEndpoint(*face1)); |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 322 | BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 323 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 324 | // non-local face, non-/localhost: OK |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 325 | strategy.afterReceiveInterest_count = 0; |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 326 | auto i4 = makeInterest("/A4"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 327 | forwarder.onIncomingInterest(*i4, FaceEndpoint(*face2)); |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 328 | BOOST_CHECK_EQUAL(strategy.afterReceiveInterest_count, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 329 | |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 330 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 0); |
| 331 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 332 | // local face, /localhost: OK |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 333 | auto d1 = makeData("/localhost/B1"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 334 | forwarder.onIncomingData(*d1, FaceEndpoint(*face1)); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 335 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 1); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 336 | |
Davide Pesavento | 0559047 | 2021-02-17 15:53:27 -0500 | [diff] [blame] | 337 | // non-local face, /localhost: violate |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 338 | auto d2 = makeData("/localhost/B2"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 339 | forwarder.onIncomingData(*d2, FaceEndpoint(*face2)); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 340 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 341 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 342 | // local face, non-/localhost: OK |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 343 | auto d3 = makeData("/B3"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 344 | forwarder.onIncomingData(*d3, FaceEndpoint(*face1)); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 345 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 2); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 346 | |
| 347 | // non-local face, non-/localhost: OK |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 348 | auto d4 = makeData("/B4"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 349 | forwarder.onIncomingData(*d4, FaceEndpoint(*face2)); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 350 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 3); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 353 | BOOST_AUTO_TEST_CASE(IncomingInterestStrategyDispatch) |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 354 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 355 | auto face1 = addFace(); |
| 356 | auto face2 = addFace(); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 357 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 358 | auto& strategyA = choose<DummyStrategy>(forwarder, "/", DummyStrategy::getStrategyName()); |
| 359 | auto& strategyB = choose<DummyStrategy>(forwarder, "/B", DummyStrategy::getStrategyName()); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 360 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 361 | auto interest1 = makeInterest("/A/1"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 362 | strategyA.afterReceiveInterest_count = 0; |
| 363 | strategyA.interestOutFace = face2; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 364 | forwarder.onIncomingInterest(*interest1, FaceEndpoint(*face1)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 365 | BOOST_CHECK_EQUAL(strategyA.afterReceiveInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 366 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 367 | auto interest2 = makeInterest("/B/2", true); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 368 | strategyB.afterReceiveInterest_count = 0; |
| 369 | strategyB.interestOutFace = face2; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 370 | forwarder.onIncomingInterest(*interest2, FaceEndpoint(*face1)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 371 | BOOST_CHECK_EQUAL(strategyB.afterReceiveInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 372 | |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 373 | this->advanceClocks(1_ms, 5_ms); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 374 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 375 | auto data1 = makeData("/A/1"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 376 | strategyA.beforeSatisfyInterest_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 377 | forwarder.onIncomingData(*data1, FaceEndpoint(*face2)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 378 | BOOST_CHECK_EQUAL(strategyA.beforeSatisfyInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 379 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 380 | auto data2 = makeData("/B/2/b"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 381 | strategyB.beforeSatisfyInterest_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 382 | forwarder.onIncomingData(*data2, FaceEndpoint(*face2)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 383 | BOOST_CHECK_EQUAL(strategyB.beforeSatisfyInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 384 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 385 | auto interest3 = makeInterest("/A/3", false, 30_ms); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 386 | forwarder.onIncomingInterest(*interest3, FaceEndpoint(*face1)); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 387 | auto interest4 = makeInterest("/B/4", false, 5_s); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 388 | forwarder.onIncomingInterest(*interest4, FaceEndpoint(*face1)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 391 | BOOST_AUTO_TEST_CASE(IncomingData) |
| 392 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 393 | auto face1 = addFace(); |
| 394 | auto face2 = addFace(); |
| 395 | auto face3 = addFace(); |
| 396 | auto face4 = addFace(); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 397 | |
| 398 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 399 | auto interestD = makeInterest("/A/B/C/D"); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 400 | auto pitD = pit.insert(*interestD).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 401 | pitD->insertOrUpdateInRecord(*face1, *interestD); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 402 | auto interestA = makeInterest("/A", true); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 403 | auto pitA = pit.insert(*interestA).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 404 | pitA->insertOrUpdateInRecord(*face2, *interestA); |
| 405 | pitA->insertOrUpdateInRecord(*face3, *interestA); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 406 | auto interestC = makeInterest("/A/B/C", true); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 407 | auto pitC = pit.insert(*interestC).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 408 | pitC->insertOrUpdateInRecord(*face3, *interestC); |
| 409 | pitC->insertOrUpdateInRecord(*face4, *interestC); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 410 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 411 | auto dataD = makeData("/A/B/C/D"); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 412 | forwarder.onIncomingData(*dataD, FaceEndpoint(*face3)); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 413 | this->advanceClocks(1_ms, 5_ms); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 414 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 415 | BOOST_CHECK_EQUAL(face1->sentData.size(), 1); |
| 416 | BOOST_CHECK_EQUAL(face2->sentData.size(), 1); |
| 417 | BOOST_CHECK_EQUAL(face3->sentData.size(), 0); |
| 418 | BOOST_CHECK_EQUAL(face4->sentData.size(), 1); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 419 | |
| 420 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 1); |
| 421 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 3); |
| 422 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 0); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 425 | BOOST_AUTO_TEST_CASE(OutgoingData) |
| 426 | { |
| 427 | auto face1 = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 428 | auto face2 = addFace("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 429 | auto face3 = addFace(); |
| 430 | face3->setId(face::INVALID_FACEID); |
| 431 | |
| 432 | auto data = makeData("/QkzAWU6K"); |
| 433 | auto localData = makeData("/localhost/YH8bqnbv"); |
| 434 | |
| 435 | face1->sentData.clear(); |
| 436 | BOOST_CHECK(forwarder.onOutgoingData(*data, *face1)); |
| 437 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
| 438 | BOOST_CHECK_EQUAL(face1->sentData.back().getName(), data->getName()); |
| 439 | |
| 440 | // scope control |
| 441 | face1->sentData.clear(); |
| 442 | face2->sentData.clear(); |
| 443 | BOOST_CHECK(!forwarder.onOutgoingData(*localData, *face2)); |
| 444 | BOOST_CHECK_EQUAL(face2->sentData.size(), 0); |
| 445 | BOOST_CHECK(forwarder.onOutgoingData(*localData, *face1)); |
| 446 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
| 447 | BOOST_CHECK_EQUAL(face1->sentData.back().getName(), localData->getName()); |
| 448 | |
| 449 | // face with invalid ID |
| 450 | face3->sentData.clear(); |
| 451 | BOOST_CHECK(!forwarder.onOutgoingData(*data, *face3)); |
| 452 | BOOST_CHECK_EQUAL(face3->sentData.size(), 0); |
| 453 | } |
| 454 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 455 | BOOST_AUTO_TEST_CASE(IncomingNack) |
| 456 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 457 | auto face1 = addFace(); |
| 458 | auto face2 = addFace(); |
| 459 | auto face3 = addFace("dummy://", "dummy://", |
| 460 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 461 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 462 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 463 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 464 | auto& strategyA = choose<DummyStrategy>(forwarder, "/", DummyStrategy::getStrategyName()); |
| 465 | auto& strategyB = choose<DummyStrategy>(forwarder, "/B", DummyStrategy::getStrategyName()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 466 | |
| 467 | Pit& pit = forwarder.getPit(); |
| 468 | |
| 469 | // dispatch to the correct strategy |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 470 | auto interest1 = makeInterest("/A/AYJqayrzF", false, std::nullopt, 562); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 471 | auto pit1 = pit.insert(*interest1).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 472 | pit1->insertOrUpdateOutRecord(*face1, *interest1); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 473 | auto interest2 = makeInterest("/B/EVyP73ru", false, std::nullopt, 221); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 474 | auto pit2 = pit.insert(*interest2).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 475 | pit2->insertOrUpdateOutRecord(*face1, *interest2); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 476 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 477 | auto nack1 = makeNack(*interest1, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 478 | strategyA.afterReceiveNack_count = 0; |
| 479 | strategyB.afterReceiveNack_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 480 | forwarder.onIncomingNack(nack1, FaceEndpoint(*face1)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 481 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 1); |
| 482 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 483 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 484 | auto nack2 = makeNack(*interest2, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 485 | strategyA.afterReceiveNack_count = 0; |
| 486 | strategyB.afterReceiveNack_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 487 | forwarder.onIncomingNack(nack2, FaceEndpoint(*face1)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 488 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 489 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 490 | |
| 491 | // record Nack on PIT out-record |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 492 | auto outRecord1 = pit1->getOutRecord(*face1); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 493 | BOOST_REQUIRE(outRecord1 != pit1->out_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 494 | BOOST_REQUIRE(outRecord1->getIncomingNack() != nullptr); |
| 495 | BOOST_CHECK_EQUAL(outRecord1->getIncomingNack()->getReason(), lp::NackReason::CONGESTION); |
| 496 | |
| 497 | // drop if no PIT entry |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 498 | auto nack3 = makeNack(*makeInterest("/yEcw5HhdM", false, std::nullopt, 243), lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 499 | strategyA.afterReceiveNack_count = 0; |
| 500 | strategyB.afterReceiveNack_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 501 | forwarder.onIncomingNack(nack3, FaceEndpoint(*face1)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 502 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 503 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 504 | |
| 505 | // drop if no out-record |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 506 | auto interest4 = makeInterest("/Etab4KpY", false, std::nullopt, 157); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 507 | auto pit4 = pit.insert(*interest4).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 508 | pit4->insertOrUpdateOutRecord(*face1, *interest4); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 509 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 510 | auto nack4a = makeNack(*interest4, lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 511 | strategyA.afterReceiveNack_count = 0; |
| 512 | strategyB.afterReceiveNack_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 513 | forwarder.onIncomingNack(nack4a, FaceEndpoint(*face2)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 514 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 515 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 516 | |
| 517 | // drop if Nonce does not match out-record |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 518 | auto nack4b = makeNack(*makeInterest("/Etab4KpY", false, std::nullopt, 294), lp::NackReason::CONGESTION); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 519 | strategyA.afterReceiveNack_count = 0; |
| 520 | strategyB.afterReceiveNack_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 521 | forwarder.onIncomingNack(nack4b, FaceEndpoint(*face1)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 522 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 523 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 524 | |
| 525 | // drop if inFace is multi-access |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 526 | pit4->insertOrUpdateOutRecord(*face3, *interest4); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 527 | strategyA.afterReceiveNack_count = 0; |
| 528 | strategyB.afterReceiveNack_count = 0; |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 529 | forwarder.onIncomingNack(nack4a, FaceEndpoint(*face3)); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 530 | BOOST_CHECK_EQUAL(strategyA.afterReceiveNack_count, 0); |
| 531 | BOOST_CHECK_EQUAL(strategyB.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | BOOST_AUTO_TEST_CASE(OutgoingNack) |
| 535 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 536 | auto face1 = addFace(); |
| 537 | auto face2 = addFace(); |
| 538 | auto face3 = addFace("dummy://", "dummy://", |
| 539 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 540 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 541 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 542 | auto face4 = addFace(); |
| 543 | face4->setId(face::INVALID_FACEID); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 544 | |
| 545 | Pit& pit = forwarder.getPit(); |
| 546 | |
| 547 | lp::NackHeader nackHeader; |
| 548 | nackHeader.setReason(lp::NackReason::CONGESTION); |
| 549 | |
| 550 | // don't send Nack if there's no in-record |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 551 | auto interest1 = makeInterest("/fM5IVEtC", false, std::nullopt, 719); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 552 | auto pit1 = pit.insert(*interest1).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 553 | pit1->insertOrUpdateInRecord(*face1, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 554 | |
| 555 | face2->sentNacks.clear(); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 556 | BOOST_CHECK(!forwarder.onOutgoingNack(nackHeader, *face2, pit1)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 557 | BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0); |
| 558 | |
| 559 | // send Nack with correct Nonce |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 560 | auto interest2a = makeInterest("/Vi8tRm9MG3", false, std::nullopt, 152); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 561 | auto pit2 = pit.insert(*interest2a).first; |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 562 | pit2->insertOrUpdateInRecord(*face1, *interest2a); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 563 | auto interest2b = makeInterest("/Vi8tRm9MG3", false, std::nullopt, 808); |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 564 | pit2->insertOrUpdateInRecord(*face2, *interest2b); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 565 | face1->sentNacks.clear(); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 566 | face2->sentNacks.clear(); |
| 567 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 568 | BOOST_CHECK(forwarder.onOutgoingNack(nackHeader, *face1, pit2)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 569 | BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1); |
| 570 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::CONGESTION); |
| 571 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest().getNonce(), 152); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 572 | BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 573 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 574 | // in-record is erased |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 575 | auto inRecord2a = pit2->getInRecord(*face1); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 576 | BOOST_CHECK(inRecord2a == pit2->in_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 577 | |
| 578 | // send Nack with correct Nonce |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 579 | BOOST_CHECK(forwarder.onOutgoingNack(nackHeader, *face2, pit2)); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 580 | BOOST_CHECK_EQUAL(face1->sentNacks.size(), 1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 581 | BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1); |
| 582 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::CONGESTION); |
| 583 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest().getNonce(), 808); |
| 584 | |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 585 | // in-record is erased |
| 586 | auto inRecord2b = pit2->getInRecord(*face2); |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 587 | BOOST_CHECK(inRecord2b == pit2->in_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 588 | |
| 589 | // don't send Nack to multi-access face |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 590 | auto interest2c = makeInterest("/Vi8tRm9MG3", false, std::nullopt, 228); |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 591 | pit2->insertOrUpdateInRecord(*face3, *interest2c); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 592 | |
| 593 | face3->sentNacks.clear(); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 594 | BOOST_CHECK(!forwarder.onOutgoingNack(nackHeader, *face3, pit2)); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 595 | BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 596 | |
| 597 | // don't send Nack to face with invalid ID |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 598 | auto interest1b = makeInterest("/fM5IVEtC", false, std::nullopt, 553); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 599 | pit1->insertOrUpdateInRecord(*face4, *interest1b); |
| 600 | |
| 601 | face4->sentNacks.clear(); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 602 | BOOST_CHECK(!forwarder.onOutgoingNack(nackHeader, *face4, pit1)); |
Eric Newberry | 2377ada | 2020-09-28 22:40:14 -0700 | [diff] [blame] | 603 | BOOST_CHECK_EQUAL(face4->sentNacks.size(), 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | BOOST_AUTO_TEST_CASE(InterestLoopNack) |
| 607 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 608 | auto face1 = addFace(); |
| 609 | auto face2 = addFace(); |
| 610 | auto face3 = addFace("dummy://", "dummy://", |
| 611 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 612 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 613 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 614 | auto face4 = addFace(); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 615 | |
| 616 | Fib& fib = forwarder.getFib(); |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 617 | fib::Entry* entry = fib.insert("/zT4XwK0Hnx").first; |
| 618 | fib.addOrUpdateNextHop(*entry, *face4, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 619 | |
| 620 | // receive Interest on face1 |
| 621 | face1->sentNacks.clear(); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 622 | auto interest1a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 623 | face1->receiveInterest(*interest1a); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 624 | BOOST_CHECK(face1->sentNacks.empty()); |
| 625 | |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 626 | // receive Interest with duplicate Nonce on face1: legit retransmission |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 627 | face1->sentNacks.clear(); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 628 | auto interest1b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 629 | face1->receiveInterest(*interest1b); |
Junxiao Shi | 2fe3af0 | 2017-03-04 17:24:19 +0000 | [diff] [blame] | 630 | BOOST_CHECK(face1->sentNacks.empty()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 631 | |
| 632 | // receive Interest with duplicate Nonce on face2 |
| 633 | face2->sentNacks.clear(); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 634 | auto interest2a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 635 | face2->receiveInterest(*interest2a); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 636 | BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1); |
Davide Pesavento | 7890a9f | 2019-08-25 23:11:18 -0400 | [diff] [blame] | 637 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest().wireEncode(), interest2a->wireEncode()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 638 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::DUPLICATE); |
| 639 | |
| 640 | // receive Interest with new Nonce on face2 |
| 641 | face2->sentNacks.clear(); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 642 | auto interest2b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 944); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 643 | face2->receiveInterest(*interest2b); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 644 | BOOST_CHECK(face2->sentNacks.empty()); |
| 645 | |
| 646 | // receive Interest with duplicate Nonce on face3, don't send Nack to multi-access face |
| 647 | face3->sentNacks.clear(); |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 648 | auto interest3a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", false, std::nullopt, 732); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 649 | face3->receiveInterest(*interest3a); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 650 | BOOST_CHECK(face3->sentNacks.empty()); |
| 651 | } |
| 652 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 653 | BOOST_AUTO_TEST_CASE(InterestLoopWithShortLifetime) // Bug 1953 |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 654 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 655 | auto face1 = addFace(); |
| 656 | auto face2 = addFace(); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 657 | |
| 658 | // 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] | 659 | face2->afterSend.connect([face1, face2] (uint32_t pktType) { |
| 660 | if (pktType == tlv::Interest) { |
| 661 | auto interest = make_shared<Interest>(face2->sentInterests.back()); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 662 | getScheduler().schedule(170_ms, [face1, interest] { face1->receiveInterest(*interest); }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 663 | } |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 664 | }); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 665 | |
| 666 | Fib& fib = forwarder.getFib(); |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 667 | fib::Entry* entry = fib.insert("/A").first; |
| 668 | fib.addOrUpdateNextHop(*entry, *face2, 0); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 669 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 670 | // receive an Interest |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 671 | auto interest = makeInterest("/A/1", false, 50_ms, 82101183); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 672 | face1->receiveInterest(*interest); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 673 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 674 | // 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] | 675 | BOOST_ASSERT(25_ms * 40 < forwarder.getDeadNonceList().getLifetime()); |
| 676 | this->advanceClocks(25_ms, 40); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 677 | BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 678 | |
| 679 | // It's unnecessary to check that Interest with duplicate Nonce can be forwarded again |
| 680 | // after it's gone from Dead Nonce List, because the entry lifetime of Dead Nonce List |
| 681 | // is an implementation decision. NDN protocol requires Name+Nonce to be unique, |
| 682 | // without specifying when Name+Nonce could repeat. Forwarder is permitted to suppress |
| 683 | // 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] | 684 | } |
| 685 | |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 686 | BOOST_AUTO_TEST_CASE(PitLeak) // Bug 3484 |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 687 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 688 | auto face1 = addFace(); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 689 | auto interest = makeInterest("/hcLSAsQ9A", false, 2_s, 61883075); |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 690 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 691 | auto& dnl = forwarder.getDeadNonceList(); |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 692 | dnl.add(interest->getName(), interest->getNonce()); |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 693 | auto& pit = forwarder.getPit(); |
| 694 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 695 | |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 696 | forwarder.onIncomingInterest(*interest, FaceEndpoint(*face1)); |
Davide Pesavento | 14e71f0 | 2019-03-28 17:35:25 -0400 | [diff] [blame] | 697 | this->advanceClocks(100_ms, 20_s); |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 698 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 699 | } |
| 700 | |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 701 | BOOST_AUTO_TEST_CASE(UnsolicitedData) |
| 702 | { |
| 703 | auto face1 = addFace(); |
| 704 | auto data = makeData("/A"); |
| 705 | |
| 706 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 0); |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 707 | forwarder.onIncomingData(*data, FaceEndpoint(*face1)); |
Alex Lane | 6bead9b | 2020-05-12 19:08:20 -0500 | [diff] [blame] | 708 | this->advanceClocks(1_ms, 10_ms); |
| 709 | BOOST_CHECK_EQUAL(forwarder.getCounters().nUnsolicitedData, 1); |
| 710 | } |
| 711 | |
Davide Pesavento | b21bed8 | 2021-02-13 00:20:06 -0500 | [diff] [blame] | 712 | BOOST_AUTO_TEST_CASE(NewNextHop) |
| 713 | { |
| 714 | auto face1 = addFace(); |
| 715 | auto face2 = addFace(); |
| 716 | auto face3 = addFace(); |
| 717 | auto face4 = addFace(); |
| 718 | |
| 719 | auto& strategy = choose<DummyStrategy>(forwarder, "/A", DummyStrategy::getStrategyName()); |
| 720 | |
| 721 | Fib& fib = forwarder.getFib(); |
| 722 | Pit& pit = forwarder.getPit(); |
| 723 | |
| 724 | // fib: "/", "/A/B", "/A/B/C/D/E" |
| 725 | fib::Entry* entry = fib.insert("/").first; |
| 726 | fib.addOrUpdateNextHop(*entry, *face1, 100); |
| 727 | entry = fib.insert("/A/B").first; |
| 728 | fib.addOrUpdateNextHop(*entry, *face2, 0); |
| 729 | entry = fib.insert("/A/B/C/D/E").first; |
| 730 | fib.addOrUpdateNextHop(*entry, *face3, 0); |
| 731 | |
| 732 | // pit: "/A", "/A/B/C", "/A/B/Z" |
| 733 | auto interest1 = makeInterest("/A"); |
| 734 | auto pit1 = pit.insert(*interest1).first; |
| 735 | pit1->insertOrUpdateInRecord(*face3, *interest1); |
| 736 | auto interest2 = makeInterest("/A/B/C"); |
| 737 | auto pit2 = pit.insert(*interest2).first; |
| 738 | pit2->insertOrUpdateInRecord(*face3, *interest2); |
| 739 | auto interest3 = makeInterest("/A/B/Z"); |
| 740 | auto pit3 = pit.insert(*interest3).first; |
| 741 | pit3->insertOrUpdateInRecord(*face3, *interest3); |
| 742 | |
| 743 | // new nexthop for "/" |
| 744 | entry = fib.insert("/").first; |
| 745 | fib.addOrUpdateNextHop(*entry, *face2, 50); |
| 746 | |
| 747 | // /A --> triggered |
| 748 | // /A/B/C --> not triggered |
| 749 | // /A/B/Z --> not triggered |
| 750 | BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 1); |
| 751 | BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A"); |
| 752 | strategy.afterNewNextHopCalls.clear(); |
| 753 | |
| 754 | // new nexthop for "/A" |
| 755 | entry = fib.insert("/A").first; |
| 756 | fib.addOrUpdateNextHop(*entry, *face4, 50); |
| 757 | |
| 758 | // /A --> triggered |
| 759 | // /A/B/C --> not triggered |
| 760 | // /A/B/Z --> not triggered |
| 761 | BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 1); |
| 762 | BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A"); |
| 763 | strategy.afterNewNextHopCalls.clear(); |
| 764 | |
| 765 | // new nexthop for "/A/B" |
| 766 | entry = fib.insert("/A/B").first; |
| 767 | fib.addOrUpdateNextHop(*entry, *face4, 0); |
| 768 | |
| 769 | // /A --> not triggered |
| 770 | // /A/B/C --> triggered |
| 771 | // /A/B/Z --> triggered |
| 772 | BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 2); |
| 773 | BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A/B/C"); |
| 774 | BOOST_TEST(strategy.afterNewNextHopCalls[1] == "/A/B/Z"); |
| 775 | strategy.afterNewNextHopCalls.clear(); |
| 776 | |
| 777 | // new nexthop for "/A/B/C/D" |
| 778 | entry = fib.insert("/A/B/C/D").first; |
| 779 | fib.addOrUpdateNextHop(*entry, *face1, 0); |
| 780 | |
| 781 | // nothing triggered |
| 782 | BOOST_TEST(strategy.afterNewNextHopCalls.size() == 0); |
| 783 | |
| 784 | // create a second pit entry for /A |
| 785 | auto interest4 = makeInterest("/A"); |
| 786 | interest4->setMustBeFresh(true); |
| 787 | auto pit4 = pit.insert(*interest4).first; |
| 788 | pit4->insertOrUpdateInRecord(*face3, *interest4); |
| 789 | |
| 790 | // new nexthop for "/A" |
| 791 | entry = fib.insert("/A").first; |
| 792 | fib.addOrUpdateNextHop(*entry, *face1, 0); |
| 793 | |
| 794 | // /A --> triggered twice |
| 795 | // /A/B/C --> not triggered |
| 796 | // /A/B/Z --> not triggered |
| 797 | BOOST_TEST_REQUIRE(strategy.afterNewNextHopCalls.size() == 2); |
| 798 | BOOST_TEST(strategy.afterNewNextHopCalls[0] == "/A"); |
| 799 | BOOST_TEST(strategy.afterNewNextHopCalls[1] == "/A"); |
| 800 | } |
| 801 | |
Philipp Moll | a103334 | 2021-06-14 09:34:21 +0200 | [diff] [blame] | 802 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
| 803 | |
| 804 | BOOST_AUTO_TEST_CASE(DefaultHopLimit) |
| 805 | { |
| 806 | ConfigFile cf; |
| 807 | forwarder.setConfigFile(cf); |
| 808 | |
| 809 | std::string config = R"CONFIG( |
| 810 | forwarder |
| 811 | { |
| 812 | default_hop_limit 10 |
| 813 | } |
| 814 | )CONFIG"; |
| 815 | |
| 816 | // The default value is 0 |
| 817 | BOOST_TEST(forwarder.m_config.defaultHopLimit == 0); |
| 818 | |
| 819 | // Dry run parsing should not change the default config |
| 820 | cf.parse(config, true, "dummy-config"); |
| 821 | BOOST_TEST(forwarder.m_config.defaultHopLimit == 0); |
| 822 | |
| 823 | // Check if the actual parsing works |
| 824 | cf.parse(config, false, "dummy-config"); |
| 825 | BOOST_TEST(forwarder.m_config.defaultHopLimit == 10); |
| 826 | |
| 827 | // After removing default_hop_limit from the config file, |
| 828 | // the default value of zero should be restored |
| 829 | config = R"CONFIG( |
| 830 | forwarder |
| 831 | { |
| 832 | } |
| 833 | )CONFIG"; |
| 834 | |
| 835 | cf.parse(config, false, "dummy-config"); |
| 836 | BOOST_TEST(forwarder.m_config.defaultHopLimit == 0); |
| 837 | } |
| 838 | |
| 839 | BOOST_AUTO_TEST_CASE(BadDefaultHopLimit) |
| 840 | { |
| 841 | ConfigFile cf; |
| 842 | forwarder.setConfigFile(cf); |
| 843 | |
| 844 | // not a number |
| 845 | std::string config = R"CONFIG( |
| 846 | forwarder |
| 847 | { |
| 848 | default_hop_limit hello |
| 849 | } |
| 850 | )CONFIG"; |
| 851 | |
| 852 | BOOST_CHECK_THROW(cf.parse(config, true, "dummy-config"), ConfigFile::Error); |
| 853 | BOOST_CHECK_THROW(cf.parse(config, false, "dummy-config"), ConfigFile::Error); |
| 854 | |
| 855 | // negative number |
| 856 | config = R"CONFIG( |
| 857 | forwarder |
| 858 | { |
| 859 | default_hop_limit -1 |
| 860 | } |
| 861 | )CONFIG"; |
| 862 | |
| 863 | BOOST_CHECK_THROW(cf.parse(config, true, "dummy-config"), ConfigFile::Error); |
| 864 | BOOST_CHECK_THROW(cf.parse(config, false, "dummy-config"), ConfigFile::Error); |
| 865 | |
| 866 | // out of range |
| 867 | config = R"CONFIG( |
| 868 | forwarder |
| 869 | { |
| 870 | default_hop_limit 256 |
| 871 | } |
| 872 | )CONFIG"; |
| 873 | |
| 874 | BOOST_CHECK_THROW(cf.parse(config, true, "dummy-config"), ConfigFile::Error); |
| 875 | BOOST_CHECK_THROW(cf.parse(config, false, "dummy-config"), ConfigFile::Error); |
| 876 | } |
| 877 | |
| 878 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 879 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 880 | BOOST_AUTO_TEST_SUITE_END() // TestForwarder |
| 881 | BOOST_AUTO_TEST_SUITE_END() // Fw |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 882 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 883 | } // namespace nfd::tests |