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