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