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