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