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