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