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