Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [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_UDP_CHANNEL_FIXTURE_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_UDP_CHANNEL_FIXTURE_HPP |
| 28 | |
| 29 | #include "face/udp-channel.hpp" |
| 30 | #include "face/transport.hpp" |
| 31 | |
| 32 | #include "channel-fixture.hpp" |
| 33 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 34 | namespace nfd::tests { |
| 35 | |
| 36 | using face::UdpChannel; |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 37 | |
| 38 | class UdpChannelFixture : public ChannelFixture<UdpChannel, udp::Endpoint> |
| 39 | { |
| 40 | protected: |
Alexander Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 41 | shared_ptr<UdpChannel> |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 42 | makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0, |
| 43 | std::optional<size_t> mtu = std::nullopt) final |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 44 | { |
| 45 | if (port == 0) |
| 46 | port = getNextPort(); |
| 47 | |
Davide Pesavento | b7bfcb9 | 2022-05-22 23:55:23 -0400 | [diff] [blame] | 48 | return std::make_shared<UdpChannel>(udp::Endpoint(addr, port), 2_s, false, |
| 49 | mtu.value_or(ndn::MAX_NDN_PACKET_SIZE)); |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Davide Pesavento | 8fd15e6 | 2017-04-06 19:58:54 -0400 | [diff] [blame] | 52 | void |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 53 | connect(UdpChannel& channel) final |
| 54 | { |
| 55 | g_io.post([&] { |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 56 | channel.connect(listenerEp, {}, |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 57 | [this] (const shared_ptr<Face>& newFace) { |
| 58 | BOOST_REQUIRE(newFace != nullptr); |
| 59 | connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); }); |
| 60 | clientFaces.push_back(newFace); |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 61 | newFace->getTransport()->send(ndn::encoding::makeStringBlock(300, "hello")); |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 62 | limitedIo.afterOp(); |
| 63 | }, |
| 64 | ChannelFixture::unexpectedFailure); |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | protected: |
| 69 | std::vector<shared_ptr<Face>> clientFaces; |
| 70 | }; |
| 71 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame^] | 72 | } // namespace nfd::tests |
Davide Pesavento | 9a00fab | 2016-09-27 11:22:46 +0200 | [diff] [blame] | 73 | |
| 74 | #endif // NFD_TESTS_DAEMON_FACE_UDP_CHANNEL_FIXTURE_HPP |