Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California, |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [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_DUMMY_TRANSPORT_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |
| 28 | |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 29 | #include "core/common.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 30 | |
| 31 | #include "face/transport.hpp" |
| 32 | |
| 33 | namespace nfd { |
| 34 | namespace face { |
| 35 | namespace tests { |
| 36 | |
| 37 | /** \brief dummy Transport used in unit tests |
| 38 | */ |
| 39 | class DummyTransport : public Transport |
| 40 | { |
| 41 | public: |
| 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 Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 46 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT, |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 47 | ssize_t mtu = MTU_UNLIMITED, |
| 48 | ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 49 | : isClosed(false) |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 50 | , m_sendQueueLength(0) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 51 | { |
| 52 | this->setLocalUri(FaceUri(localUri)); |
| 53 | this->setRemoteUri(FaceUri(remoteUri)); |
| 54 | this->setScope(scope); |
| 55 | this->setPersistency(persistency); |
| 56 | this->setLinkType(linkType); |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 57 | this->setMtu(mtu); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 58 | this->setSendQueueCapacity(sendQueueCapacity); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void |
Eric Newberry | 4c3e6b8 | 2015-11-10 16:48:42 -0700 | [diff] [blame] | 62 | setMtu(ssize_t mtu) |
| 63 | { |
| 64 | this->Transport::setMtu(mtu); |
| 65 | } |
| 66 | |
| 67 | void |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 68 | setState(FaceState state) |
| 69 | { |
| 70 | this->Transport::setState(state); |
| 71 | } |
| 72 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 73 | ssize_t |
| 74 | getSendQueueLength() override |
| 75 | { |
| 76 | return m_sendQueueLength; |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | setSendQueueLength(ssize_t sendQueueLength) |
| 81 | { |
| 82 | m_sendQueueLength = sendQueueLength; |
| 83 | } |
| 84 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 85 | void |
| 86 | receivePacket(Packet&& packet) |
| 87 | { |
| 88 | this->receive(std::move(packet)); |
| 89 | } |
| 90 | |
| 91 | void |
| 92 | receivePacket(Block block) |
| 93 | { |
| 94 | this->receive(Packet(std::move(block))); |
| 95 | } |
| 96 | |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 97 | protected: |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 98 | bool |
| 99 | canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const override |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 100 | { |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 101 | return true; |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 104 | private: |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 105 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 106 | doClose() override |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 107 | { |
| 108 | isClosed = true; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 109 | this->setState(TransportState::CLOSED); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 112 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 113 | doSend(Packet&& packet) override |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 114 | { |
| 115 | sentPackets.push_back(std::move(packet)); |
| 116 | } |
| 117 | |
| 118 | public: |
| 119 | bool isClosed; |
| 120 | std::vector<Packet> sentPackets; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 121 | |
| 122 | private: |
| 123 | ssize_t m_sendQueueLength; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace tests |
| 127 | } // namespace face |
| 128 | } // namespace nfd |
| 129 | |
| 130 | #endif // NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |