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 | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 29 | #include "install-strategy.hpp" |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 31 | #include "tests/test-common.hpp" |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | namespace tests { |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 36 | BOOST_AUTO_TEST_SUITE(Fw) |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 37 | BOOST_FIXTURE_TEST_SUITE(TestForwarder, UnitTestTimeFixture) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 38 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 39 | BOOST_AUTO_TEST_CASE(SimpleExchange) |
| 40 | { |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 41 | Forwarder forwarder; |
| 42 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 43 | shared_ptr<Interest> interestAB = makeInterest("/A/B"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 44 | interestAB->setInterestLifetime(time::seconds(4)); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 45 | shared_ptr<Data> dataABC = makeData("/A/B/C"); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 46 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 47 | auto face1 = make_shared<DummyFace>(); |
| 48 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 49 | forwarder.addFace(face1); |
| 50 | forwarder.addFace(face2); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 51 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 52 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 53 | fib.insert("/A").first->addNextHop(*face2, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 54 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 55 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 0); |
| 56 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 0); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 57 | face1->receiveInterest(*interestAB); |
| 58 | this->advanceClocks(time::milliseconds(100), time::seconds(1)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 59 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(face2->sentInterests[0].getName(), "/A/B"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 61 | BOOST_REQUIRE(face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 62 | BOOST_CHECK_EQUAL(*face2->sentInterests[0].getTag<lp::IncomingFaceIdTag>(), face1->getId()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 63 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInInterests, 1); |
| 64 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutInterests, 1); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 65 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 66 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 0); |
| 67 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 0); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 68 | face2->receiveData(*dataABC); |
| 69 | this->advanceClocks(time::milliseconds(100), time::seconds(1)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 70 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 71 | BOOST_CHECK_EQUAL(face1->sentData[0].getName(), "/A/B/C"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 72 | BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 73 | BOOST_CHECK_EQUAL(*face1->sentData[0].getTag<lp::IncomingFaceIdTag>(), face2->getId()); |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(forwarder.getCounters().nInData, 1); |
| 75 | BOOST_CHECK_EQUAL(forwarder.getCounters().nOutData, 1); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 78 | BOOST_AUTO_TEST_CASE(CsMatched) |
| 79 | { |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 80 | Forwarder forwarder; |
| 81 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 82 | auto face1 = make_shared<DummyFace>(); |
| 83 | auto face2 = make_shared<DummyFace>(); |
| 84 | auto face3 = make_shared<DummyFace>(); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 85 | forwarder.addFace(face1); |
| 86 | forwarder.addFace(face2); |
| 87 | forwarder.addFace(face3); |
| 88 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 89 | shared_ptr<Interest> interestA = makeInterest("/A"); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 90 | interestA->setInterestLifetime(time::seconds(4)); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 91 | shared_ptr<Data> dataA = makeData("/A"); |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 92 | dataA->setTag(make_shared<lp::IncomingFaceIdTag>(face3->getId())); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 93 | |
| 94 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 95 | fib.insert("/A").first->addNextHop(*face2, 0); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 96 | |
| 97 | Pit& pit = forwarder.getPit(); |
| 98 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 99 | |
| 100 | Cs& cs = forwarder.getCs(); |
Minsheng Zhang | ffe8bbb | 2016-03-10 13:40:37 -0700 | [diff] [blame] | 101 | cs.insert(*dataA); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 102 | |
| 103 | face1->receiveInterest(*interestA); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 104 | this->advanceClocks(time::milliseconds(1), time::milliseconds(5)); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 105 | // Interest matching ContentStore should not be forwarded |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 106 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 0); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 107 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 108 | BOOST_REQUIRE_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 109 | // IncomingFaceId field should be reset to represent CS |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 110 | BOOST_REQUIRE(face1->sentData[0].getTag<lp::IncomingFaceIdTag>() != nullptr); |
| 111 | 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] | 112 | |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 113 | this->advanceClocks(time::milliseconds(100), time::milliseconds(500)); |
Junxiao Shi | ad3f1cb | 2014-08-18 11:12:30 -0700 | [diff] [blame] | 114 | // PIT entry should not be left behind |
| 115 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 116 | } |
| 117 | |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 118 | BOOST_AUTO_TEST_CASE(OutgoingInterest) |
| 119 | { |
| 120 | Forwarder forwarder; |
| 121 | auto face1 = make_shared<DummyFace>(); |
| 122 | auto face2 = make_shared<DummyFace>(); |
| 123 | auto face3 = make_shared<DummyFace>(); |
| 124 | forwarder.addFace(face1); |
| 125 | forwarder.addFace(face2); |
| 126 | forwarder.addFace(face3); |
| 127 | |
| 128 | Pit& pit = forwarder.getPit(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 129 | auto interestA1 = makeInterest("/A"); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 130 | interestA1->setNonce(8378); |
| 131 | shared_ptr<pit::Entry> pitA = pit.insert(*interestA1).first; |
| 132 | pit::InRecordCollection::iterator inA1 = pitA->insertOrUpdateInRecord(face1, *interestA1); |
| 133 | |
| 134 | // there is only one downstream, interestA1 is used |
| 135 | forwarder.onOutgoingInterest(pitA, *face3, false); |
| 136 | BOOST_REQUIRE_EQUAL(face3->sentInterests.size(), 1); |
| 137 | BOOST_CHECK_EQUAL(face3->sentInterests.back().getNonce(), 8378); |
| 138 | |
| 139 | // new Nonce is requested |
| 140 | forwarder.onOutgoingInterest(pitA, *face3, true); |
| 141 | BOOST_REQUIRE_EQUAL(face3->sentInterests.size(), 2); |
| 142 | BOOST_CHECK_NE(face3->sentInterests.back().getNonce(), 8378); |
| 143 | // Nonce on in-record Interest shouldn't be touched |
| 144 | BOOST_CHECK_EQUAL(inA1->getInterest().getNonce(), 8378); |
| 145 | |
| 146 | // outgoing face is face1, interestA1 is still used because there's no other choice |
| 147 | forwarder.onOutgoingInterest(pitA, *face1, false); |
| 148 | BOOST_REQUIRE_EQUAL(face1->sentInterests.size(), 1); |
| 149 | BOOST_CHECK_EQUAL(face1->sentInterests.back().getNonce(), 8378); |
| 150 | |
| 151 | this->advanceClocks(time::seconds(2)); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 152 | auto interestA2 = makeInterest("/A"); |
Junxiao Shi | 891f47b | 2016-06-20 00:02:11 +0000 | [diff] [blame] | 153 | interestA2->setNonce(9102); |
| 154 | pitA->insertOrUpdateInRecord(face2, *interestA2); |
| 155 | |
| 156 | // there are two downstreams, prefer newer interestA2 |
| 157 | forwarder.onOutgoingInterest(pitA, *face3, false); |
| 158 | BOOST_REQUIRE_EQUAL(face3->sentInterests.size(), 3); |
| 159 | BOOST_CHECK_EQUAL(face3->sentInterests.back().getNonce(), 9102); |
| 160 | |
| 161 | // outgoing face is face2, prefer interestA1 from face1 despite it's older |
| 162 | forwarder.onOutgoingInterest(pitA, *face2, false); |
| 163 | BOOST_REQUIRE_EQUAL(face2->sentInterests.size(), 1); |
| 164 | BOOST_CHECK_EQUAL(face2->sentInterests.back().getNonce(), 8378); |
| 165 | |
| 166 | // outgoing face is face1, prefer interestA2 |
| 167 | forwarder.onOutgoingInterest(pitA, *face1, false); |
| 168 | BOOST_REQUIRE_EQUAL(face1->sentInterests.size(), 2); |
| 169 | BOOST_CHECK_EQUAL(face1->sentInterests.back().getNonce(), 9102); |
| 170 | } |
| 171 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 172 | class ScopeLocalhostIncomingTestForwarder : public Forwarder |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 173 | { |
| 174 | public: |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 175 | ScopeLocalhostIncomingTestForwarder() |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 176 | { |
| 177 | } |
| 178 | |
| 179 | virtual void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 180 | onDataUnsolicited(Face& inFace, const Data& data) override |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 181 | { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 182 | ++onDataUnsolicited_count; |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | protected: |
| 186 | virtual void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 187 | dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> f) override |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 188 | { |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 189 | ++dispatchToStrategy_count; |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | public: |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 193 | int dispatchToStrategy_count; |
| 194 | int onDataUnsolicited_count; |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 197 | BOOST_AUTO_TEST_CASE(ScopeLocalhostIncoming) |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 198 | { |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 199 | ScopeLocalhostIncomingTestForwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 200 | auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 201 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 202 | forwarder.addFace(face1); |
| 203 | forwarder.addFace(face2); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 204 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 205 | // local face, /localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 206 | forwarder.dispatchToStrategy_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 207 | shared_ptr<Interest> i1 = makeInterest("/localhost/A1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 208 | forwarder.onIncomingInterest(*face1, *i1); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 209 | BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1); |
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 | // non-local face, /localhost: violate |
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> i2 = makeInterest("/localhost/A2"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 214 | forwarder.onIncomingInterest(*face2, *i2); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 215 | BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 0); |
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 | // local face, non-/localhost: OK |
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> i3 = makeInterest("/A3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 220 | forwarder.onIncomingInterest(*face1, *i3); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 221 | BOOST_CHECK_EQUAL(forwarder.dispatchToStrategy_count, 1); |
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 | // non-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> i4 = makeInterest("/A4"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 226 | forwarder.onIncomingInterest(*face2, *i4); |
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 | // local face, /localhost: OK |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 230 | forwarder.onDataUnsolicited_count = 0; |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 231 | shared_ptr<Data> d1 = makeData("/localhost/B1"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 232 | forwarder.onIncomingData(*face1, *d1); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 233 | BOOST_CHECK_EQUAL(forwarder.onDataUnsolicited_count, 1); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 234 | |
| 235 | // non-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> d2 = makeData("/localhost/B2"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 238 | forwarder.onIncomingData(*face2, *d2); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 239 | BOOST_CHECK_EQUAL(forwarder.onDataUnsolicited_count, 0); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 240 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 241 | // local face, non-/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> d3 = makeData("/B3"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 244 | forwarder.onIncomingData(*face1, *d3); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 245 | BOOST_CHECK_EQUAL(forwarder.onDataUnsolicited_count, 1); |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 246 | |
| 247 | // non-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> d4 = makeData("/B4"); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 250 | forwarder.onIncomingData(*face2, *d4); |
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 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 254 | BOOST_AUTO_TEST_CASE(ScopeLocalhostOutgoing) |
| 255 | { |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 256 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 257 | auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 258 | auto face2 = make_shared<DummyFace>(); |
| 259 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 260 | forwarder.addFace(face1); |
| 261 | forwarder.addFace(face2); |
| 262 | forwarder.addFace(face3); |
| 263 | Pit& pit = forwarder.getPit(); |
| 264 | |
| 265 | // local face, /localhost: OK |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 266 | shared_ptr<Interest> interestA1 = makeInterest("/localhost/A1"); |
| 267 | shared_ptr<pit::Entry> pitA1 = pit.insert(*interestA1).first; |
| 268 | pitA1->insertOrUpdateInRecord(face3, *interestA1); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 269 | face1->sentInterests.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 270 | forwarder.onOutgoingInterest(pitA1, *face1); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 271 | BOOST_CHECK_EQUAL(face1->sentInterests.size(), 1); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 272 | |
| 273 | // non-local face, /localhost: violate |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 274 | shared_ptr<Interest> interestA2 = makeInterest("/localhost/A2"); |
| 275 | shared_ptr<pit::Entry> pitA2 = pit.insert(*interestA2).first; |
| 276 | pitA2->insertOrUpdateInRecord(face3, *interestA2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 277 | face2->sentInterests.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 278 | forwarder.onOutgoingInterest(pitA2, *face2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 279 | BOOST_CHECK_EQUAL(face2->sentInterests.size(), 0); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 280 | |
| 281 | // local face, non-/localhost: OK |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 282 | shared_ptr<Interest> interestA3 = makeInterest("/A3"); |
| 283 | shared_ptr<pit::Entry> pitA3 = pit.insert(*interestA3).first; |
| 284 | pitA3->insertOrUpdateInRecord(face3, *interestA3); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 285 | face1->sentInterests.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 286 | forwarder.onOutgoingInterest(pitA3, *face1); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 287 | BOOST_CHECK_EQUAL(face1->sentInterests.size(), 1); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 288 | |
| 289 | // non-local face, non-/localhost: OK |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 290 | shared_ptr<Interest> interestA4 = makeInterest("/A4"); |
| 291 | shared_ptr<pit::Entry> pitA4 = pit.insert(*interestA4).first; |
| 292 | pitA4->insertOrUpdateInRecord(face3, *interestA4); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 293 | face2->sentInterests.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 294 | forwarder.onOutgoingInterest(pitA4, *face2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 295 | BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 296 | |
| 297 | // local face, /localhost: OK |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 298 | face1->sentData.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 299 | forwarder.onOutgoingData(Data("/localhost/B1"), *face1); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 300 | BOOST_CHECK_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 301 | |
| 302 | // non-local face, /localhost: OK |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 303 | face2->sentData.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 304 | forwarder.onOutgoingData(Data("/localhost/B2"), *face2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(face2->sentData.size(), 0); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 306 | |
| 307 | // local face, non-/localhost: OK |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 308 | face1->sentData.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 309 | forwarder.onOutgoingData(Data("/B3"), *face1); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 310 | BOOST_CHECK_EQUAL(face1->sentData.size(), 1); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 311 | |
| 312 | // non-local face, non-/localhost: OK |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 313 | face2->sentData.clear(); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 314 | forwarder.onOutgoingData(Data("/B4"), *face2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 315 | BOOST_CHECK_EQUAL(face2->sentData.size(), 1); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 318 | BOOST_AUTO_TEST_CASE(ScopeLocalhopOutgoing) |
| 319 | { |
| 320 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 321 | auto face1 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 322 | auto face2 = make_shared<DummyFace>(); |
| 323 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", ndn::nfd::FACE_SCOPE_LOCAL); |
| 324 | auto face4 = make_shared<DummyFace>(); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 325 | forwarder.addFace(face1); |
| 326 | forwarder.addFace(face2); |
| 327 | forwarder.addFace(face3); |
| 328 | forwarder.addFace(face4); |
| 329 | Pit& pit = forwarder.getPit(); |
| 330 | |
| 331 | // from local face, to local face: OK |
| 332 | shared_ptr<Interest> interest1 = makeInterest("/localhop/1"); |
| 333 | shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first; |
| 334 | pit1->insertOrUpdateInRecord(face1, *interest1); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 335 | face3->sentInterests.clear(); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 336 | forwarder.onOutgoingInterest(pit1, *face3); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 337 | BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 338 | |
| 339 | // from non-local face, to local face: OK |
| 340 | shared_ptr<Interest> interest2 = makeInterest("/localhop/2"); |
| 341 | shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first; |
| 342 | pit2->insertOrUpdateInRecord(face2, *interest2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 343 | face3->sentInterests.clear(); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 344 | forwarder.onOutgoingInterest(pit2, *face3); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 345 | BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 346 | |
| 347 | // from local face, to non-local face: OK |
| 348 | shared_ptr<Interest> interest3 = makeInterest("/localhop/3"); |
| 349 | shared_ptr<pit::Entry> pit3 = pit.insert(*interest3).first; |
| 350 | pit3->insertOrUpdateInRecord(face1, *interest3); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 351 | face4->sentInterests.clear(); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 352 | forwarder.onOutgoingInterest(pit3, *face4); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 353 | BOOST_CHECK_EQUAL(face4->sentInterests.size(), 1); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 354 | |
| 355 | // from non-local face, to non-local face: violate |
| 356 | shared_ptr<Interest> interest4 = makeInterest("/localhop/4"); |
| 357 | shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first; |
| 358 | pit4->insertOrUpdateInRecord(face2, *interest4); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 359 | face4->sentInterests.clear(); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 360 | forwarder.onOutgoingInterest(pit4, *face4); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 361 | BOOST_CHECK_EQUAL(face4->sentInterests.size(), 0); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 362 | |
| 363 | // from local face and non-local face, to local face: OK |
| 364 | shared_ptr<Interest> interest5 = makeInterest("/localhop/5"); |
| 365 | shared_ptr<pit::Entry> pit5 = pit.insert(*interest5).first; |
| 366 | pit5->insertOrUpdateInRecord(face1, *interest5); |
| 367 | pit5->insertOrUpdateInRecord(face2, *interest5); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 368 | face3->sentInterests.clear(); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 369 | forwarder.onOutgoingInterest(pit5, *face3); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 370 | BOOST_CHECK_EQUAL(face3->sentInterests.size(), 1); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 371 | |
| 372 | // from local face and non-local face, to non-local face: OK |
| 373 | shared_ptr<Interest> interest6 = makeInterest("/localhop/6"); |
| 374 | shared_ptr<pit::Entry> pit6 = pit.insert(*interest6).first; |
| 375 | pit6->insertOrUpdateInRecord(face1, *interest6); |
| 376 | pit6->insertOrUpdateInRecord(face2, *interest6); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 377 | face4->sentInterests.clear(); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 378 | forwarder.onOutgoingInterest(pit6, *face4); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 379 | BOOST_CHECK_EQUAL(face4->sentInterests.size(), 1); |
Junxiao Shi | 11bd9c2 | 2014-03-13 20:44:13 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 382 | BOOST_AUTO_TEST_CASE(IncomingInterestStrategyDispatch) |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 383 | { |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 384 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 385 | auto face1 = make_shared<DummyFace>(); |
| 386 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 387 | forwarder.addFace(face1); |
| 388 | forwarder.addFace(face2); |
| 389 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 390 | DummyStrategy& strategyP = choose<DummyStrategy>(forwarder, "ndn:/", "ndn:/strategyP"); |
| 391 | DummyStrategy& strategyQ = choose<DummyStrategy>(forwarder, "ndn:/B", "ndn:/strategyQ"); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 392 | |
| 393 | shared_ptr<Interest> interest1 = makeInterest("ndn:/A/1"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 394 | strategyP.afterReceiveInterest_count = 0; |
| 395 | strategyP.interestOutFace = face2; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 396 | forwarder.startProcessInterest(*face1, *interest1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 397 | BOOST_CHECK_EQUAL(strategyP.afterReceiveInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 398 | |
| 399 | shared_ptr<Interest> interest2 = makeInterest("ndn:/B/2"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 400 | strategyQ.afterReceiveInterest_count = 0; |
| 401 | strategyQ.interestOutFace = face2; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 402 | forwarder.startProcessInterest(*face1, *interest2); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 403 | BOOST_CHECK_EQUAL(strategyQ.afterReceiveInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 404 | |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 405 | this->advanceClocks(time::milliseconds(1), time::milliseconds(5)); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 406 | |
| 407 | shared_ptr<Data> data1 = makeData("ndn:/A/1/a"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 408 | strategyP.beforeSatisfyInterest_count = 0; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 409 | forwarder.startProcessData(*face2, *data1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 410 | BOOST_CHECK_EQUAL(strategyP.beforeSatisfyInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 411 | |
| 412 | shared_ptr<Data> data2 = makeData("ndn:/B/2/b"); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 413 | strategyQ.beforeSatisfyInterest_count = 0; |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 414 | forwarder.startProcessData(*face2, *data2); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 415 | BOOST_CHECK_EQUAL(strategyQ.beforeSatisfyInterest_count, 1); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 416 | |
| 417 | shared_ptr<Interest> interest3 = makeInterest("ndn:/A/3"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 418 | interest3->setInterestLifetime(time::milliseconds(30)); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 419 | forwarder.startProcessInterest(*face1, *interest3); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 420 | shared_ptr<Interest> interest4 = makeInterest("ndn:/B/4"); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 421 | interest4->setInterestLifetime(time::milliseconds(5000)); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 422 | forwarder.startProcessInterest(*face1, *interest4); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 423 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 424 | strategyP.beforeExpirePendingInterest_count = 0; |
| 425 | strategyQ.beforeExpirePendingInterest_count = 0; |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 426 | this->advanceClocks(time::milliseconds(10), time::milliseconds(100)); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 427 | BOOST_CHECK_EQUAL(strategyP.beforeExpirePendingInterest_count, 1); |
| 428 | BOOST_CHECK_EQUAL(strategyQ.beforeExpirePendingInterest_count, 0); |
Junxiao Shi | f3c0781 | 2014-03-11 21:48:49 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 431 | BOOST_AUTO_TEST_CASE(IncomingData) |
| 432 | { |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 433 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 434 | auto face1 = make_shared<DummyFace>(); |
| 435 | auto face2 = make_shared<DummyFace>(); |
| 436 | auto face3 = make_shared<DummyFace>(); |
| 437 | auto face4 = make_shared<DummyFace>(); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 438 | forwarder.addFace(face1); |
| 439 | forwarder.addFace(face2); |
Junxiao Shi | 223271b | 2014-07-03 22:06:13 -0700 | [diff] [blame] | 440 | forwarder.addFace(face3); |
| 441 | forwarder.addFace(face4); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 442 | |
| 443 | Pit& pit = forwarder.getPit(); |
| 444 | shared_ptr<Interest> interest0 = makeInterest("ndn:/"); |
| 445 | shared_ptr<pit::Entry> pit0 = pit.insert(*interest0).first; |
| 446 | pit0->insertOrUpdateInRecord(face1, *interest0); |
| 447 | shared_ptr<Interest> interestA = makeInterest("ndn:/A"); |
| 448 | shared_ptr<pit::Entry> pitA = pit.insert(*interestA).first; |
| 449 | pitA->insertOrUpdateInRecord(face1, *interestA); |
| 450 | pitA->insertOrUpdateInRecord(face2, *interestA); |
| 451 | shared_ptr<Interest> interestC = makeInterest("ndn:/A/B/C"); |
| 452 | shared_ptr<pit::Entry> pitC = pit.insert(*interestC).first; |
| 453 | pitC->insertOrUpdateInRecord(face3, *interestC); |
| 454 | pitC->insertOrUpdateInRecord(face4, *interestC); |
| 455 | |
| 456 | shared_ptr<Data> dataD = makeData("ndn:/A/B/C/D"); |
| 457 | forwarder.onIncomingData(*face3, *dataD); |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 458 | this->advanceClocks(time::milliseconds(1), time::milliseconds(5)); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 459 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 460 | BOOST_CHECK_EQUAL(face1->sentData.size(), 1); |
| 461 | BOOST_CHECK_EQUAL(face2->sentData.size(), 1); |
| 462 | BOOST_CHECK_EQUAL(face3->sentData.size(), 0); |
| 463 | BOOST_CHECK_EQUAL(face4->sentData.size(), 1); |
Junxiao Shi | da006f5 | 2014-05-16 11:18:00 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 466 | BOOST_AUTO_TEST_CASE(IncomingNack) |
| 467 | { |
| 468 | Forwarder forwarder; |
| 469 | auto face1 = make_shared<DummyFace>(); |
| 470 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 471 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", |
| 472 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 473 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 474 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 475 | forwarder.addFace(face1); |
| 476 | forwarder.addFace(face2); |
| 477 | forwarder.addFace(face3); |
| 478 | |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 479 | DummyStrategy& strategyP = choose<DummyStrategy>(forwarder, "ndn:/", "ndn:/strategyP"); |
| 480 | DummyStrategy& strategyQ = choose<DummyStrategy>(forwarder, "ndn:/B", "ndn:/strategyQ"); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 481 | |
| 482 | Pit& pit = forwarder.getPit(); |
| 483 | |
| 484 | // dispatch to the correct strategy |
| 485 | shared_ptr<Interest> interest1 = makeInterest("/A/AYJqayrzF", 562); |
| 486 | shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first; |
| 487 | pit1->insertOrUpdateOutRecord(face1, *interest1); |
| 488 | shared_ptr<Interest> interest2 = makeInterest("/B/EVyP73ru", 221); |
| 489 | shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first; |
| 490 | pit2->insertOrUpdateOutRecord(face1, *interest2); |
| 491 | |
| 492 | lp::Nack nack1 = makeNack("/A/AYJqayrzF", 562, lp::NackReason::CONGESTION); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 493 | strategyP.afterReceiveNack_count = 0; |
| 494 | strategyQ.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 495 | forwarder.onIncomingNack(*face1, nack1); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 496 | BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 1); |
| 497 | BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 498 | |
| 499 | lp::Nack nack2 = makeNack("/B/EVyP73ru", 221, lp::NackReason::CONGESTION); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 500 | strategyP.afterReceiveNack_count = 0; |
| 501 | strategyQ.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 502 | forwarder.onIncomingNack(*face1, nack2); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 503 | BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0); |
| 504 | BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 505 | |
| 506 | // record Nack on PIT out-record |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 507 | pit::OutRecordCollection::iterator outRecord1 = pit1->getOutRecord(*face1); |
| 508 | BOOST_REQUIRE(outRecord1 != pit1->out_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 509 | BOOST_REQUIRE(outRecord1->getIncomingNack() != nullptr); |
| 510 | BOOST_CHECK_EQUAL(outRecord1->getIncomingNack()->getReason(), lp::NackReason::CONGESTION); |
| 511 | |
| 512 | // drop if no PIT entry |
| 513 | lp::Nack nack3 = makeNack("/yEcw5HhdM", 243, lp::NackReason::CONGESTION); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 514 | strategyP.afterReceiveNack_count = 0; |
| 515 | strategyQ.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 516 | forwarder.onIncomingNack(*face1, nack3); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 517 | BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0); |
| 518 | BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 519 | |
| 520 | // drop if no out-record |
| 521 | shared_ptr<Interest> interest4 = makeInterest("/Etab4KpY", 157); |
| 522 | shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first; |
| 523 | pit4->insertOrUpdateOutRecord(face1, *interest4); |
| 524 | |
| 525 | lp::Nack nack4a = makeNack("/Etab4KpY", 157, lp::NackReason::CONGESTION); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 526 | strategyP.afterReceiveNack_count = 0; |
| 527 | strategyQ.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 528 | forwarder.onIncomingNack(*face2, nack4a); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 529 | BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0); |
| 530 | BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 531 | |
| 532 | // drop if Nonce does not match out-record |
| 533 | lp::Nack nack4b = makeNack("/Etab4KpY", 294, lp::NackReason::CONGESTION); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 534 | strategyP.afterReceiveNack_count = 0; |
| 535 | strategyQ.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 536 | forwarder.onIncomingNack(*face1, nack4b); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 537 | BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0); |
| 538 | BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 539 | |
| 540 | // drop if inFace is multi-access |
| 541 | pit4->insertOrUpdateOutRecord(face3, *interest4); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 542 | strategyP.afterReceiveNack_count = 0; |
| 543 | strategyQ.afterReceiveNack_count = 0; |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 544 | forwarder.onIncomingNack(*face3, nack4a); |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 545 | BOOST_CHECK_EQUAL(strategyP.afterReceiveNack_count, 0); |
| 546 | BOOST_CHECK_EQUAL(strategyQ.afterReceiveNack_count, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | BOOST_AUTO_TEST_CASE(OutgoingNack) |
| 550 | { |
| 551 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 552 | auto face1 = make_shared<DummyFace>(); |
| 553 | auto face2 = make_shared<DummyFace>(); |
| 554 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", |
| 555 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 556 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 557 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
| 558 | forwarder.addFace(face1); |
| 559 | forwarder.addFace(face2); |
| 560 | forwarder.addFace(face3); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 561 | |
| 562 | Pit& pit = forwarder.getPit(); |
| 563 | |
| 564 | lp::NackHeader nackHeader; |
| 565 | nackHeader.setReason(lp::NackReason::CONGESTION); |
| 566 | |
| 567 | // don't send Nack if there's no in-record |
| 568 | shared_ptr<Interest> interest1 = makeInterest("/fM5IVEtC", 719); |
| 569 | shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 570 | pit1->insertOrUpdateInRecord(face1, *interest1); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 571 | |
| 572 | face2->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 573 | forwarder.onOutgoingNack(pit1, *face2, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 574 | BOOST_CHECK_EQUAL(face2->sentNacks.size(), 0); |
| 575 | |
| 576 | // send Nack with correct Nonce |
| 577 | shared_ptr<Interest> interest2a = makeInterest("/Vi8tRm9MG3", 152); |
| 578 | shared_ptr<pit::Entry> pit2 = pit.insert(*interest2a).first; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 579 | pit2->insertOrUpdateInRecord(face1, *interest2a); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 580 | shared_ptr<Interest> interest2b = makeInterest("/Vi8tRm9MG3", 808); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 581 | pit2->insertOrUpdateInRecord(face2, *interest2b); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 582 | |
| 583 | face1->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 584 | forwarder.onOutgoingNack(pit2, *face1, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 585 | BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1); |
| 586 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::CONGESTION); |
| 587 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest().getNonce(), 152); |
| 588 | |
| 589 | // erase in-record |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 590 | pit::InRecordCollection::iterator inRecord2a = pit2->getInRecord(*face1); |
| 591 | BOOST_CHECK(inRecord2a == pit2->in_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 592 | |
| 593 | // send Nack with correct Nonce |
| 594 | face2->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 595 | forwarder.onOutgoingNack(pit2, *face2, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 596 | BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1); |
| 597 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::CONGESTION); |
| 598 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest().getNonce(), 808); |
| 599 | |
| 600 | // erase in-record |
Junxiao Shi | 4846f37 | 2016-04-05 13:39:30 -0700 | [diff] [blame] | 601 | pit::InRecordCollection::iterator inRecord2b = pit2->getInRecord(*face1); |
| 602 | BOOST_CHECK(inRecord2b == pit2->in_end()); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 603 | |
| 604 | // don't send Nack to multi-access face |
| 605 | shared_ptr<Interest> interest2c = makeInterest("/Vi8tRm9MG3", 228); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 606 | pit2->insertOrUpdateInRecord(face3, *interest2c); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 607 | |
| 608 | face3->sentNacks.clear(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 609 | forwarder.onOutgoingNack(pit1, *face3, nackHeader); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 610 | BOOST_CHECK_EQUAL(face3->sentNacks.size(), 0); |
| 611 | } |
| 612 | |
| 613 | BOOST_AUTO_TEST_CASE(InterestLoopNack) |
| 614 | { |
| 615 | Forwarder forwarder; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 616 | auto face1 = make_shared<DummyFace>(); |
| 617 | auto face2 = make_shared<DummyFace>(); |
| 618 | auto face3 = make_shared<DummyFace>("dummy://", "dummy://", |
| 619 | ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 620 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 621 | ndn::nfd::LINK_TYPE_MULTI_ACCESS); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 622 | auto face4 = make_shared<DummyFace>(); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 623 | forwarder.addFace(face1); |
| 624 | forwarder.addFace(face2); |
| 625 | forwarder.addFace(face3); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 626 | forwarder.addFace(face4); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 627 | |
| 628 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 629 | fib.insert("/zT4XwK0Hnx").first->addNextHop(*face4, 0); |
Junxiao Shi | 5e5e445 | 2015-09-24 16:56:52 -0700 | [diff] [blame] | 630 | |
| 631 | // receive Interest on face1 |
| 632 | face1->sentNacks.clear(); |
| 633 | shared_ptr<Interest> interest1a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 634 | face1->receiveInterest(*interest1a); |
| 635 | BOOST_CHECK(face1->sentNacks.empty()); |
| 636 | |
| 637 | // receive Interest with duplicate Nonce on face1 |
| 638 | face1->sentNacks.clear(); |
| 639 | shared_ptr<Interest> interest1b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 640 | face1->receiveInterest(*interest1b); |
| 641 | BOOST_REQUIRE_EQUAL(face1->sentNacks.size(), 1); |
| 642 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getInterest(), *interest1b); |
| 643 | BOOST_CHECK_EQUAL(face1->sentNacks.back().getReason(), lp::NackReason::DUPLICATE); |
| 644 | |
| 645 | // receive Interest with duplicate Nonce on face2 |
| 646 | face2->sentNacks.clear(); |
| 647 | shared_ptr<Interest> interest2a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 648 | face2->receiveInterest(*interest2a); |
| 649 | BOOST_REQUIRE_EQUAL(face2->sentNacks.size(), 1); |
| 650 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getInterest(), *interest2a); |
| 651 | BOOST_CHECK_EQUAL(face2->sentNacks.back().getReason(), lp::NackReason::DUPLICATE); |
| 652 | |
| 653 | // receive Interest with new Nonce on face2 |
| 654 | face2->sentNacks.clear(); |
| 655 | shared_ptr<Interest> interest2b = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 944); |
| 656 | face2->receiveInterest(*interest2b); |
| 657 | BOOST_CHECK(face2->sentNacks.empty()); |
| 658 | |
| 659 | // receive Interest with duplicate Nonce on face3, don't send Nack to multi-access face |
| 660 | face3->sentNacks.clear(); |
| 661 | shared_ptr<Interest> interest3a = makeInterest("/zT4XwK0Hnx/28JBUvbEzc", 732); |
| 662 | face3->receiveInterest(*interest3a); |
| 663 | BOOST_CHECK(face3->sentNacks.empty()); |
| 664 | } |
| 665 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 666 | BOOST_FIXTURE_TEST_CASE(InterestLoopWithShortLifetime, UnitTestTimeFixture) // Bug 1953 |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 667 | { |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 668 | Forwarder forwarder; |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 669 | auto face1 = make_shared<DummyFace>(); |
| 670 | auto face2 = make_shared<DummyFace>(); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 671 | forwarder.addFace(face1); |
| 672 | forwarder.addFace(face2); |
| 673 | |
| 674 | // 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] | 675 | face2->afterSend.connect([face1, face2] (uint32_t pktType) { |
| 676 | if (pktType == tlv::Interest) { |
| 677 | auto interest = make_shared<Interest>(face2->sentInterests.back()); |
| 678 | scheduler::schedule(time::milliseconds(170), [face1, interest] { face1->receiveInterest(*interest); }); |
| 679 | } |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 680 | }); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 681 | |
| 682 | Fib& fib = forwarder.getFib(); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 683 | fib.insert("/A").first->addNextHop(*face2, 0); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 684 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 685 | // receive an Interest |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 686 | shared_ptr<Interest> interest = makeInterest("ndn:/A/1"); |
| 687 | interest->setNonce(82101183); |
| 688 | interest->setInterestLifetime(time::milliseconds(50)); |
| 689 | face1->receiveInterest(*interest); |
| 690 | |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 691 | // interest should be forwarded only once, as long as Nonce is in Dead Nonce List |
| 692 | BOOST_ASSERT(time::milliseconds(25) * 40 < forwarder.getDeadNonceList().getLifetime()); |
| 693 | this->advanceClocks(time::milliseconds(25), 40); |
Junxiao Shi | a110f26 | 2014-10-12 12:35:20 -0700 | [diff] [blame] | 694 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 695 | BOOST_CHECK_EQUAL(face2->sentInterests.size(), 1); |
Junxiao Shi | 455581d | 2014-11-17 18:38:40 -0700 | [diff] [blame] | 696 | |
| 697 | // It's unnecessary to check that Interest with duplicate Nonce can be forwarded again |
| 698 | // after it's gone from Dead Nonce List, because the entry lifetime of Dead Nonce List |
| 699 | // is an implementation decision. NDN protocol requires Name+Nonce to be unique, |
| 700 | // without specifying when Name+Nonce could repeat. Forwarder is permitted to suppress |
| 701 | // 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] | 702 | } |
| 703 | |
Junxiao Shi | d41d607 | 2016-06-19 23:35:27 +0000 | [diff] [blame] | 704 | BOOST_AUTO_TEST_CASE(PitLeak) // Bug 3484 |
Junxiao Shi | 330136a | 2016-03-10 04:53:08 -0700 | [diff] [blame] | 705 | { |
| 706 | Forwarder forwarder; |
| 707 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 708 | forwarder.addFace(face1); |
| 709 | |
| 710 | shared_ptr<Interest> interest = makeInterest("ndn:/hcLSAsQ9A"); |
| 711 | interest->setNonce(61883075); |
| 712 | interest->setInterestLifetime(time::seconds(2)); |
| 713 | |
| 714 | DeadNonceList& dnl = forwarder.getDeadNonceList(); |
| 715 | dnl.add(interest->getName(), interest->getNonce()); |
| 716 | Pit& pit = forwarder.getPit(); |
| 717 | BOOST_REQUIRE_EQUAL(pit.size(), 0); |
| 718 | |
| 719 | forwarder.startProcessInterest(*face1, *interest); |
| 720 | this->advanceClocks(time::milliseconds(100), time::seconds(20)); |
| 721 | BOOST_CHECK_EQUAL(pit.size(), 0); |
| 722 | } |
| 723 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 724 | BOOST_AUTO_TEST_CASE(LinkDelegation) |
| 725 | { |
| 726 | Forwarder forwarder; |
| 727 | shared_ptr<Face> face1 = make_shared<DummyFace>(); |
| 728 | shared_ptr<Face> face2 = make_shared<DummyFace>(); |
| 729 | forwarder.addFace(face1); |
| 730 | forwarder.addFace(face2); |
| 731 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 732 | Fib& fib = forwarder.getFib(); |
| 733 | Pit& pit = forwarder.getPit(); |
| 734 | NetworkRegionTable& nrt = forwarder.getNetworkRegionTable(); |
| 735 | |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 736 | shared_ptr<Link> link = makeLink("/net/ndnsim", {{10, "/telia/terabits"}, {20, "/ucla/cs"}}); |
| 737 | |
| 738 | // consumer region |
| 739 | nrt.clear(); |
| 740 | nrt.insert("/arizona/cs/avenir"); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 741 | fib.insert("/").first->addNextHop(*face2, 10); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 742 | |
| 743 | auto interest1 = makeInterest("/net/ndnsim/www/1.html"); |
| 744 | interest1->setLink(link->wireEncode()); |
| 745 | shared_ptr<pit::Entry> pit1 = pit.insert(*interest1).first; |
| 746 | pit1->insertOrUpdateInRecord(face1, *interest1); |
| 747 | |
Junxiao Shi | 05cc50a | 2016-07-11 22:38:21 +0000 | [diff] [blame] | 748 | BOOST_CHECK_EQUAL(forwarder.lookupFib(*pit1).getPrefix(), "/"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 749 | BOOST_CHECK_EQUAL(interest1->hasSelectedDelegation(), false); |
| 750 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 751 | fib.insert("/").first->removeNextHop(*face2); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 752 | |
| 753 | // first default-free router, both delegations are available |
| 754 | nrt.clear(); |
| 755 | nrt.insert("/arizona/cs/hobo"); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 756 | fib.insert("/telia").first->addNextHop(*face2, 10); |
| 757 | fib.insert("/ucla").first->addNextHop(*face2, 10); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 758 | |
| 759 | auto interest2 = makeInterest("/net/ndnsim/www/2.html"); |
| 760 | interest2->setLink(link->wireEncode()); |
| 761 | shared_ptr<pit::Entry> pit2 = pit.insert(*interest2).first; |
| 762 | pit2->insertOrUpdateInRecord(face1, *interest2); |
| 763 | |
Junxiao Shi | 05cc50a | 2016-07-11 22:38:21 +0000 | [diff] [blame] | 764 | BOOST_CHECK_EQUAL(forwarder.lookupFib(*pit2).getPrefix(), "/telia"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 765 | BOOST_REQUIRE_EQUAL(interest2->hasSelectedDelegation(), true); |
| 766 | BOOST_CHECK_EQUAL(interest2->getSelectedDelegation(), "/telia/terabits"); |
| 767 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 768 | fib.erase("/telia"); |
| 769 | fib.erase("/ucla"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 770 | |
| 771 | // first default-free router, only second delegation is available |
| 772 | nrt.clear(); |
| 773 | nrt.insert("/arizona/cs/hobo"); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 774 | fib.insert("/ucla").first->addNextHop(*face2, 10); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 775 | |
| 776 | auto interest3 = makeInterest("/net/ndnsim/www/3.html"); |
| 777 | interest3->setLink(link->wireEncode()); |
| 778 | shared_ptr<pit::Entry> pit3 = pit.insert(*interest3).first; |
| 779 | pit3->insertOrUpdateInRecord(face1, *interest3); |
| 780 | |
Junxiao Shi | 05cc50a | 2016-07-11 22:38:21 +0000 | [diff] [blame] | 781 | BOOST_CHECK_EQUAL(forwarder.lookupFib(*pit3).getPrefix(), "/ucla"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 782 | BOOST_REQUIRE_EQUAL(interest3->hasSelectedDelegation(), true); |
| 783 | BOOST_CHECK_EQUAL(interest3->getSelectedDelegation(), "/ucla/cs"); |
| 784 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 785 | fib.erase("/ucla"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 786 | |
| 787 | // default-free router, chosen SelectedDelegation |
| 788 | nrt.clear(); |
| 789 | nrt.insert("/ucsd/caida/click"); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 790 | fib.insert("/telia").first->addNextHop(*face2, 10); |
| 791 | fib.insert("/ucla").first->addNextHop(*face2, 10); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 792 | |
| 793 | auto interest4 = makeInterest("/net/ndnsim/www/4.html"); |
| 794 | interest4->setLink(link->wireEncode()); |
| 795 | interest4->setSelectedDelegation("/ucla/cs"); |
| 796 | shared_ptr<pit::Entry> pit4 = pit.insert(*interest4).first; |
| 797 | pit4->insertOrUpdateInRecord(face1, *interest4); |
| 798 | |
Junxiao Shi | 05cc50a | 2016-07-11 22:38:21 +0000 | [diff] [blame] | 799 | BOOST_CHECK_EQUAL(forwarder.lookupFib(*pit4).getPrefix(), "/ucla"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 800 | BOOST_REQUIRE_EQUAL(interest4->hasSelectedDelegation(), true); |
| 801 | BOOST_CHECK_EQUAL(interest4->getSelectedDelegation(), "/ucla/cs"); |
| 802 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 803 | fib.erase("/telia"); |
| 804 | fib.erase("/ucla"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 805 | |
| 806 | // producer region |
| 807 | nrt.clear(); |
| 808 | nrt.insert("/ucla/cs/spurs"); |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 809 | fib.insert("/").first->addNextHop(*face2, 10); |
| 810 | fib.insert("/ucla").first->addNextHop(*face2, 10); |
| 811 | fib.insert("/net/ndnsim").first->addNextHop(*face2, 10); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 812 | |
| 813 | auto interest5 = makeInterest("/net/ndnsim/www/5.html"); |
| 814 | interest5->setLink(link->wireEncode()); |
| 815 | interest5->setSelectedDelegation("/ucla/cs"); |
| 816 | shared_ptr<pit::Entry> pit5 = pit.insert(*interest5).first; |
| 817 | pit5->insertOrUpdateInRecord(face1, *interest5); |
| 818 | |
Junxiao Shi | 05cc50a | 2016-07-11 22:38:21 +0000 | [diff] [blame] | 819 | BOOST_CHECK_EQUAL(forwarder.lookupFib(*pit1).getPrefix(), "/net/ndnsim"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 820 | BOOST_REQUIRE_EQUAL(interest5->hasSelectedDelegation(), true); |
| 821 | BOOST_CHECK_EQUAL(interest5->getSelectedDelegation(), "/ucla/cs"); |
| 822 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 823 | fib.insert("/").first->removeNextHop(*face2); |
| 824 | fib.erase("/ucla"); |
| 825 | fib.erase("/ndnsim"); |
Junxiao Shi | 0355e9f | 2015-09-02 07:24:53 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | |
| 829 | class MalformedPacketFixture : public UnitTestTimeFixture |
| 830 | { |
| 831 | protected: |
| 832 | MalformedPacketFixture() |
| 833 | : face1(make_shared<DummyFace>()) |
| 834 | , face2(make_shared<DummyFace>()) |
| 835 | { |
| 836 | forwarder.addFace(face1); |
| 837 | forwarder.addFace(face2); |
| 838 | } |
| 839 | |
| 840 | void |
| 841 | processInterest(shared_ptr<Interest> badInterest) |
| 842 | { |
| 843 | forwarder.startProcessInterest(*face1, *badInterest); |
| 844 | this->continueProcessPacket(); |
| 845 | } |
| 846 | |
| 847 | // processData |
| 848 | |
| 849 | // processNack |
| 850 | |
| 851 | private: |
| 852 | void |
| 853 | continueProcessPacket() |
| 854 | { |
| 855 | this->advanceClocks(time::milliseconds(10), time::seconds(6)); |
| 856 | } |
| 857 | |
| 858 | protected: |
| 859 | Forwarder forwarder; |
| 860 | shared_ptr<DummyFace> face1; // face of incoming bad packet |
| 861 | shared_ptr<DummyFace> face2; // another face for setting up states |
| 862 | }; |
| 863 | |
| 864 | BOOST_FIXTURE_TEST_SUITE(MalformedPacket, MalformedPacketFixture) |
| 865 | |
| 866 | BOOST_AUTO_TEST_CASE(BadLink) |
| 867 | { |
| 868 | shared_ptr<Interest> goodInterest = makeInterest("ndn:/"); |
| 869 | Block wire = goodInterest->wireEncode(); |
| 870 | wire.push_back(ndn::encoding::makeEmptyBlock(tlv::Data)); // bad Link |
| 871 | wire.encode(); |
| 872 | |
| 873 | auto badInterest = make_shared<Interest>(); |
| 874 | BOOST_REQUIRE_NO_THROW(badInterest->wireDecode(wire)); |
| 875 | BOOST_REQUIRE(badInterest->hasLink()); |
| 876 | BOOST_REQUIRE_THROW(badInterest->getLink(), tlv::Error); |
| 877 | |
| 878 | BOOST_CHECK_NO_THROW(this->processInterest(badInterest)); |
| 879 | } |
| 880 | |
| 881 | BOOST_AUTO_TEST_SUITE_END() // MalformedPacket |
| 882 | |
| 883 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 884 | BOOST_AUTO_TEST_SUITE_END() |
| 885 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 886 | } // namespace tests |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 887 | } // namespace nfd |