blob: 951b1a517c69ffb8f10738cf91e282cf4a242a72 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventob84bd3a2016-04-22 02:21:45 +02003 * Copyright (c) 2014-2016, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -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#ifndef NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
27#define NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP
28
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000029#include "core/common.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070030
31#include "face/transport.hpp"
32
33namespace nfd {
34namespace face {
35namespace tests {
36
37/** \brief dummy Transport used in unit tests
38 */
39class DummyTransport : public Transport
40{
41public:
42 DummyTransport(const std::string& localUri = "dummy://",
43 const std::string& remoteUri = "dummy://",
44 ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
45 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Junxiao Shi57df2882015-11-11 06:12:35 -070046 ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT,
47 ssize_t mtu = MTU_UNLIMITED)
Eric Newberrya98bf932015-09-21 00:58:47 -070048 : isClosed(false)
49 {
50 this->setLocalUri(FaceUri(localUri));
51 this->setRemoteUri(FaceUri(remoteUri));
52 this->setScope(scope);
53 this->setPersistency(persistency);
54 this->setLinkType(linkType);
Junxiao Shi57df2882015-11-11 06:12:35 -070055 this->setMtu(mtu);
Eric Newberrya98bf932015-09-21 00:58:47 -070056 }
57
58 void
Eric Newberry4c3e6b82015-11-10 16:48:42 -070059 setMtu(ssize_t mtu)
60 {
61 this->Transport::setMtu(mtu);
62 }
63
64 void
Eric Newberrya98bf932015-09-21 00:58:47 -070065 setState(FaceState state)
66 {
67 this->Transport::setState(state);
68 }
69
70 void
71 receivePacket(Packet&& packet)
72 {
73 this->receive(std::move(packet));
74 }
75
76 void
77 receivePacket(Block block)
78 {
79 this->receive(Packet(std::move(block)));
80 }
81
Davide Pesavento8728a252015-11-06 04:01:22 +010082protected:
83 virtual void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020084 beforeChangePersistency(ndn::nfd::FacePersistency newPersistency) override
Davide Pesavento8728a252015-11-06 04:01:22 +010085 {
86 // accept everything
87 }
88
Eric Newberrya98bf932015-09-21 00:58:47 -070089private:
90 virtual void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020091 doClose() override
Eric Newberrya98bf932015-09-21 00:58:47 -070092 {
93 isClosed = true;
Junxiao Shicde37ad2015-12-24 01:02:05 -070094 this->setState(TransportState::CLOSED);
Eric Newberrya98bf932015-09-21 00:58:47 -070095 }
96
97 virtual void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020098 doSend(Packet&& packet) override
Eric Newberrya98bf932015-09-21 00:58:47 -070099 {
100 sentPackets.push_back(std::move(packet));
101 }
102
103public:
104 bool isClosed;
105 std::vector<Packet> sentPackets;
106};
107
108} // namespace tests
109} // namespace face
110} // namespace nfd
111
112#endif // NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP