blob: 5192a9742e87d7a63d5b7c4be955d2691510d78e [file] [log] [blame]
Davide Pesavento9a00fab2016-09-27 11:22:46 +02001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry2642cd22017-07-13 21:34:53 -04002/*
Davide Pesavento14e71f02019-03-28 17:35:25 -04003 * Copyright (c) 2014-2019, 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_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
34namespace nfd {
Davide Pesavento8fd15e62017-04-06 19:58:54 -040035namespace face {
Davide Pesavento9a00fab2016-09-27 11:22:46 +020036namespace tests {
37
38class UdpChannelFixture : public ChannelFixture<UdpChannel, udp::Endpoint>
39{
40protected:
Davide Pesavento8fd15e62017-04-06 19:58:54 -040041 unique_ptr<UdpChannel>
Davide Pesavento9a00fab2016-09-27 11:22:46 +020042 makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0) final
43 {
44 if (port == 0)
45 port = getNextPort();
46
Davide Pesavento14e71f02019-03-28 17:35:25 -040047 return make_unique<UdpChannel>(udp::Endpoint(addr, port), 2_s, false);
Davide Pesavento9a00fab2016-09-27 11:22:46 +020048 }
49
Davide Pesavento8fd15e62017-04-06 19:58:54 -040050 void
Davide Pesavento9a00fab2016-09-27 11:22:46 +020051 connect(UdpChannel& channel) final
52 {
53 g_io.post([&] {
Davide Pesavento15b55052018-01-27 19:09:28 -050054 channel.connect(listenerEp, {},
Davide Pesavento9a00fab2016-09-27 11:22:46 +020055 [this] (const shared_ptr<Face>& newFace) {
56 BOOST_REQUIRE(newFace != nullptr);
57 connectFaceClosedSignal(*newFace, [this] { limitedIo.afterOp(); });
58 clientFaces.push_back(newFace);
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040059 newFace->getTransport()->send(ndn::encoding::makeStringBlock(300, "hello"));
Davide Pesavento9a00fab2016-09-27 11:22:46 +020060 limitedIo.afterOp();
61 },
62 ChannelFixture::unexpectedFailure);
63 });
64 }
65
66protected:
67 std::vector<shared_ptr<Face>> clientFaces;
68};
69
70} // namespace tests
Davide Pesavento8fd15e62017-04-06 19:58:54 -040071} // namespace face
Davide Pesavento9a00fab2016-09-27 11:22:46 +020072} // namespace nfd
73
74#endif // NFD_TESTS_DAEMON_FACE_UDP_CHANNEL_FIXTURE_HPP