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