blob: 5c573418757bf3377aa61f53e5596f28434308be [file] [log] [blame]
Yanbiao Li4ee73d42015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento1d12d2f2019-03-22 12:44:14 -04002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Yanbiao Li4ee73d42015-08-19 16:30:16 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "face/internal-face.hpp"
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070027
Junxiao Shicde37ad2015-12-24 01:02:05 -070028#include "transport-test-common.hpp"
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040029#include "tests/key-chain-fixture.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040030#include "tests/daemon/global-io-fixture.hpp"
Yanbiao Li4ee73d42015-08-19 16:30:16 -070031
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040032namespace nfd::tests {
Yanbiao Li4ee73d42015-08-19 16:30:16 -070033
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040034using namespace nfd::face;
Junxiao Shi6535f1e2015-10-08 13:02:18 -070035
36BOOST_AUTO_TEST_SUITE(Face)
37
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038class InternalFaceFixture : public GlobalIoTimeFixture, public KeyChainFixture
Yanbiao Li4ee73d42015-08-19 16:30:16 -070039{
40public:
41 InternalFaceFixture()
42 {
Davide Pesavento284bd622019-03-31 02:10:02 -040043 std::tie(forwarderFace, clientFace) = makeInternalFace(m_keyChain);
Junxiao Shi6535f1e2015-10-08 13:02:18 -070044
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070045 forwarderFace->afterReceiveInterest.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000046 [this] (const Interest& interest, const EndpointId&) { receivedInterests.push_back(interest); } );
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070047 forwarderFace->afterReceiveData.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000048 [this] (const Data& data, const EndpointId&) { receivedData.push_back(data); } );
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070049 forwarderFace->afterReceiveNack.connect(
ashiqopu075bb7d2019-03-10 01:38:21 +000050 [this] (const lp::Nack& nack, const EndpointId&) { receivedNacks.push_back(nack); } );
Yanbiao Li4ee73d42015-08-19 16:30:16 -070051 }
52
53protected:
Junxiao Shicde37ad2015-12-24 01:02:05 -070054 shared_ptr<nfd::Face> forwarderFace;
Junxiao Shi6535f1e2015-10-08 13:02:18 -070055 shared_ptr<ndn::Face> clientFace;
56
57 std::vector<Interest> receivedInterests;
58 std::vector<Data> receivedData;
59 std::vector<lp::Nack> receivedNacks;
Yanbiao Li4ee73d42015-08-19 16:30:16 -070060};
61
Junxiao Shi6535f1e2015-10-08 13:02:18 -070062BOOST_FIXTURE_TEST_SUITE(TestInternalFace, InternalFaceFixture)
Yanbiao Li4ee73d42015-08-19 16:30:16 -070063
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070064BOOST_AUTO_TEST_CASE(TransportStaticProperties)
65{
66 Transport* transport = forwarderFace->getTransport();
67 checkStaticPropertiesInitialized(*transport);
68
69 BOOST_CHECK_EQUAL(transport->getLocalUri(), FaceUri("internal://"));
70 BOOST_CHECK_EQUAL(transport->getRemoteUri(), FaceUri("internal://"));
71 BOOST_CHECK_EQUAL(transport->getScope(), ndn::nfd::FACE_SCOPE_LOCAL);
72 BOOST_CHECK_EQUAL(transport->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
73 BOOST_CHECK_EQUAL(transport->getLinkType(), ndn::nfd::LINK_TYPE_POINT_TO_POINT);
74 BOOST_CHECK_EQUAL(transport->getMtu(), MTU_UNLIMITED);
75}
76
Junxiao Shi6535f1e2015-10-08 13:02:18 -070077// note: "send" and "receive" in test case names refer to the direction seen on forwarderFace.
78// i.e. "send" means transmission from forwarder to client,
Junxiao Shi5b8a2b22015-10-22 17:20:44 -070079// "receive" means transmission from client to forwarder.
Junxiao Shi6535f1e2015-10-08 13:02:18 -070080
81BOOST_AUTO_TEST_CASE(ReceiveInterestTimeout)
Yanbiao Li4ee73d42015-08-19 16:30:16 -070082{
Davide Pesavento284bd622019-03-31 02:10:02 -040083 auto interest = makeInterest("/TLETccRv");
Davide Pesavento14e71f02019-03-28 17:35:25 -040084 interest->setInterestLifetime(100_ms);
Yanbiao Li4ee73d42015-08-19 16:30:16 -070085
Junxiao Shi6535f1e2015-10-08 13:02:18 -070086 bool hasTimeout = false;
87 clientFace->expressInterest(*interest,
Davide Pesavento412c9822021-07-02 00:21:05 -040088 [] (auto&&...) { BOOST_ERROR("unexpected Data"); },
89 [] (auto&&...) { BOOST_ERROR("unexpected Nack"); },
90 [&] (auto&&...) { hasTimeout = true; });
Davide Pesavento14e71f02019-03-28 17:35:25 -040091 this->advanceClocks(1_ms, 10);
Yanbiao Li4ee73d42015-08-19 16:30:16 -070092
Junxiao Shi6535f1e2015-10-08 13:02:18 -070093 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
94 BOOST_CHECK_EQUAL(receivedInterests.back().getName(), "/TLETccRv");
95
Davide Pesavento14e71f02019-03-28 17:35:25 -040096 this->advanceClocks(1_ms, 100);
Junxiao Shi6535f1e2015-10-08 13:02:18 -070097
98 BOOST_CHECK(hasTimeout);
Yanbiao Li4ee73d42015-08-19 16:30:16 -070099}
100
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700101BOOST_AUTO_TEST_CASE(ReceiveInterestSendData)
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700102{
Junxiao Shi9d727852019-05-14 13:44:22 -0600103 auto interest = makeInterest("/PQstEJGdL", true);
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700104
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700105 bool hasReceivedData = false;
106 clientFace->expressInterest(*interest,
Davide Pesavento412c9822021-07-02 00:21:05 -0400107 [&] (const Interest&, const Data& data) {
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700108 hasReceivedData = true;
109 BOOST_CHECK_EQUAL(data.getName(), "/PQstEJGdL/aI7oCrDXNX");
110 },
Davide Pesavento412c9822021-07-02 00:21:05 -0400111 [] (auto&&...) { BOOST_ERROR("unexpected Nack"); },
112 [] (auto&&...) { BOOST_ERROR("unexpected timeout"); });
Davide Pesavento14e71f02019-03-28 17:35:25 -0400113 this->advanceClocks(1_ms, 10);
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700114
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700115 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
116 BOOST_CHECK_EQUAL(receivedInterests.back().getName(), "/PQstEJGdL");
117
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700118 forwarderFace->sendData(*makeData("/PQstEJGdL/aI7oCrDXNX"));
Davide Pesavento14e71f02019-03-28 17:35:25 -0400119 this->advanceClocks(1_ms, 10);
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700120
121 BOOST_CHECK(hasReceivedData);
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700122}
123
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700124BOOST_AUTO_TEST_CASE(ReceiveInterestSendNack)
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700125{
Junxiao Shi9d727852019-05-14 13:44:22 -0600126 auto interest = makeInterest("/1HrsRM1X");
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700127
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700128 bool hasReceivedNack = false;
129 clientFace->expressInterest(*interest,
Davide Pesavento412c9822021-07-02 00:21:05 -0400130 [] (auto&&...) { BOOST_ERROR("unexpected Data"); },
131 [&] (const Interest&, const lp::Nack& nack) {
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700132 hasReceivedNack = true;
133 BOOST_CHECK_EQUAL(nack.getReason(), lp::NackReason::NO_ROUTE);
134 },
Davide Pesavento412c9822021-07-02 00:21:05 -0400135 [] (auto&&...) { BOOST_ERROR("unexpected timeout"); });
Davide Pesavento14e71f02019-03-28 17:35:25 -0400136 this->advanceClocks(1_ms, 10);
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700137
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700138 BOOST_REQUIRE_EQUAL(receivedInterests.size(), 1);
139 BOOST_CHECK_EQUAL(receivedInterests.back().getName(), "/1HrsRM1X");
140
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700141 forwarderFace->sendNack(makeNack(*interest, lp::NackReason::NO_ROUTE));
Davide Pesavento14e71f02019-03-28 17:35:25 -0400142 this->advanceClocks(1_ms, 10);
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700143
144 BOOST_CHECK(hasReceivedNack);
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700145}
146
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700147BOOST_AUTO_TEST_CASE(SendInterestReceiveData)
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700148{
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700149 bool hasDeliveredInterest = false;
150 clientFace->setInterestFilter("/Wpc8TnEeoF",
151 [this, &hasDeliveredInterest] (const ndn::InterestFilter&, const Interest& interest) {
152 hasDeliveredInterest = true;
153 BOOST_CHECK_EQUAL(interest.getName(), "/Wpc8TnEeoF/f6SzV8hD");
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700154
Davide Pesavento284bd622019-03-31 02:10:02 -0400155 clientFace->put(*makeData("/Wpc8TnEeoF/f6SzV8hD/3uytUJCuIi"));
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700156 });
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700157
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700158 forwarderFace->sendInterest(*makeInterest("/Wpc8TnEeoF/f6SzV8hD", true));
Davide Pesavento14e71f02019-03-28 17:35:25 -0400159 this->advanceClocks(1_ms, 10);
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700160
161 BOOST_CHECK(hasDeliveredInterest);
162 BOOST_REQUIRE_EQUAL(receivedData.size(), 1);
163 BOOST_CHECK_EQUAL(receivedData.back().getName(), "/Wpc8TnEeoF/f6SzV8hD/3uytUJCuIi");
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700164}
165
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700166BOOST_AUTO_TEST_CASE(SendInterestReceiveNack)
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700167{
Junxiao Shi9d727852019-05-14 13:44:22 -0600168 auto interest = makeInterest("/4YgJKWcXN/5oaTe05o");
169
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700170 bool hasDeliveredInterest = false;
171 clientFace->setInterestFilter("/4YgJKWcXN",
172 [this, &hasDeliveredInterest] (const ndn::InterestFilter&, const Interest& interest) {
173 hasDeliveredInterest = true;
174 BOOST_CHECK_EQUAL(interest.getName(), "/4YgJKWcXN/5oaTe05o");
Junxiao Shi9d727852019-05-14 13:44:22 -0600175 clientFace->put(makeNack(interest, lp::NackReason::NO_ROUTE));
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700176 });
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700177
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700178 forwarderFace->sendInterest(*interest);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400179 this->advanceClocks(1_ms, 10);
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700180
181 BOOST_CHECK(hasDeliveredInterest);
182 BOOST_REQUIRE_EQUAL(receivedNacks.size(), 1);
183 BOOST_CHECK_EQUAL(receivedNacks.back().getReason(), lp::NackReason::NO_ROUTE);
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700184}
185
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700186BOOST_AUTO_TEST_CASE(CloseForwarderFace)
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700187{
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700188 forwarderFace->close();
Davide Pesavento14e71f02019-03-28 17:35:25 -0400189 this->advanceClocks(1_ms, 10);
Junxiao Shi5b8a2b22015-10-22 17:20:44 -0700190 BOOST_CHECK_EQUAL(forwarderFace->getState(), FaceState::CLOSED);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700191 forwarderFace.reset();
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700192
Davide Pesavento284bd622019-03-31 02:10:02 -0400193 auto interest = makeInterest("/zpHsVesu0B");
Davide Pesavento14e71f02019-03-28 17:35:25 -0400194 interest->setInterestLifetime(100_ms);
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700195
196 bool hasTimeout = false;
197 clientFace->expressInterest(*interest,
Davide Pesavento412c9822021-07-02 00:21:05 -0400198 [] (auto&&...) { BOOST_ERROR("unexpected Data"); },
199 [] (auto&&...) { BOOST_ERROR("unexpected Nack"); },
200 [&] (auto&&...) { hasTimeout = true; });
Davide Pesavento14e71f02019-03-28 17:35:25 -0400201 BOOST_CHECK_NO_THROW(this->advanceClocks(1_ms, 200));
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700202
203 BOOST_CHECK_EQUAL(receivedInterests.size(), 0);
204 BOOST_CHECK(hasTimeout);
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700205}
206
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700207BOOST_AUTO_TEST_CASE(CloseClientFace)
208{
209 g_io.poll(); // #3248 workaround
210 clientFace.reset();
211
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700212 forwarderFace->sendInterest(*makeInterest("/aau42XQqb"));
Davide Pesavento14e71f02019-03-28 17:35:25 -0400213 BOOST_CHECK_NO_THROW(this->advanceClocks(1_ms, 10));
Junxiao Shi6535f1e2015-10-08 13:02:18 -0700214}
215
216BOOST_AUTO_TEST_SUITE_END() // TestInternalFace
217BOOST_AUTO_TEST_SUITE_END() // Face
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700218
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400219} // namespace nfd::tests