blob: c3d07c6b0f8668bd2ca84f76df0e7e4d3764d775 [file] [log] [blame]
Davide Pesavento9a00fab2016-09-27 11:22:46 +02001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento19779d82019-02-14 13:40:04 -05002/*
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Davide Pesavento9a00fab2016-09-27 11:22:46 +02004 * 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#ifndef NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP
27#define NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP
28
29#include "face/channel.hpp"
Davide Pesaventocb425e82019-07-14 21:48:22 -040030#include "face/face.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060031
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040032#include "tests/test-common.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060033#include "tests/daemon/limited-io.hpp"
Davide Pesavento9a00fab2016-09-27 11:22:46 +020034
35#include <type_traits>
36
37namespace nfd {
Davide Pesavento8fd15e62017-04-06 19:58:54 -040038namespace face {
Davide Pesavento9a00fab2016-09-27 11:22:46 +020039namespace tests {
40
Davide Pesavento8fd15e62017-04-06 19:58:54 -040041using namespace nfd::tests;
42
Davide Pesavento9a00fab2016-09-27 11:22:46 +020043template<class ChannelT, class EndpointT>
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040044class ChannelFixture : public GlobalIoFixture
Davide Pesavento9a00fab2016-09-27 11:22:46 +020045{
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040046 static_assert(std::is_base_of_v<Channel, ChannelT>);
Davide Pesavento9a00fab2016-09-27 11:22:46 +020047
48public:
49 virtual
50 ~ChannelFixture() = default;
51
52 static void
53 unexpectedFailure(uint32_t status, const std::string& reason)
54 {
55 BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]");
56 }
57
58protected:
59 uint16_t
60 getNextPort()
61 {
62 return m_nextPort++;
63 }
64
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -040065 virtual shared_ptr<ChannelT>
Davide Pesavento9a00fab2016-09-27 11:22:46 +020066 makeChannel()
67 {
Davide Pesavento19779d82019-02-14 13:40:04 -050068 BOOST_FAIL("Unimplemented");
69 return nullptr;
Davide Pesavento9a00fab2016-09-27 11:22:46 +020070 }
71
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -040072 virtual shared_ptr<ChannelT>
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040073 makeChannel(const boost::asio::ip::address&, uint16_t port = 0,
74 std::optional<size_t> mtu = std::nullopt)
Davide Pesavento9a00fab2016-09-27 11:22:46 +020075 {
Davide Pesavento19779d82019-02-14 13:40:04 -050076 BOOST_FAIL("Unimplemented");
77 return nullptr;
Davide Pesavento9a00fab2016-09-27 11:22:46 +020078 }
79
80 void
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040081 listen(const boost::asio::ip::address& addr, std::optional<size_t> mtu = std::nullopt)
Davide Pesavento9a00fab2016-09-27 11:22:46 +020082 {
83 listenerEp = EndpointT{addr, 7030};
Junxiao Shia6286a92021-02-23 06:43:52 -070084 listenerChannel = makeChannel(addr, 7030, mtu);
Davide Pesavento9a00fab2016-09-27 11:22:46 +020085 listenerChannel->listen(
86 [this] (const shared_ptr<Face>& newFace) {
87 BOOST_REQUIRE(newFace != nullptr);
88 connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); });
89 listenerFaces.push_back(newFace);
90 limitedIo.afterOp();
91 },
92 ChannelFixture::unexpectedFailure);
93 }
94
95 virtual void
96 connect(ChannelT&)
97 {
Davide Pesavento19779d82019-02-14 13:40:04 -050098 BOOST_FAIL("Unimplemented");
Davide Pesavento9a00fab2016-09-27 11:22:46 +020099 }
100
101protected:
102 LimitedIo limitedIo;
103 EndpointT listenerEp;
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400104 shared_ptr<ChannelT> listenerChannel;
Davide Pesavento9a00fab2016-09-27 11:22:46 +0200105 std::vector<shared_ptr<Face>> listenerFaces;
106
107private:
108 uint16_t m_nextPort = 7050;
109};
110
111} // namespace tests
Davide Pesavento8fd15e62017-04-06 19:58:54 -0400112} // namespace face
Davide Pesavento9a00fab2016-09-27 11:22:46 +0200113} // namespace nfd
114
115#endif // NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP