Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 4 | * 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 Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 30 | #include "face/face.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 31 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 32 | #include "tests/test-common.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 33 | #include "tests/daemon/limited-io.hpp" |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 34 | |
| 35 | #include <type_traits> |
| 36 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | namespace nfd::tests { |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 38 | |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 39 | template<class ChannelT, class EndpointT> |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 40 | class ChannelFixture : public GlobalIoFixture |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 41 | { |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 42 | static_assert(std::is_base_of_v<face::Channel, ChannelT>); |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 43 | |
| 44 | public: |
| 45 | virtual |
| 46 | ~ChannelFixture() = default; |
| 47 | |
| 48 | static void |
| 49 | unexpectedFailure(uint32_t status, const std::string& reason) |
| 50 | { |
| 51 | BOOST_FAIL("No error expected, but got: [" << status << ": " << reason << "]"); |
| 52 | } |
| 53 | |
| 54 | protected: |
| 55 | uint16_t |
| 56 | getNextPort() |
| 57 | { |
| 58 | return m_nextPort++; |
| 59 | } |
| 60 | |
Alexander Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 61 | virtual shared_ptr<ChannelT> |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 62 | makeChannel() |
| 63 | { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 64 | BOOST_FAIL("Unimplemented"); |
| 65 | return nullptr; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Alexander Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 68 | virtual shared_ptr<ChannelT> |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 69 | makeChannel(const boost::asio::ip::address&, uint16_t port = 0, |
| 70 | std::optional<size_t> mtu = std::nullopt) |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 71 | { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 72 | BOOST_FAIL("Unimplemented"); |
| 73 | return nullptr; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 77 | listen(const boost::asio::ip::address& addr, std::optional<size_t> mtu = std::nullopt) |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 78 | { |
| 79 | listenerEp = EndpointT{addr, 7030}; |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame] | 80 | listenerChannel = makeChannel(addr, 7030, mtu); |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 81 | listenerChannel->listen( |
| 82 | [this] (const shared_ptr<Face>& newFace) { |
| 83 | BOOST_REQUIRE(newFace != nullptr); |
| 84 | connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); }); |
| 85 | listenerFaces.push_back(newFace); |
| 86 | limitedIo.afterOp(); |
| 87 | }, |
| 88 | ChannelFixture::unexpectedFailure); |
| 89 | } |
| 90 | |
| 91 | virtual void |
| 92 | connect(ChannelT&) |
| 93 | { |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 94 | BOOST_FAIL("Unimplemented"); |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | protected: |
| 98 | LimitedIo limitedIo; |
| 99 | EndpointT listenerEp; |
Alexander Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 100 | shared_ptr<ChannelT> listenerChannel; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 101 | std::vector<shared_ptr<Face>> listenerFaces; |
| 102 | |
| 103 | private: |
| 104 | uint16_t m_nextPort = 7050; |
| 105 | }; |
| 106 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 107 | } // namespace nfd::tests |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 108 | |
| 109 | #endif // NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP |