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