Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [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. |
| 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/>. |
| 24 | */ |
| 25 | |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 26 | #include "tests/test-common.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 27 | #include "tests/daemon/global-io-fixture.hpp" |
| 28 | #include "tests/daemon/face/dummy-face.hpp" |
| 29 | #include "choose-strategy.hpp" |
| 30 | #include "dummy-strategy.hpp" |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 31 | |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 32 | #include <ndn-cxx/lp/tags.hpp> |
| 33 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 34 | namespace nfd::tests { |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 35 | |
| 36 | BOOST_AUTO_TEST_SUITE(Fw) |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 37 | BOOST_FIXTURE_TEST_SUITE(TestPitExpiry, GlobalIoTimeFixture) |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 38 | |
| 39 | class PitExpiryTestStrategy : public DummyStrategy |
| 40 | { |
| 41 | public: |
| 42 | static Name |
| 43 | getStrategyName(uint64_t version) |
| 44 | { |
| 45 | return Name("/PitExpiryTestStrategy").appendVersion(version); |
| 46 | } |
| 47 | |
| 48 | static void |
| 49 | registerAs(const Name& strategyName) |
| 50 | { |
| 51 | registerAsImpl<PitExpiryTestStrategy>(strategyName); |
| 52 | } |
| 53 | |
| 54 | explicit |
| 55 | PitExpiryTestStrategy(Forwarder& forwarder, const Name& name = getStrategyName(1)) |
| 56 | : DummyStrategy(forwarder, name) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 61 | afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress, |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 62 | const shared_ptr<pit::Entry>& pitEntry) override |
| 63 | { |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 64 | DummyStrategy::afterReceiveInterest(interest, ingress, pitEntry); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 65 | |
| 66 | if (afterReceiveInterest_count <= 1) { |
| 67 | setExpiryTimer(pitEntry, 190_ms); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 72 | afterContentStoreHit(const Data& data, const FaceEndpoint& ingress, |
| 73 | const shared_ptr<pit::Entry>& pitEntry) override |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 74 | { |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 75 | if (afterContentStoreHit_count == 0) { |
| 76 | setExpiryTimer(pitEntry, 190_ms); |
| 77 | } |
| 78 | |
| 79 | DummyStrategy::afterContentStoreHit(data, ingress, pitEntry); |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | beforeSatisfyInterest(const Data& data, const FaceEndpoint& ingress, |
| 84 | const shared_ptr<pit::Entry>& pitEntry) override |
| 85 | { |
| 86 | DummyStrategy::beforeSatisfyInterest(data, ingress, pitEntry); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 87 | |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 88 | if (beforeSatisfyInterest_count <= 2) { |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 89 | setExpiryTimer(pitEntry, 190_ms); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 94 | afterReceiveData(const Data& data, const FaceEndpoint& ingress, |
| 95 | const shared_ptr<pit::Entry>& pitEntry) override |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 96 | { |
| 97 | ++afterReceiveData_count; |
| 98 | |
| 99 | if (afterReceiveData_count <= 2) { |
| 100 | setExpiryTimer(pitEntry, 290_ms); |
| 101 | } |
| 102 | |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 103 | this->sendDataToAll(data, pitEntry, ingress.face); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 107 | afterReceiveNack(const lp::Nack& nack, const FaceEndpoint& ingress, |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 108 | const shared_ptr<pit::Entry>& pitEntry) override |
| 109 | { |
Davide Pesavento | 0498ce8 | 2021-06-14 02:02:21 -0400 | [diff] [blame] | 110 | DummyStrategy::afterReceiveNack(nack, ingress, pitEntry); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 111 | |
| 112 | if (afterReceiveNack_count <= 1) { |
| 113 | setExpiryTimer(pitEntry, 50_ms); |
| 114 | } |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | BOOST_AUTO_TEST_CASE(UnsatisfiedInterest) |
| 119 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 120 | FaceTable faceTable; |
| 121 | Forwarder forwarder(faceTable); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 122 | |
| 123 | auto face1 = make_shared<DummyFace>(); |
| 124 | auto face2 = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 125 | faceTable.add(face1); |
| 126 | faceTable.add(face2); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 127 | |
| 128 | Pit& pit = forwarder.getPit(); |
| 129 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 130 | auto interest1 = makeInterest("/A/0"); |
| 131 | auto interest2 = makeInterest("/A/1"); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 132 | interest1->setInterestLifetime(90_ms); |
| 133 | interest2->setInterestLifetime(90_ms); |
| 134 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 135 | face1->receiveInterest(*interest1, 0); |
| 136 | face2->receiveInterest(*interest2, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(pit.size(), 2); |
| 138 | |
| 139 | this->advanceClocks(100_ms); |
| 140 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 141 | } |
| 142 | |
| 143 | BOOST_AUTO_TEST_CASE(SatisfiedInterest) |
| 144 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 145 | FaceTable faceTable; |
| 146 | Forwarder forwarder(faceTable); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 147 | |
| 148 | auto face1 = make_shared<DummyFace>(); |
| 149 | auto face2 = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 150 | faceTable.add(face1); |
| 151 | faceTable.add(face2); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 152 | |
| 153 | Pit& pit = forwarder.getPit(); |
| 154 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 155 | auto interest = makeInterest("/A/0"); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 156 | interest->setInterestLifetime(90_ms); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 157 | auto data = makeData("/A/0"); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 158 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 159 | face1->receiveInterest(*interest, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 160 | |
| 161 | this->advanceClocks(30_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 162 | face2->receiveData(*data, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 163 | |
| 164 | this->advanceClocks(1_ms); |
| 165 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 166 | } |
| 167 | |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 168 | BOOST_AUTO_TEST_CASE(CsHit) |
| 169 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 170 | FaceTable faceTable; |
| 171 | Forwarder forwarder(faceTable); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 172 | |
| 173 | auto face1 = make_shared<DummyFace>(); |
| 174 | auto face2 = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 175 | faceTable.add(face1); |
| 176 | faceTable.add(face2); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 177 | |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 178 | auto strategyA = Name("/strategyA").appendVersion(1); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 179 | PitExpiryTestStrategy::registerAs(strategyA); |
| 180 | choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA); |
| 181 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 182 | auto interest = makeInterest("/A/0"); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 183 | interest->setInterestLifetime(90_ms); |
| 184 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 185 | auto data = makeData("/A/0"); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 186 | data->setTag(make_shared<lp::IncomingFaceIdTag>(face2->getId())); |
| 187 | |
| 188 | Pit& pit = forwarder.getPit(); |
| 189 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 190 | |
| 191 | Cs& cs = forwarder.getCs(); |
| 192 | cs.insert(*data); |
| 193 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 194 | face1->receiveInterest(*interest, 0); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 195 | this->advanceClocks(1_ms); |
| 196 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 197 | |
| 198 | this->advanceClocks(190_ms); |
| 199 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 200 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 201 | face1->receiveInterest(*interest, 0); |
Teng Liang | 85a3663 | 2018-03-21 05:59:34 -0700 | [diff] [blame] | 202 | this->advanceClocks(1_ms); |
| 203 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 204 | } |
| 205 | |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 206 | BOOST_AUTO_TEST_CASE(ReceiveNack) |
| 207 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 208 | FaceTable faceTable; |
| 209 | Forwarder forwarder(faceTable); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 210 | |
| 211 | auto face1 = make_shared<DummyFace>(); |
| 212 | auto face2 = make_shared<DummyFace>(); |
| 213 | auto face3 = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 214 | faceTable.add(face1); |
| 215 | faceTable.add(face2); |
| 216 | faceTable.add(face3); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 217 | |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 218 | auto strategyA = Name("/strategyA").appendVersion(1); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 219 | PitExpiryTestStrategy::registerAs(strategyA); |
| 220 | choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA); |
| 221 | |
| 222 | Pit& pit = forwarder.getPit(); |
| 223 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 224 | auto interest = makeInterest("/A/0", false, 90_ms, 562); |
| 225 | lp::Nack nack = makeNack(*interest, lp::NackReason::CONGESTION); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 226 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 227 | face1->receiveInterest(*interest, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 228 | auto entry = pit.find(*interest); |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 229 | entry->insertOrUpdateOutRecord(*face2, *interest); |
| 230 | entry->insertOrUpdateOutRecord(*face3, *interest); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 231 | |
| 232 | this->advanceClocks(10_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 233 | face2->receiveNack(nack, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 234 | |
| 235 | this->advanceClocks(1_ms); |
| 236 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 237 | |
| 238 | this->advanceClocks(50_ms); |
| 239 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 240 | } |
| 241 | |
| 242 | BOOST_AUTO_TEST_CASE(ResetTimerAfterReceiveInterest) |
| 243 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 244 | FaceTable faceTable; |
| 245 | Forwarder forwarder(faceTable); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 246 | |
| 247 | auto face = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 248 | faceTable.add(face); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 249 | |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 250 | auto strategyA = Name("/strategyA").appendVersion(1); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 251 | PitExpiryTestStrategy::registerAs(strategyA); |
| 252 | choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA); |
| 253 | |
| 254 | Pit& pit = forwarder.getPit(); |
| 255 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 256 | auto interest = makeInterest("/A/0", false, 90_ms); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 257 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 258 | face->receiveInterest(*interest, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 259 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 260 | |
| 261 | this->advanceClocks(100_ms); |
| 262 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 263 | |
| 264 | this->advanceClocks(100_ms); |
| 265 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 266 | } |
| 267 | |
| 268 | BOOST_AUTO_TEST_CASE(ResetTimerBeforeSatisfyInterest) |
| 269 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 270 | FaceTable faceTable; |
| 271 | Forwarder forwarder(faceTable); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 272 | |
| 273 | auto face1 = make_shared<DummyFace>(); |
| 274 | auto face2 = make_shared<DummyFace>(); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 275 | auto face3 = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 276 | faceTable.add(face1); |
| 277 | faceTable.add(face2); |
| 278 | faceTable.add(face3); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 279 | |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 280 | auto strategyA = Name("/strategyA").appendVersion(1); |
| 281 | auto strategyB = Name("/strategyB").appendVersion(1); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 282 | PitExpiryTestStrategy::registerAs(strategyA); |
| 283 | PitExpiryTestStrategy::registerAs(strategyB); |
| 284 | auto& sA = choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA); |
| 285 | auto& sB = choose<PitExpiryTestStrategy>(forwarder, "/A/0", strategyB); |
| 286 | Pit& pit = forwarder.getPit(); |
| 287 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 288 | auto interest1 = makeInterest("/A", true, 90_ms); |
| 289 | auto interest2 = makeInterest("/A/0", false, 90_ms); |
| 290 | auto data = makeData("/A/0"); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 291 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 292 | face1->receiveInterest(*interest1, 0); |
| 293 | face2->receiveInterest(*interest2, 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 294 | BOOST_CHECK_EQUAL(pit.size(), 2); |
| 295 | |
| 296 | // beforeSatisfyInterest: the first Data prolongs PIT expiry timer by 190 ms |
| 297 | this->advanceClocks(30_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 298 | face3->receiveData(*data, 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 299 | this->advanceClocks(189_ms); |
| 300 | BOOST_CHECK_EQUAL(pit.size(), 2); |
| 301 | this->advanceClocks(2_ms); |
| 302 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 303 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 304 | face1->receiveInterest(*interest1, 0); |
| 305 | face2->receiveInterest(*interest2, 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 306 | |
| 307 | // beforeSatisfyInterest: the second Data prolongs PIT expiry timer |
| 308 | // and the third one sets the timer to now |
| 309 | this->advanceClocks(30_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 310 | face3->receiveData(*data, 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 311 | this->advanceClocks(1_ms); |
| 312 | BOOST_CHECK_EQUAL(pit.size(), 2); |
| 313 | |
| 314 | this->advanceClocks(30_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 315 | face3->receiveData(*data, 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 316 | this->advanceClocks(1_ms); |
| 317 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 318 | |
| 319 | BOOST_CHECK_EQUAL(sA.beforeSatisfyInterest_count, 3); |
| 320 | BOOST_CHECK_EQUAL(sB.beforeSatisfyInterest_count, 3); |
| 321 | BOOST_CHECK_EQUAL(sA.afterReceiveData_count, 0); |
| 322 | BOOST_CHECK_EQUAL(sB.afterReceiveData_count, 0); |
| 323 | } |
| 324 | |
| 325 | BOOST_AUTO_TEST_CASE(ResetTimerAfterReceiveData) |
| 326 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 327 | FaceTable faceTable; |
| 328 | Forwarder forwarder(faceTable); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 329 | |
| 330 | auto face1 = make_shared<DummyFace>(); |
| 331 | auto face2 = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 332 | faceTable.add(face1); |
| 333 | faceTable.add(face2); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 334 | |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 335 | auto strategyA = Name("/strategyA").appendVersion(1); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 336 | PitExpiryTestStrategy::registerAs(strategyA); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 337 | auto& sA = choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 338 | |
| 339 | Pit& pit = forwarder.getPit(); |
| 340 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 341 | auto interest = makeInterest("/A/0", false, 90_ms); |
| 342 | auto data = makeData("/A/0"); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 343 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 344 | face1->receiveInterest(*interest, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 345 | |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 346 | // afterReceiveData: the first Data prolongs PIT expiry timer by 290 ms |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 347 | this->advanceClocks(30_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 348 | face2->receiveData(*data, 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 349 | this->advanceClocks(289_ms); |
| 350 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 351 | this->advanceClocks(2_ms); |
| 352 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 353 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 354 | face1->receiveInterest(*interest, 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 355 | |
| 356 | // afterReceiveData: the second Data prolongs PIT expiry timer |
| 357 | // and the third one sets the timer to now |
| 358 | this->advanceClocks(30_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 359 | face2->receiveData(*data, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 360 | this->advanceClocks(1_ms); |
| 361 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 362 | |
| 363 | this->advanceClocks(30_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 364 | face2->receiveData(*data, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 365 | this->advanceClocks(1_ms); |
| 366 | BOOST_CHECK_EQUAL(pit.size(), 0); |
Teng Liang | 43bb231 | 2018-03-26 04:16:42 -0700 | [diff] [blame] | 367 | |
| 368 | BOOST_CHECK_EQUAL(sA.beforeSatisfyInterest_count, 0); |
| 369 | BOOST_CHECK_EQUAL(sA.afterReceiveData_count, 3); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | BOOST_AUTO_TEST_CASE(ReceiveNackAfterResetTimer) |
| 373 | { |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 374 | FaceTable faceTable; |
| 375 | Forwarder forwarder(faceTable); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 376 | |
| 377 | auto face1 = make_shared<DummyFace>(); |
| 378 | auto face2 = make_shared<DummyFace>(); |
| 379 | auto face3 = make_shared<DummyFace>(); |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 380 | faceTable.add(face1); |
| 381 | faceTable.add(face2); |
| 382 | faceTable.add(face3); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 383 | |
Eric Newberry | 358414d | 2021-03-21 20:56:42 -0700 | [diff] [blame] | 384 | auto strategyA = Name("/strategyA").appendVersion(1); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 385 | PitExpiryTestStrategy::registerAs(strategyA); |
| 386 | choose<PitExpiryTestStrategy>(forwarder, "/A", strategyA); |
| 387 | |
| 388 | Pit& pit = forwarder.getPit(); |
| 389 | |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 390 | auto interest = makeInterest("/A/0", false, 90_ms, 562); |
| 391 | lp::Nack nack = makeNack(*interest, lp::NackReason::CONGESTION); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 392 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 393 | face1->receiveInterest(*interest, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 394 | auto entry = pit.find(*interest); |
Md Ashiqur Rahman | c88d2d4 | 2019-08-28 20:19:47 +0000 | [diff] [blame] | 395 | entry->insertOrUpdateOutRecord(*face2, *interest); |
| 396 | entry->insertOrUpdateOutRecord(*face3, *interest); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 397 | |
| 398 | //pitEntry is not erased after receiving the first Nack |
| 399 | this->advanceClocks(10_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 400 | face2->receiveNack(nack, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 401 | this->advanceClocks(1_ms); |
| 402 | BOOST_CHECK_EQUAL(pit.size(), 1); |
| 403 | |
| 404 | //pitEntry is erased after receiving the second Nack |
| 405 | this->advanceClocks(10_ms); |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 406 | face3->receiveNack(nack, 0); |
Teng Liang | 7003e0b | 2018-03-03 16:03:30 -0700 | [diff] [blame] | 407 | this->advanceClocks(1_ms); |
| 408 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 409 | } |
| 410 | |
| 411 | BOOST_AUTO_TEST_SUITE_END() // TestPitExpiry |
| 412 | BOOST_AUTO_TEST_SUITE_END() // Fw |
| 413 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 414 | } // namespace nfd::tests |