Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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" |
| 23 | #include "util/scheduler.hpp" |
| 24 | #include "security/key-chain.hpp" |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 25 | #include "util/dummy-client-face.hpp" |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 26 | #include "transport/tcp-transport.hpp" |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 27 | #include "transport/unix-transport.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" |
| 31 | #include "key-chain-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 | e4f8c3b | 2016-06-23 16:03:48 -0700 | [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; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 68 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 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 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 77 | advanceClocks(time::milliseconds(40)); |
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 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 82 | advanceClocks(time::milliseconds(50), 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; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 89 | face.expressInterest(Interest("/Hello/World/a/2", time::milliseconds(50)), |
| 90 | bind([]{}), |
| 91 | bind([]{}), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 92 | bind([&nTimeouts] { ++nTimeouts; })); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 93 | advanceClocks(time::milliseconds(200), 5); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 94 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
| 95 | } |
| 96 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 97 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyDataCallback) |
| 98 | { |
| 99 | face.expressInterest(Interest("/Hello/World"), |
| 100 | nullptr, |
| 101 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 102 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 103 | advanceClocks(time::milliseconds(1)); |
| 104 | |
| 105 | BOOST_CHECK_NO_THROW(do { |
| 106 | face.receive(*makeData("/Hello/World/a")); |
| 107 | advanceClocks(time::milliseconds(1)); |
| 108 | } while (false)); |
| 109 | } |
| 110 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 111 | BOOST_AUTO_TEST_CASE(DeprecatedExpressInterestData) |
| 112 | { |
| 113 | size_t nData = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 114 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 115 | [&] (const Interest& i, Data& d) { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 116 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
| 117 | ++nData; |
| 118 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 119 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 120 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 121 | advanceClocks(time::milliseconds(40)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 122 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 123 | face.receive(*makeData("/Bye/World/a")); |
| 124 | face.receive(*makeData("/Hello/World/a")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 125 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 126 | advanceClocks(time::milliseconds(50), 2); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 127 | |
| 128 | BOOST_CHECK_EQUAL(nData, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 129 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 130 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 131 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 132 | face.expressInterest(Interest("/Hello/World/a", time::milliseconds(50)), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 133 | [&] (const Interest& i, Data& d) { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 134 | BOOST_CHECK(i.getName().isPrefixOf(d.getName())); |
| 135 | ++nData; |
| 136 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 137 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 138 | advanceClocks(time::milliseconds(40)); |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 139 | face.receive(*makeData("/Hello/World/a/1/xxxxx")); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 140 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 141 | advanceClocks(time::milliseconds(50), 2); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 142 | |
| 143 | BOOST_CHECK_EQUAL(nData, 2); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 144 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 2); |
| 145 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | BOOST_AUTO_TEST_CASE(ExpressInterestTimeout) |
| 149 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 150 | size_t nTimeouts = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 151 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 152 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 153 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 154 | [&nTimeouts] (const Interest& i) { |
| 155 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 156 | ++nTimeouts; |
| 157 | }); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 158 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 159 | advanceClocks(time::milliseconds(200), 5); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 160 | |
| 161 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 162 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 163 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 164 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 167 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyTimeoutCallback) |
| 168 | { |
| 169 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 170 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 171 | bind([] { BOOST_FAIL("Unexpected Nack"); }), |
| 172 | nullptr); |
| 173 | advanceClocks(time::milliseconds(40)); |
| 174 | |
| 175 | BOOST_CHECK_NO_THROW(do { |
| 176 | advanceClocks(time::milliseconds(6), 2); |
| 177 | } while (false)); |
| 178 | } |
| 179 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 180 | BOOST_AUTO_TEST_CASE(DeprecatedExpressInterestTimeout) |
| 181 | { |
| 182 | size_t nTimeouts = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 183 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 184 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 185 | bind([&nTimeouts] { ++nTimeouts; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 186 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 187 | advanceClocks(time::milliseconds(200), 5); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 188 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 189 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 190 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 191 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 194 | BOOST_AUTO_TEST_CASE(ExpressInterestNack) |
| 195 | { |
| 196 | size_t nNacks = 0; |
| 197 | |
| 198 | Interest interest("/Hello/World", time::milliseconds(50)); |
| 199 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 200 | face.expressInterest(interest, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 201 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 202 | [&] (const Interest& i, const lp::Nack& n) { |
| 203 | BOOST_CHECK(i.getName().isPrefixOf(n.getInterest().getName())); |
| 204 | BOOST_CHECK_EQUAL(i.getName(), "/Hello/World"); |
| 205 | BOOST_CHECK_EQUAL(n.getReason(), lp::NackReason::DUPLICATE); |
| 206 | ++nNacks; |
| 207 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 208 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 209 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 210 | advanceClocks(time::milliseconds(40)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 211 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 212 | face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE)); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 213 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 214 | advanceClocks(time::milliseconds(50), 2); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 215 | |
| 216 | BOOST_CHECK_EQUAL(nNacks, 1); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 217 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 220 | BOOST_AUTO_TEST_CASE(ExpressInterestEmptyNackCallback) |
| 221 | { |
| 222 | face.expressInterest(Interest("/Hello/World"), |
| 223 | bind([] { BOOST_FAIL("Unexpected Data"); }), |
| 224 | nullptr, |
| 225 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
| 226 | advanceClocks(time::milliseconds(1)); |
| 227 | |
| 228 | BOOST_CHECK_NO_THROW(do { |
| 229 | face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::DUPLICATE)); |
| 230 | advanceClocks(time::milliseconds(1)); |
| 231 | } while (false)); |
| 232 | } |
| 233 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 234 | BOOST_AUTO_TEST_CASE(DeprecatedExpressInterestNack) |
| 235 | { |
| 236 | size_t nTimeouts = 0; |
| 237 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 238 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 239 | bind([&nTimeouts] { ++nTimeouts; })); |
| 240 | advanceClocks(time::milliseconds(1)); |
| 241 | |
| 242 | face.receive(makeNack(face.sentInterests.at(0), lp::NackReason::CONGESTION)); |
| 243 | advanceClocks(time::milliseconds(1)); |
| 244 | |
| 245 | BOOST_CHECK_EQUAL(nTimeouts, 1); |
| 246 | BOOST_CHECK_EQUAL(face.sentInterests.size(), 1); |
| 247 | BOOST_CHECK_EQUAL(face.sentData.size(), 0); |
| 248 | } |
| 249 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 250 | BOOST_AUTO_TEST_CASE(RemovePendingInterest) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 251 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 252 | const PendingInterestId* interestId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 253 | face.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 254 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 255 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 256 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 257 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 258 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 259 | face.removePendingInterest(interestId); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 260 | advanceClocks(time::milliseconds(10)); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 261 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 262 | face.receive(*makeData("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 263 | advanceClocks(time::milliseconds(200), 5); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 264 | } |
| 265 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 266 | BOOST_AUTO_TEST_CASE(RemoveAllPendingInterests) |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 267 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 268 | face.expressInterest(Interest("/Hello/World/0", time::milliseconds(50)), |
| 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 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 273 | face.expressInterest(Interest("/Hello/World/1", time::milliseconds(50)), |
| 274 | bind([] { BOOST_FAIL("Unexpected data"); }), |
| 275 | bind([] { BOOST_FAIL("Unexpected nack"); }), |
| 276 | bind([] { BOOST_FAIL("Unexpected timeout"); })); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 277 | |
| 278 | advanceClocks(time::milliseconds(10)); |
| 279 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 280 | face.removeAllPendingInterests(); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 281 | advanceClocks(time::milliseconds(10)); |
| 282 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 283 | BOOST_CHECK_EQUAL(face.getNPendingInterests(), 0); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 284 | |
Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame] | 285 | face.receive(*makeData("/Hello/World/0")); |
| 286 | face.receive(*makeData("/Hello/World/1")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 287 | advanceClocks(time::milliseconds(200), 5); |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 288 | } |
| 289 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 290 | BOOST_AUTO_TEST_CASE(DestructionWithoutCancellingPendingInterests) // Bug #2518 |
| 291 | { |
| 292 | { |
| 293 | DummyClientFace face2(io, m_keyChain); |
| 294 | face2.expressInterest(Interest("/Hello/World", time::milliseconds(50)), |
| 295 | bind([]{}), bind([]{})); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 296 | advanceClocks(time::milliseconds(50), 2); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 299 | advanceClocks(time::milliseconds(50), 2); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 300 | // should not segfault |
| 301 | } |
| 302 | |
| 303 | BOOST_AUTO_TEST_SUITE_END() // Consumer |
| 304 | |
| 305 | BOOST_AUTO_TEST_SUITE(Producer) |
| 306 | |
| 307 | BOOST_AUTO_TEST_CASE(PutNack) |
| 308 | { |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 309 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 0); |
| 310 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 311 | face.put(makeNack(Interest("/Hello/World", time::milliseconds(50)), lp::NackReason::NO_ROUTE)); |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 312 | advanceClocks(time::milliseconds(10)); |
| 313 | |
| 314 | BOOST_CHECK_EQUAL(face.sentNacks.size(), 1); |
| 315 | } |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 316 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 317 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilter) |
| 318 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 319 | size_t nInterests = 0; |
| 320 | size_t nRegs = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 321 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 322 | face.setInterestFilter("/Hello/World", |
| 323 | bind([&nInterests] { ++nInterests; }), |
| 324 | bind([&nRegs] { ++nRegs; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 325 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 326 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 327 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 328 | BOOST_CHECK_EQUAL(nInterests, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 329 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 330 | face.receive(Interest("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 331 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 332 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 333 | BOOST_CHECK_EQUAL(nRegs, 1); |
| 334 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 335 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 336 | face.receive(Interest("/Bye/World/%21")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 337 | advanceClocks(time::milliseconds(10000), 10); |
| 338 | BOOST_CHECK_EQUAL(nInterests, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 339 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 340 | face.receive(Interest("/Hello/World/%21/2")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 341 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 342 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 343 | |
| 344 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 345 | face.unsetInterestFilter(regPrefixId); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 346 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 347 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 348 | face.receive(Interest("/Hello/World/%21/3")); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 349 | BOOST_CHECK_EQUAL(nInterests, 2); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 350 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 351 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 352 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 353 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 354 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 355 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 356 | } |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 357 | |
Junxiao Shi | 76e0eb2 | 2016-08-08 05:54:10 +0000 | [diff] [blame] | 358 | BOOST_AUTO_TEST_CASE(SetInterestFilterEmptyInterestCallback) |
| 359 | { |
| 360 | face.setInterestFilter("/A", nullptr); |
| 361 | advanceClocks(time::milliseconds(1)); |
| 362 | |
| 363 | BOOST_CHECK_NO_THROW(do { |
| 364 | face.receive(*makeInterest("/A/1")); |
| 365 | advanceClocks(time::milliseconds(1)); |
| 366 | } while (false)); |
| 367 | } |
| 368 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 369 | BOOST_AUTO_TEST_CASE(SetUnsetInterestFilterWithoutSucessCallback) |
| 370 | { |
| 371 | size_t nInterests = 0; |
| 372 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 373 | face.setInterestFilter("/Hello/World", |
| 374 | bind([&nInterests] { ++nInterests; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 375 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 376 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 377 | BOOST_CHECK_EQUAL(nInterests, 0); |
| 378 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 379 | face.receive(Interest("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 380 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 381 | |
| 382 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 383 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 384 | face.receive(Interest("/Bye/World/%21")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 385 | advanceClocks(time::milliseconds(10000), 10); |
| 386 | BOOST_CHECK_EQUAL(nInterests, 1); |
| 387 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 388 | face.receive(Interest("/Hello/World/%21/2")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 389 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 391 | |
| 392 | // removing filter |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 393 | face.unsetInterestFilter(regPrefixId); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 394 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 395 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 396 | face.receive(Interest("/Hello/World/%21/3")); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 397 | BOOST_CHECK_EQUAL(nInterests, 2); |
| 398 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 399 | face.unsetInterestFilter(static_cast<const RegisteredPrefixId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 400 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 401 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 402 | face.unsetInterestFilter(static_cast<const InterestFilterId*>(nullptr)); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 403 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 404 | } |
| 405 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 406 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFail, FacesNoRegistrationReplyFixture) |
| 407 | { |
| 408 | // don't enable registration reply |
| 409 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 410 | face.setInterestFilter("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 411 | bind([] { BOOST_FAIL("Unexpected Interest"); }), |
| 412 | bind([] { BOOST_FAIL("Unexpected success of setInterestFilter"); }), |
| 413 | bind([&nRegFailed] { ++nRegFailed; })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 414 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 415 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 416 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 417 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 418 | advanceClocks(time::milliseconds(2000), 5); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 419 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 420 | } |
| 421 | |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 422 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterFailWithoutSuccessCallback, FacesNoRegistrationReplyFixture) |
| 423 | { |
| 424 | // don't enable registration reply |
| 425 | size_t nRegFailed = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 426 | face.setInterestFilter("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 427 | bind([] { BOOST_FAIL("Unexpected Interest"); }), |
| 428 | bind([&nRegFailed] { ++nRegFailed; })); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 429 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 430 | advanceClocks(time::milliseconds(25), 4); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 431 | BOOST_CHECK_EQUAL(nRegFailed, 0); |
| 432 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 433 | advanceClocks(time::milliseconds(2000), 5); |
Joao Pereira | 0b3cac5 | 2015-07-02 14:49:49 -0400 | [diff] [blame] | 434 | BOOST_CHECK_EQUAL(nRegFailed, 1); |
| 435 | } |
| 436 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 437 | BOOST_AUTO_TEST_CASE(RegisterUnregisterPrefix) |
| 438 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 439 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 440 | const RegisteredPrefixId* regPrefixId = |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 441 | face.registerPrefix("/Hello/World", |
| 442 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 443 | bind([] { BOOST_FAIL("Unexpected registerPrefix failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 444 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 445 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 446 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 447 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 448 | size_t nUnregSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 449 | face.unregisterPrefix(regPrefixId, |
| 450 | bind([&nUnregSuccesses] { ++nUnregSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 451 | bind([] { BOOST_FAIL("Unexpected unregisterPrefix failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 452 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 453 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 454 | BOOST_CHECK_EQUAL(nUnregSuccesses, 1); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 457 | BOOST_FIXTURE_TEST_CASE(RegisterUnregisterPrefixFail, FacesNoRegistrationReplyFixture) |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 458 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 459 | size_t nRegFailures = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 460 | face.registerPrefix("/Hello/World", |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 461 | bind([] { BOOST_FAIL("Unexpected registerPrefix success"); }), |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 462 | bind([&nRegFailures] { ++nRegFailures; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 463 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 464 | advanceClocks(time::milliseconds(5000), 20); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 465 | BOOST_CHECK_EQUAL(nRegFailures, 1); |
| 466 | } |
| 467 | |
| 468 | BOOST_AUTO_TEST_CASE(SimilarFilters) |
| 469 | { |
| 470 | size_t nInInterests1 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 471 | face.setInterestFilter("/Hello/World", |
| 472 | bind([&nInInterests1] { ++nInInterests1; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 473 | nullptr, |
| 474 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 475 | |
| 476 | size_t nInInterests2 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 477 | face.setInterestFilter("/Hello", |
| 478 | bind([&nInInterests2] { ++nInInterests2; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 479 | nullptr, |
| 480 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 481 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 482 | size_t nInInterests3 = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 483 | face.setInterestFilter("/Los/Angeles/Lakers", |
| 484 | bind([&nInInterests3] { ++nInInterests3; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 485 | nullptr, |
| 486 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 487 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 488 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 489 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 490 | face.receive(Interest("/Hello/World/%21")); |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 491 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 492 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 493 | BOOST_CHECK_EQUAL(nInInterests1, 1); |
| 494 | BOOST_CHECK_EQUAL(nInInterests2, 1); |
| 495 | BOOST_CHECK_EQUAL(nInInterests3, 0); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | BOOST_AUTO_TEST_CASE(SetRegexFilterError) |
| 499 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 500 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 501 | [] (const Name&, const Interest&) { |
| 502 | BOOST_FAIL("InterestFilter::Error should have been triggered"); |
| 503 | }, |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 504 | nullptr, |
| 505 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 506 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 507 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 508 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 509 | 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] | 510 | } |
| 511 | |
| 512 | BOOST_AUTO_TEST_CASE(SetRegexFilter) |
| 513 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 514 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 515 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 516 | bind([&nInInterests] { ++nInInterests; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 517 | nullptr, |
| 518 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 519 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 520 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 521 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 522 | face.receive(Interest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 523 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 524 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 525 | face.receive(Interest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 526 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 527 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 528 | face.receive(Interest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 529 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 530 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 531 | face.receive(Interest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 532 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 533 | } |
| 534 | |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 535 | BOOST_AUTO_TEST_CASE(SetRegexFilterAndRegister) |
| 536 | { |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 537 | size_t nInInterests = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 538 | face.setInterestFilter(InterestFilter("/Hello/World", "<><b><c>?"), |
| 539 | bind([&nInInterests] { ++nInInterests; })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 540 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 541 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 542 | face.registerPrefix("/Hello/World", |
| 543 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 544 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 545 | |
Junxiao Shi | f5b5ae2 | 2016-08-08 05:54:41 +0000 | [diff] [blame^] | 546 | advanceClocks(time::milliseconds(25), 4); |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 547 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 548 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 549 | face.receive(Interest("/Hello/World/a")); // shouldn't match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 550 | BOOST_CHECK_EQUAL(nInInterests, 0); |
| 551 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 552 | face.receive(Interest("/Hello/World/a/b")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 553 | BOOST_CHECK_EQUAL(nInInterests, 1); |
| 554 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 555 | face.receive(Interest("/Hello/World/a/b/c")); // should match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 556 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 557 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 558 | face.receive(Interest("/Hello/World/a/b/d")); // should not match |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 559 | BOOST_CHECK_EQUAL(nInInterests, 2); |
| 560 | } |
| 561 | |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 562 | BOOST_FIXTURE_TEST_CASE(SetInterestFilterNoReg, FacesNoRegistrationReplyFixture) // Bug 2318 |
| 563 | { |
| 564 | // This behavior is specific to DummyClientFace. |
| 565 | // Regular Face won't accept incoming packets until something is sent. |
| 566 | |
| 567 | int hit = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 568 | face.setInterestFilter(Name("/"), bind([&hit] { ++hit; })); |
| 569 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 570 | |
| 571 | auto interest = make_shared<Interest>("/A"); |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 572 | face.receive(*interest); |
| 573 | face.processEvents(time::milliseconds(-1)); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 574 | |
| 575 | BOOST_CHECK_EQUAL(hit, 1); |
| 576 | } |
| 577 | |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 578 | BOOST_AUTO_TEST_SUITE_END() // Producer |
| 579 | |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 580 | BOOST_AUTO_TEST_CASE(ProcessEvents) |
| 581 | { |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 582 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 583 | |
Alexander Afanasyev | d3a55b2 | 2014-11-18 19:23:28 -0800 | [diff] [blame] | 584 | size_t nRegSuccesses = 0; |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 585 | face.registerPrefix("/Hello/World", |
| 586 | bind([&nRegSuccesses] { ++nRegSuccesses; }), |
Junxiao Shi | 103d8ed | 2016-08-07 20:34:10 +0000 | [diff] [blame] | 587 | bind([] { BOOST_FAIL("Unexpected setInterestFilter failure"); })); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 588 | |
| 589 | // io_service::poll() without reset |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 590 | face.getIoService().poll(); |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 591 | BOOST_CHECK_EQUAL(nRegSuccesses, 0); |
| 592 | |
Alexander Afanasyev | 9bdbb83 | 2015-12-30 12:54:22 -0800 | [diff] [blame] | 593 | face.processEvents(time::milliseconds(-1)); // io_service::reset()/poll() inside |
Alexander Afanasyev | 8e15854 | 2014-11-18 00:47:18 -0500 | [diff] [blame] | 594 | BOOST_CHECK_EQUAL(nRegSuccesses, 1); |
| 595 | } |
| 596 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 597 | struct PibDirWithDefaultTpm |
| 598 | { |
| 599 | const std::string PATH = "build/keys-with-default-tpm"; |
| 600 | }; |
| 601 | |
| 602 | BOOST_FIXTURE_TEST_CASE(FaceTransport, PibDirFixture<PibDirWithDefaultTpm>) |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 603 | { |
| 604 | KeyChain keyChain; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 605 | boost::asio::io_service io; |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 606 | |
| 607 | BOOST_CHECK(Face().getTransport() != nullptr); |
| 608 | |
Alexander Afanasyev | bb64c17 | 2015-12-29 20:32:45 -0800 | [diff] [blame] | 609 | BOOST_CHECK(Face(shared_ptr<Transport>()).getTransport() != nullptr); |
| 610 | BOOST_CHECK(Face(shared_ptr<Transport>(), io).getTransport() != nullptr); |
| 611 | BOOST_CHECK(Face(shared_ptr<Transport>(), io, keyChain).getTransport() != nullptr); |
Alexander Afanasyev | 3a6da36 | 2015-12-29 20:31:03 -0800 | [diff] [blame] | 612 | |
| 613 | auto transport = make_shared<TcpTransport>("localhost", "6363"); // no real io operations will be scheduled |
| 614 | BOOST_CHECK(Face(transport).getTransport() == transport); |
| 615 | BOOST_CHECK(Face(transport, io).getTransport() == transport); |
| 616 | BOOST_CHECK(Face(transport, io, keyChain).getTransport() == transport); |
| 617 | } |
| 618 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 619 | BOOST_AUTO_TEST_SUITE(CustomizeTransport) |
| 620 | |
| 621 | class WithEnv : private IdentityManagementTimeFixture |
| 622 | { |
| 623 | public: |
| 624 | WithEnv() |
| 625 | { |
| 626 | if (getenv("NDN_CLIENT_TRANSPORT") != nullptr) { |
| 627 | m_oldTransport = getenv("NDN_CLIENT_TRANSPORT"); |
| 628 | unsetenv("NDN_CLIENT_TRANSPORT"); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | void |
| 633 | configure(const std::string& faceUri) |
| 634 | { |
| 635 | setenv("NDN_CLIENT_TRANSPORT", faceUri.c_str(), true); |
| 636 | } |
| 637 | |
| 638 | ~WithEnv() |
| 639 | { |
| 640 | if (!m_oldTransport.empty()) { |
| 641 | setenv("NDN_CLIENT_TRANSPORT", m_oldTransport.c_str(), true); |
| 642 | } |
| 643 | else { |
| 644 | unsetenv("NDN_CLIENT_TRANSPORT"); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | private: |
| 649 | std::string m_oldTransport; |
| 650 | }; |
| 651 | |
| 652 | class WithConfig : private TestHomeFixture<DefaultPibDir> |
| 653 | { |
| 654 | public: |
| 655 | void |
| 656 | configure(const std::string& faceUri) |
| 657 | { |
| 658 | createClientConf({"transport=" + faceUri}); |
| 659 | } |
| 660 | }; |
| 661 | |
| 662 | class WithEnvAndConfig : public WithEnv, public WithConfig |
| 663 | { |
| 664 | }; |
| 665 | |
| 666 | typedef boost::mpl::vector<WithEnv, WithConfig> ConfigOptions; |
| 667 | |
| 668 | 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] | 669 | { |
| 670 | shared_ptr<Face> face; |
| 671 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 672 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 675 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Unix, T, ConfigOptions, T) |
| 676 | { |
| 677 | this->configure("unix://some/path"); |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 678 | |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame] | 679 | shared_ptr<Face> face; |
| 680 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 681 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
| 682 | } |
| 683 | |
| 684 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(Tcp, T, ConfigOptions, T) |
| 685 | { |
| 686 | this->configure("tcp://127.0.0.1:6000"); |
| 687 | |
| 688 | shared_ptr<Face> face; |
| 689 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 690 | BOOST_CHECK(dynamic_pointer_cast<TcpTransport>(face->getTransport()) != nullptr); |
| 691 | } |
| 692 | |
| 693 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongTransport, T, ConfigOptions, T) |
| 694 | { |
| 695 | this->configure("wrong-transport:"); |
| 696 | |
| 697 | BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error); |
| 698 | } |
| 699 | |
| 700 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(WrongUri, T, ConfigOptions, T) |
| 701 | { |
| 702 | this->configure("wrong-uri"); |
| 703 | |
| 704 | BOOST_CHECK_THROW(make_shared<Face>(), ConfigFile::Error); |
| 705 | } |
| 706 | |
| 707 | BOOST_FIXTURE_TEST_CASE(EnvOverride, WithEnvAndConfig) |
| 708 | { |
| 709 | this->WithEnv::configure("tcp://127.0.0.1:6000"); |
| 710 | this->WithConfig::configure("unix://some/path"); |
| 711 | |
| 712 | shared_ptr<Face> face; |
| 713 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>()); |
| 714 | BOOST_CHECK(dynamic_pointer_cast<TcpTransport>(face->getTransport()) != nullptr); |
| 715 | } |
| 716 | |
| 717 | BOOST_FIXTURE_TEST_CASE(ExplicitTransport, WithEnvAndConfig) |
| 718 | { |
| 719 | this->WithEnv::configure("wrong-uri"); |
| 720 | this->WithConfig::configure("wrong-transport:"); |
| 721 | |
| 722 | auto transport = make_shared<UnixTransport>("unix://some/path"); |
| 723 | shared_ptr<Face> face; |
| 724 | BOOST_REQUIRE_NO_THROW(face = make_shared<Face>(transport)); |
| 725 | BOOST_CHECK(dynamic_pointer_cast<UnixTransport>(face->getTransport()) != nullptr); |
| 726 | } |
| 727 | |
| 728 | BOOST_AUTO_TEST_SUITE_END() // CustomizeTransport |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 729 | BOOST_AUTO_TEST_SUITE_END() // TestFace |
| 730 | |
| 731 | } // namespace tests |
Alexander Afanasyev | 5fc795f | 2014-10-20 23:06:56 -0400 | [diff] [blame] | 732 | } // namespace ndn |