Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/face.hpp" |
| 23 | #include "ndn-cxx/lp/tags.hpp" |
| 24 | #include "ndn-cxx/transport/tcp-transport.hpp" |
| 25 | #include "ndn-cxx/transport/unix-transport.hpp" |
| 26 | #include "ndn-cxx/util/dummy-client-face.hpp" |
| 27 | #include "ndn-cxx/util/scheduler.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 28 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 29 | #include "tests/boost-test.hpp" |
| 30 | #include "tests/make-interest-data.hpp" |
| 31 | #include "tests/unit/identity-management-time-fixture.hpp" |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 32 | |
| 33 | namespace ndn { |
| 34 | namespace tests { |
| 35 | |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 36 | using ndn::util::DummyClientFace; |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 38 | class FaceFixture : public IdentityManagementTimeFixture |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 39 | { |
| 40 | public: |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 41 | explicit |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 42 | FaceFixture(bool enableRegistrationReply = true) |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 43 | : face(io, m_keyChain, {true, enableRegistrationReply}) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 47 | public: |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 48 | DummyClientFace face; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 51 | class FacesNoRegistrationReplyFixture : public FaceFixture |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
| 54 | FacesNoRegistrationReplyFixture() |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 55 | : FaceFixture(false) |
Junxiao Shi | a60d936 | 2014-11-12 09:38:21 -0700 | [diff] [blame] | 56 | { |
| 57 | } |
| 58 | }; |
| 59 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 60 | BOOST_FIXTURE_TEST_SUITE(TestFace, FaceFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 61 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 62 | BOOST_AUTO_TEST_SUITE(Consumer) |
| 63 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 64 | BOOST_AUTO_TEST_CASE(ExpressInterestData) |
| 65 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 66 | size_t nData = 0; |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 67 | face.expressInterest(*makeInterest("/Hello/World", true, 50_ms), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 68 | [&] (const Interest& i, const Data& d) { |
| 69 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
| 70 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 71 | ++nData; |
| 72 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 73 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 74 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 75 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 76 | advanceClocks(40_ms); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 77 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 78 | face.receive(*makeData("/Bye/World/a")); |
| 79 | face.receive(*makeData("/Hello/World/a")); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 80 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 81 | advanceClocks(50_ms, 2); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 82 | |
| 83 | BOOST_CHECK_EQUAL(nData, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 85 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 86 | |
| 87 | size_t nTimeouts = 0; |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 88 | face.expressInterest(*makeInterest("/Hello/World/a/2", false, 50_ms), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 89 | bind([]{}), |
| 90 | bind([]{}), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 91 | bind([&nTimeouts] { ++nTimeouts; })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 92 | advanceClocks(200_ms, 5); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
| 94 | } |
| 95 | |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 96 | BOOST_AUTO_TEST_CASE(ExpressMultipleInterestData) |
| 97 | { |
| 98 | size_t nData = 0; |
| 99 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 100 | face.expressInterest(*makeInterest("/Hello/World", true, 50_ms), |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 101 | [&] (const Interest& i, const Data& d) { |
| 102 | ++nData; |
| 103 | }, |
| 104 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 105 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 106 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 107 | face.expressInterest(*makeInterest("/Hello/World/a", true, 50_ms), |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 108 | [&] (const Interest& i, const Data& d) { |
| 109 | ++nData; |
| 110 | }, |
| 111 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 112 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 113 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 114 | advanceClocks(40_ms); |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 115 | |
| 116 | face.receive(*makeData("/Hello/World/a/b")); |
| 117 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 118 | advanceClocks(50_ms, 2); |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 119 | |
| 120 | BOOST_CHECK_EQUAL(nData, 2); |
| 121 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 2); |
| 122 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 123 | } |
| 124 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 125 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyDataCallback) |
| 126 | { |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 127 | face.expressInterest(*makeInterest("/Hello/World", true), |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 128 | nullptr, |
| 129 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 130 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 131 | advanceClocks(1_ms); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 132 | |
| 133 | BOOST_CHECK_NO_THROW(do { |
| 134 | face.receive(*makeData("/Hello/World/a")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 135 | advanceClocks(1_ms); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 136 | } while (false)); |
| 137 | } |
| 138 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 139 | BOOST_AUTO_TEST_CASE(ExpressInterestTimeout) |
| 140 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 141 | size_t nTimeouts = 0; |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 142 | face.expressInterest(*makeInterest("/Hello/World", false, 50_ms), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 143 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 144 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 145 | [&nTimeouts] (const Interest& i) { |
| 146 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 147 | ++nTimeouts; |
| 148 | }); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 149 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 150 | advanceClocks(200_ms, 5); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 151 | |
| 152 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 153 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 154 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 155 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 158 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyTimeoutCallback) |
| 159 | { |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 160 | face.expressInterest(*makeInterest("/Hello/World", false, 50_ms), |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 161 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 162 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 163 | nullptr); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 164 | advanceClocks(40_ms); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 165 | |
| 166 | BOOST_CHECK_NO_THROW(do { |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 167 | advanceClocks(6_ms, 2); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 168 | } while (false)); |
| 169 | } |
| 170 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 171 | BOOST_AUTO_TEST_CASE(ExpressInterestNack) |
| 172 | { |
| 173 | size_t nNacks = 0; |
| 174 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 175 | auto interest = makeInterest("/Hello/World", false, 50_ms); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 176 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 177 | face.expressInterest(*interest, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 178 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 179 | [&] (const Interest& i, const lp::Nack& n) { |
| 180 | BOOST_CHECK(i.getName().isPrefixOf(n.getInterest().getName())); |
| 181 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 182 | BOOST_CHECK_EQUAL(n.getReason(), lp::NackReason::DUPLICATE); |
| 183 | ++nNacks; |
| 184 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 185 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 186 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 187 | advanceClocks(40_ms); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 188 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame] | 189 | face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 190 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 191 | advanceClocks(50_ms, 2); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 192 | |
| 193 | BOOST_CHECK_EQUAL(nNacks, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 194 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 197 | BOOST_AUTO_TEST_CASE(ExpressMultipleInterestNack) |
| 198 | { |
| 199 | size_t nNacks = 0; |
| 200 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 201 | auto interest = makeInterest("/Hello/World", false, 50_ms, 1); |
| 202 | face.expressInterest(*interest, |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 203 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 204 | [&] (const Interest& i, const lp::Nack& n) { |
| 205 | ++nNacks; |
| 206 | }, |
| 207 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 208 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 209 | interest->setNonce(2); |
| 210 | face.expressInterest(*interest, |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 211 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 212 | [&] (const Interest& i, const lp::Nack& n) { |
| 213 | ++nNacks; |
| 214 | }, |
| 215 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 216 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 217 | advanceClocks(40_ms); |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 218 | |
| 219 | face.receive(makeNack(face.sentInterests.at(1), lp::NackReason::DUPLICATE)); |
| 220 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 221 | advanceClocks(50_ms, 2); |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 222 | |
| 223 | BOOST_CHECK_EQUAL(nNacks, 2); |
| 224 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 2); |
| 225 | } |
| 226 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 227 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyNackCallback) |
| 228 | { |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 229 | face.expressInterest(*makeInterest("/Hello/World"), |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 230 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 231 | nullptr, |
| 232 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 233 | advanceClocks(1_ms); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 234 | |
| 235 | BOOST_CHECK_NO_THROW(do { |
| 236 | face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 237 | advanceClocks(1_ms); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 238 | } while (false)); |
| 239 | } |
| 240 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 241 | BOOST_AUTO_TEST_CASE(RemovePendingInterest) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 242 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 243 | const PendingInterestId* interestId = |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 244 | face.expressInterest(*makeInterest("/Hello/World", true, 50_ms), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 245 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 246 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 247 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 248 | advanceClocks(10_ms); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 249 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 250 | face.removePendingInterest(interestId); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 251 | advanceClocks(10_ms); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 252 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 253 | face.receive(*makeData("/Hello/World/%21")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 254 | advanceClocks(200_ms, 5); |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 255 | |
| 256 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 257 | BOOST_CHECK(true); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 258 | } |
| 259 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 260 | BOOST_AUTO_TEST_CASE(RemoveAllPendingInterests) |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 261 | { |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 262 | face.expressInterest(*makeInterest("/Hello/World/0", false, 50_ms), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 263 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 264 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 265 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 266 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 267 | face.expressInterest(*makeInterest("/Hello/World/1", false, 50_ms), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 268 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 269 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 270 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 271 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 272 | advanceClocks(10_ms); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 273 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 274 | face.removeAllPendingInterests(); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 275 | advanceClocks(10_ms); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 276 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 277 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 278 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 279 | face.receive(*makeData("/Hello/World/0")); |
| 280 | face.receive(*makeData("/Hello/World/1")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 281 | advanceClocks(200_ms, 5); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 282 | } |
| 283 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 284 | BOOST_AUTO_TEST_CASE(DestructionWithoutCancellingPendingInterests) // Bug #2518 |
| 285 | { |
| 286 | { |
| 287 | DummyClientFace face2(io, m_keyChain); |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 288 | face2.expressInterest(*makeInterest("/Hello/World", false, 50_ms), |
Alexander Afanasyev | e6835fe | 2017-01-19 20:05:01 -0800 | [diff] [blame] | 289 | nullptr, nullptr, nullptr); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 290 | advanceClocks(50_ms, 2); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 293 | advanceClocks(50_ms, 2); // should not crash |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 294 | |
| 295 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 296 | BOOST_CHECK(true); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Ashlesh Gawande | e240422 | 2018-05-21 18:30:24 -0500 | [diff] [blame] | 299 | BOOST_AUTO_TEST_CASE(DataCallbackPutData) // Bug 4596 |
| 300 | { |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 301 | face.expressInterest(*makeInterest("/localhost/notification/1"), |
Ashlesh Gawande | e240422 | 2018-05-21 18:30:24 -0500 | [diff] [blame] | 302 | [&] (const Interest& i, const Data& d) { |
| 303 | face.put(*makeData("/chronosync/sampleDigest/1")); |
| 304 | }, nullptr, nullptr); |
| 305 | advanceClocks(10_ms); |
| 306 | BOOST_CHECK_EQUAL(face.sentInterests.back().getName(), "/localhost/notification/1"); |
| 307 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 308 | face.receive(*makeInterest("/chronosync/sampleDigest", true)); |
Ashlesh Gawande | e240422 | 2018-05-21 18:30:24 -0500 | [diff] [blame] | 309 | advanceClocks(10_ms); |
| 310 | |
| 311 | face.put(*makeData("/localhost/notification/1")); |
| 312 | advanceClocks(10_ms); |
| 313 | BOOST_CHECK_EQUAL(face.sentData.back().getName(), "/chronosync/sampleDigest/1"); |
| 314 | } |
| 315 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 316 | BOOST_AUTO_TEST_SUITE_END() // Consumer |
| 317 | |
| 318 | BOOST_AUTO_TEST_SUITE(Producer) |
| 319 | |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 320 | BOOST_AUTO_TEST_CASE(PutData) |
| 321 | { |
| 322 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 323 | |
| 324 | Data data("/4g7xxcuEow/KFvK5Kf2m"); |
| 325 | signData(data); |
| 326 | face.put(data); |
| 327 | |
| 328 | lp::CachePolicy cachePolicy; |
| 329 | cachePolicy.setPolicy(lp::CachePolicyType::NO_CACHE); |
| 330 | data.setTag(make_shared<lp::CachePolicyTag>(cachePolicy)); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 331 | data.setTag(make_shared<lp::CongestionMarkTag>(1)); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 332 | face.put(data); |
| 333 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 334 | advanceClocks(10_ms); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 335 | BOOST_REQUIRE_EQUAL(face.sentData.size(), 2); |
| 336 | BOOST_CHECK(face.sentData[0].getTag<lp::CachePolicyTag>() == nullptr); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 337 | BOOST_CHECK(face.sentData[0].getTag<lp::CongestionMarkTag>() == nullptr); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 338 | BOOST_CHECK(face.sentData[1].getTag<lp::CachePolicyTag>() != nullptr); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 339 | BOOST_CHECK(face.sentData[1].getTag<lp::CongestionMarkTag>() != nullptr); |
Junxiao Shi | e7bb6c8 | 2016-08-08 23:16:35 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 342 | BOOST_AUTO_TEST_CASE(PutDataLoopback) |
| 343 | { |
| 344 | bool hasInterest1 = false, hasData = false; |
| 345 | |
| 346 | // first InterestFilter allows loopback and should receive Interest |
| 347 | face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) { |
| 348 | hasInterest1 = true; |
| 349 | // do not respond with Data right away, so Face must send Interest to forwarder |
| 350 | }); |
| 351 | // second InterestFilter disallows loopback and should not receive Interest |
| 352 | face.setInterestFilter(InterestFilter("/").allowLoopback(false), |
| 353 | bind([] { BOOST_ERROR("Unexpected Interest on second InterestFilter"); })); |
| 354 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 355 | face.expressInterest(*makeInterest("/A", true), |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 356 | bind([&] { hasData = true; }), |
| 357 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 358 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 359 | advanceClocks(1_ms); |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 360 | BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back |
| 361 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder |
| 362 | BOOST_CHECK_EQUAL(hasData, false); // waiting for Data |
| 363 | |
| 364 | face.put(*makeData("/A/B")); // first InterestFilter responds with Data |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 365 | advanceClocks(1_ms); |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 366 | BOOST_CHECK_EQUAL(hasData, true); |
| 367 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); // do not spill Data to forwarder |
| 368 | } |
| 369 | |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 370 | BOOST_AUTO_TEST_CASE(PutMultipleData) |
| 371 | { |
| 372 | bool hasInterest1 = false; |
| 373 | // register two Interest destinations |
| 374 | face.setInterestFilter("/", bind([&] { |
| 375 | hasInterest1 = true; |
| 376 | // sending Data right away from the first destination, don't care whether Interest goes to second destination |
| 377 | face.put(*makeData("/A/B")); |
| 378 | })); |
| 379 | face.setInterestFilter("/", bind([]{})); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 380 | advanceClocks(10_ms); |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 381 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 382 | face.receive(*makeInterest("/A", true)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 383 | advanceClocks(10_ms); |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 384 | BOOST_CHECK(hasInterest1); |
| 385 | BOOST_CHECK_EQUAL(face.sentData.size(), 1); |
| 386 | BOOST_CHECK_EQUAL(face.sentData.at(0).getName(), "/A/B"); |
| 387 | |
| 388 | face.put(*makeData("/A/C")); |
| 389 | BOOST_CHECK_EQUAL(face.sentData.size(), 1); // additional Data are ignored |
| 390 | } |
| 391 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 392 | BOOST_AUTO_TEST_CASE(PutNack) |
| 393 | { |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 394 | face.setInterestFilter("/", bind([]{})); // register one Interest destination so that face can accept Nacks |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 395 | advanceClocks(10_ms); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 396 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 397 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
| 398 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 399 | face.put(makeNack(*makeInterest("/unsolicited", false, DEFAULT_INTEREST_LIFETIME, 18645250), |
| 400 | lp::NackReason::NO_ROUTE)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 401 | advanceClocks(10_ms); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 402 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); // unsolicited Nack would not be sent |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 403 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 404 | auto interest1 = makeInterest("/Hello/World", false, DEFAULT_INTEREST_LIFETIME, 14247162); |
| 405 | face.receive(*interest1); |
| 406 | auto interest2 = makeInterest("/another/prefix", false, DEFAULT_INTEREST_LIFETIME, 92203002); |
| 407 | face.receive(*interest2); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 408 | advanceClocks(10_ms); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 409 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 410 | face.put(makeNack(*interest1, lp::NackReason::DUPLICATE)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 411 | advanceClocks(10_ms); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 412 | BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 1); |
| 413 | BOOST_CHECK_EQUAL(face.sentNacks[0].getReason(), lp::NackReason::DUPLICATE); |
| 414 | BOOST_CHECK(face.sentNacks[0].getTag<lp::CongestionMarkTag>() == nullptr); |
| 415 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 416 | auto nack = makeNack(*interest2, lp::NackReason::NO_ROUTE); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 417 | nack.setTag(make_shared<lp::CongestionMarkTag>(1)); |
| 418 | face.put(nack); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 419 | advanceClocks(10_ms); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 420 | BOOST_REQUIRE_EQUAL(face.sentNacks.size(), 2); |
Junxiao Shi | 1ad0b4b | 2017-08-18 14:19:14 +0000 | [diff] [blame] | 421 | BOOST_CHECK_EQUAL(face.sentNacks[1].getReason(), lp::NackReason::NO_ROUTE); |
Eric Newberry | 4d261b6 | 2016-11-10 13:40:09 -0700 | [diff] [blame] | 422 | BOOST_CHECK(face.sentNacks[1].getTag<lp::CongestionMarkTag>() != nullptr); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 423 | } |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 424 | |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 425 | BOOST_AUTO_TEST_CASE(PutMultipleNack) |
| 426 | { |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 427 | bool hasInterest1 = false, hasInterest2 = false; |
| 428 | // register two Interest destinations |
| 429 | face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) { |
| 430 | hasInterest1 = true; |
| 431 | // sending Nack right away from the first destination, Interest should still go to second destination |
| 432 | face.put(makeNack(interest, lp::NackReason::CONGESTION)); |
| 433 | }); |
| 434 | face.setInterestFilter("/", bind([&] { hasInterest2 = true; })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 435 | advanceClocks(10_ms); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 436 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 437 | auto interest = makeInterest("/A", false, DEFAULT_INTEREST_LIFETIME, 14333271); |
| 438 | face.receive(*interest); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 439 | advanceClocks(10_ms); |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 440 | BOOST_CHECK(hasInterest1); |
| 441 | BOOST_CHECK(hasInterest2); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 442 | |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 443 | // Nack from first destination is received, should wait for a response from the other destination |
| 444 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 445 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 446 | face.put(makeNack(*interest, lp::NackReason::NO_ROUTE)); // Nack from second destination |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 447 | advanceClocks(10_ms); |
Junxiao Shi | 859888f | 2017-09-12 14:29:16 +0000 | [diff] [blame] | 448 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // sending Nack after both destinations Nacked |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 449 | BOOST_CHECK_EQUAL(face.sentNacks.at(0).getReason(), lp::NackReason::CONGESTION); // least severe reason |
| 450 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 451 | face.put(makeNack(*interest, lp::NackReason::DUPLICATE)); |
Junxiao Shi | 79a7a16 | 2017-09-09 08:33:57 +0000 | [diff] [blame] | 452 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); // additional Nacks are ignored |
| 453 | } |
| 454 | |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 455 | BOOST_AUTO_TEST_CASE(PutMultipleNackLoopback) |
| 456 | { |
| 457 | bool hasInterest1 = false, hasNack = false; |
| 458 | |
| 459 | // first InterestFilter allows loopback and should receive Interest |
| 460 | face.setInterestFilter("/", [&] (const InterestFilter&, const Interest& interest) { |
| 461 | hasInterest1 = true; |
| 462 | face.put(makeNack(interest, lp::NackReason::CONGESTION)); |
| 463 | }); |
| 464 | // second InterestFilter disallows loopback and should not receive Interest |
| 465 | face.setInterestFilter(InterestFilter("/").allowLoopback(false), |
| 466 | bind([] { BOOST_ERROR("Unexpected Interest on second InterestFilter"); })); |
| 467 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 468 | auto interest = makeInterest("/A", false, DEFAULT_INTEREST_LIFETIME, 28395852); |
| 469 | face.expressInterest(*interest, |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 470 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 471 | [&] (const Interest&, const lp::Nack& nack) { |
| 472 | hasNack = true; |
| 473 | BOOST_CHECK_EQUAL(nack.getReason(), lp::NackReason::CONGESTION); |
| 474 | }, |
| 475 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 476 | advanceClocks(1_ms); |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 477 | BOOST_CHECK_EQUAL(hasInterest1, true); // Interest looped back |
| 478 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); // Interest sent to forwarder |
| 479 | BOOST_CHECK_EQUAL(hasNack, false); // waiting for Nack from forwarder |
| 480 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 481 | face.receive(makeNack(*interest, lp::NackReason::NO_ROUTE)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 482 | advanceClocks(1_ms); |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 483 | BOOST_CHECK_EQUAL(hasNack, true); |
| 484 | } |
| 485 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 486 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilter) |
| 487 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 488 | size_t nInterests = 0; |
| 489 | size_t nRegs = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 490 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 491 | face.setInterestFilter("/Hello/World", |
| 492 | bind([&nInterests] { ++nInterests; }), |
| 493 | bind([&nRegs] { ++nRegs; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 494 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 495 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 496 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 497 | BOOST_CHECK_EQUAL(nInterests, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 498 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 499 | face.receive(*makeInterest("/Hello/World/%21")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 500 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 501 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 502 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 503 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 504 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 505 | face.receive(*makeInterest("/Bye/World/%21")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 506 | advanceClocks(10000_ms, 10); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 507 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 508 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 509 | face.receive(*makeInterest("/Hello/World/%21/2")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 510 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 511 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 512 | |
| 513 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 514 | face.unsetInterestFilter(regPrefixId); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 515 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 516 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 517 | face.receive(*makeInterest("/Hello/World/%21/3")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 518 | BOOST_CHECK_EQUAL(nInterests, 2); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 519 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 520 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 521 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 522 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 523 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(nullptr)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 524 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 525 | } |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 526 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 527 | BOOST_AUTO_TEST_CASE(SetInterestFilterEmptyInterestCallback) |
| 528 | { |
| 529 | face.setInterestFilter("/A", nullptr); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 530 | advanceClocks(1_ms); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 531 | |
| 532 | BOOST_CHECK_NO_THROW(do { |
| 533 | face.receive(*makeInterest("/A/1")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 534 | advanceClocks(1_ms); |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 535 | } while (false)); |
| 536 | } |
| 537 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 538 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilterWithoutSucessCallback) |
| 539 | { |
| 540 | size_t nInterests = 0; |
| 541 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 542 | face.setInterestFilter("/Hello/World", |
| 543 | bind([&nInterests] { ++nInterests; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 544 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 545 | advanceClocks(25_ms, 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 546 | BOOST_CHECK_EQUAL(nInterests, 0); |
| 547 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 548 | face.receive(*makeInterest("/Hello/World/%21")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 549 | advanceClocks(25_ms, 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 550 | |
| 551 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 552 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 553 | face.receive(*makeInterest("/Bye/World/%21")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 554 | advanceClocks(10000_ms, 10); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 555 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 556 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 557 | face.receive(*makeInterest("/Hello/World/%21/2")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 558 | advanceClocks(25_ms, 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 559 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 560 | |
| 561 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 562 | face.unsetInterestFilter(regPrefixId); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 563 | advanceClocks(25_ms, 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 564 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 565 | face.receive(*makeInterest("/Hello/World/%21/3")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 566 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 567 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 568 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 569 | advanceClocks(25_ms, 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 570 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 571 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(nullptr)); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 572 | advanceClocks(25_ms, 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 575 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFail, FacesNoRegistrationReplyFixture) |
| 576 | { |
| 577 | // don't enable registration reply |
| 578 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 579 | face.setInterestFilter("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 580 | bind([] { BOOST_FAIL("Unexpected Interest"); }), |
| 581 | bind([] { BOOST_FAIL("Unexpected success of setInterestFilter"); }), |
| 582 | bind([&nRegFailed] { ++nRegFailed; })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 583 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 584 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 585 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 586 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 587 | advanceClocks(2000_ms, 5); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 588 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 591 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFailWithoutSuccessCallback, FacesNoRegistrationReplyFixture) |
| 592 | { |
| 593 | // don't enable registration reply |
| 594 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 595 | face.setInterestFilter("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 596 | bind([] { BOOST_FAIL("Unexpected Interest"); }), |
| 597 | bind([&nRegFailed] { ++nRegFailed; })); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 598 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 599 | advanceClocks(25_ms, 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 600 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 601 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 602 | advanceClocks(2000_ms, 5); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 603 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
| 604 | } |
| 605 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 606 | BOOST_AUTO_TEST_CASE(RegisterUnregisterPrefix) |
| 607 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 608 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 609 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 610 | face.registerPrefix("/Hello/World", |
| 611 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 612 | bind([] { BOOST_FAIL("Unexpected registerPrefix failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 613 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 614 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 615 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 616 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 617 | size_t nUnregSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 618 | face.unregisterPrefix(regPrefixId, |
| 619 | bind([&nUnregSuccesses] { ++nUnregSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 620 | bind([] { BOOST_FAIL("Unexpected unregisterPrefix failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 621 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 622 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 623 | BOOST_CHECK_EQUAL(nUnregSuccesses, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 624 | } |
| 625 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 626 | BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefixFail, FacesNoRegistrationReplyFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 627 | { |
Junxiao Shi | b682891 | 2017-11-20 14:06:32 +0000 | [diff] [blame] | 628 | // don't enable registration reply |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 629 | size_t nRegFailures = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 630 | face.registerPrefix("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 631 | bind([] { BOOST_FAIL("Unexpected registerPrefix success"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 632 | bind([&nRegFailures] { ++nRegFailures; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 633 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 634 | advanceClocks(5000_ms, 20); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 635 | BOOST_CHECK_EQUAL(nRegFailures, 1); |
| 636 | } |
| 637 | |
| 638 | BOOST_AUTO_TEST_CASE(SimilarFilters) |
| 639 | { |
| 640 | size_t nInInterests1 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 641 | face.setInterestFilter("/Hello/World", |
| 642 | bind([&nInInterests1] { ++nInInterests1; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 643 | nullptr, |
| 644 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 645 | |
| 646 | size_t nInInterests2 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 647 | face.setInterestFilter("/Hello", |
| 648 | bind([&nInInterests2] { ++nInInterests2; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 649 | nullptr, |
| 650 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 651 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 652 | size_t nInInterests3 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 653 | face.setInterestFilter("/Los/Angeles/Lakers", |
| 654 | bind([&nInInterests3] { ++nInInterests3; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 655 | nullptr, |
| 656 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 657 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 658 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 659 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 660 | face.receive(*makeInterest("/Hello/World/%21")); |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 661 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 662 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 663 | BOOST_CHECK_EQUAL(nInInterests1, 1); |
| 664 | BOOST_CHECK_EQUAL(nInInterests2, 1); |
| 665 | BOOST_CHECK_EQUAL(nInInterests3, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | BOOST_AUTO_TEST_CASE(SetRegexFilterError) |
| 669 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 670 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 671 | [] (const Name&, const Interest&) { |
| 672 | BOOST_FAIL("InterestFilter::Error should have been triggered"); |
| 673 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 674 | nullptr, |
| 675 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 676 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 677 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 678 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 679 | BOOST_REQUIRE_THROW(face.receive(*makeInterest("/Hello/World/XXX/b/c")), InterestFilter::Error); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | BOOST_AUTO_TEST_CASE(SetRegexFilter) |
| 683 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 684 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 685 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 686 | bind([&nInInterests] { ++nInInterests; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 687 | nullptr, |
| 688 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 689 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 690 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 691 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 692 | face.receive(*makeInterest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 693 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 694 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 695 | face.receive(*makeInterest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 696 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 697 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 698 | face.receive(*makeInterest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 699 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 700 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 701 | face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 702 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 703 | } |
| 704 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 705 | BOOST_AUTO_TEST_CASE(SetRegexFilterAndRegister) |
| 706 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 707 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 708 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 709 | bind([&nInInterests] { ++nInInterests; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 710 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 711 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 712 | face.registerPrefix("/Hello/World", |
| 713 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 714 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 715 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 716 | advanceClocks(25_ms, 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 717 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 718 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 719 | face.receive(*makeInterest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 720 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 721 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 722 | face.receive(*makeInterest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 723 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 724 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 725 | face.receive(*makeInterest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 726 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 727 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 728 | face.receive(*makeInterest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 729 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 730 | } |
| 731 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 732 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterNoReg, FacesNoRegistrationReplyFixture) // Bug 2318 |
| 733 | { |
| 734 | // This behavior is specific to DummyClientFace. |
| 735 | // Regular Face won't accept incoming packets until something is sent. |
| 736 | |
| 737 | int hit = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 738 | face.setInterestFilter(Name("/"), bind([&hit] { ++hit; })); |
| 739 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 740 | |
Junxiao Shi | b55e5d3 | 2018-07-18 13:32:00 -0600 | [diff] [blame] | 741 | face.receive(*makeInterest("/A")); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 742 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 743 | |
| 744 | BOOST_CHECK_EQUAL(hit, 1); |
| 745 | } |
| 746 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 747 | BOOST_AUTO_TEST_SUITE_END() // Producer |
| 748 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 749 | BOOST_AUTO_TEST_SUITE(IoRoutines) |
| 750 | |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 751 | BOOST_AUTO_TEST_CASE(ProcessEvents) |
| 752 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 753 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 754 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 755 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 756 | face.registerPrefix("/Hello/World", |
| 757 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 758 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 759 | |
| 760 | // io_service::poll() without reset |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 761 | face.getIoService().poll(); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 762 | BOOST_CHECK_EQUAL(nRegSuccesses, 0); |
| 763 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 764 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 765 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 766 | } |
| 767 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 768 | BOOST_AUTO_TEST_CASE(DestroyWithoutProcessEvents) // Bug 3248 |
| 769 | { |
| 770 | auto face2 = make_unique<Face>(io); |
| 771 | face2.reset(); |
| 772 | |
| 773 | io.poll(); // should not crash |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 774 | |
| 775 | // avoid "test case [...] did not check any assertions" message from Boost.Test |
| 776 | BOOST_CHECK(true); |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | BOOST_AUTO_TEST_SUITE_END() // IoRoutines |
| 780 | |
| 781 | BOOST_AUTO_TEST_SUITE(Transport) |
| 782 | |
| 783 | using ndn::Transport; |
| 784 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 785 | struct PibDirWithDefaultTpm |
| 786 | { |
| 787 | const std::string PATH = "build/keys-with-default-tpm"; |
| 788 | }; |
| 789 | |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 790 | BOOST_FIXTURE_TEST_CASE(FaceTransport, IdentityManagementTimeFixture) |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 791 | { |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 792 | BOOST_CHECK(Face().getTransport() != nullptr); |
| 793 | |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 794 | BOOST_CHECK(Face(shared_ptr<Transport>()).getTransport() != nullptr); |
| 795 | BOOST_CHECK(Face(shared_ptr<Transport>(), io).getTransport() != nullptr); |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 796 | BOOST_CHECK(Face(shared_ptr<Transport>(), io, m_keyChain).getTransport() != nullptr); |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 797 | |
| 798 | auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled |
| 799 | BOOST_CHECK(Face(transport).getTransport() == transport); |
| 800 | BOOST_CHECK(Face(transport, io).getTransport() == transport); |
Alexander Afanasyev | 80782e0 | 2017-01-04 13:16:54 -0800 | [diff] [blame] | 801 | BOOST_CHECK(Face(transport, io, m_keyChain).getTransport() == transport); |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 804 | class WithEnv : private IdentityManagementTimeFixture |
| 805 | { |
| 806 | public: |
| 807 | WithEnv() |
| 808 | { |
| 809 | if (getenv("NDN_CLIENT_TRANSPORT") != nullptr) { |
| 810 | m_oldTransport = getenv("NDN_CLIENT_TRANSPORT"); |
| 811 | unsetenv("NDN_CLIENT_TRANSPORT"); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | void |
| 816 | configure(const std::string& faceUri) |
| 817 | { |
| 818 | setenv("NDN_CLIENT_TRANSPORT", faceUri.c_str(), true); |
| 819 | } |
| 820 | |
| 821 | ~WithEnv() |
| 822 | { |
| 823 | if (!m_oldTransport.empty()) { |
| 824 | setenv("NDN_CLIENT_TRANSPORT", m_oldTransport.c_str(), true); |
| 825 | } |
| 826 | else { |
| 827 | unsetenv("NDN_CLIENT_TRANSPORT"); |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | private: |
| 832 | std::string m_oldTransport; |
| 833 | }; |
| 834 | |
| 835 | class WithConfig : private TestHomeFixture<DefaultPibDir> |
| 836 | { |
| 837 | public: |
| 838 | void |
| 839 | configure(const std::string& faceUri) |
| 840 | { |
| 841 | createClientConf({"transport=" + faceUri}); |
| 842 | } |
| 843 | }; |
| 844 | |
| 845 | class WithEnvAndConfig : public WithEnv, public WithConfig |
| 846 | { |
| 847 | }; |
| 848 | |
| 849 | typedef boost::mpl::vector<WithEnv, WithConfig> ConfigOptions; |
| 850 | |
| 851 | BOOST_FIXTURE_TEST_CASE(NoConfig, WithEnvAndConfig) // fixture configures test HOME and PIB/TPM path |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 852 | { |
| 853 | shared_ptr<Face> face; |
| 854 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 855 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 858 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Unix, T, ConfigOptions, T) |
| 859 | { |
| 860 | this->configure("unix://some/path"); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 861 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 862 | shared_ptr<Face> face; |
| 863 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 864 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
| 865 | } |
| 866 | |
| 867 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Tcp, T, ConfigOptions, T) |
| 868 | { |
| 869 | this->configure("tcp://127.0.0.1:6000"); |
| 870 | |
| 871 | shared_ptr<Face> face; |
| 872 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 873 | BOOST_CHECK(dynamic_pointer_cast<TcpTransport>(face->getTransport()) != nullptr); |
| 874 | } |
| 875 | |
| 876 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongTransport, T, ConfigOptions, T) |
| 877 | { |
| 878 | this->configure("wrong-transport:"); |
| 879 | |
| 880 | BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error); |
| 881 | } |
| 882 | |
| 883 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongUri, T, ConfigOptions, T) |
| 884 | { |
| 885 | this->configure("wrong-uri"); |
| 886 | |
| 887 | BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error); |
| 888 | } |
| 889 | |
| 890 | BOOST_FIXTURE_TEST_CASE(EnvOverride, WithEnvAndConfig) |
| 891 | { |
| 892 | this->WithEnv::configure("tcp://127.0.0.1:6000"); |
| 893 | this->WithConfig::configure("unix://some/path"); |
| 894 | |
| 895 | shared_ptr<Face> face; |
| 896 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 897 | BOOST_CHECK(dynamic_pointer_cast<TcpTransport>(face->getTransport()) != nullptr); |
| 898 | } |
| 899 | |
| 900 | BOOST_FIXTURE_TEST_CASE(ExplicitTransport, WithEnvAndConfig) |
| 901 | { |
| 902 | this->WithEnv::configure("wrong-uri"); |
| 903 | this->WithConfig::configure("wrong-transport:"); |
| 904 | |
| 905 | auto transport = make_shared<UnixTransport>("unix://some/path"); |
| 906 | shared_ptr<Face> face; |
| 907 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>(transport)); |
| 908 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
| 909 | } |
| 910 | |
Junxiao Shi | ae0b418 | 2016-08-08 22:53:17 +0000 | [diff] [blame] | 911 | BOOST_AUTO_TEST_SUITE_END() // Transport |
| 912 | |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 913 | BOOST_AUTO_TEST_SUITE_END() // TestFace |
| 914 | |
| 915 | } // namespace tests |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 916 | } // namespace ndn |