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