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