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 | /* |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, 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 | |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 31 | #include "face/null-transport.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace face { |
| 35 | namespace tests { |
| 36 | |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 37 | /** \brief Dummy Transport type used in unit tests. |
| 38 | * |
| 39 | * All packets sent through this transport are stored in `sentPackets`. |
| 40 | * Reception of a packet can be simulated by invoking `receivePacket()`. |
| 41 | * All persistency changes are recorded in `persistencyHistory`. |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 42 | */ |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 43 | template<bool CAN_CHANGE_PERSISTENCY> |
| 44 | class DummyTransportBase : public NullTransport |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 45 | { |
| 46 | public: |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 47 | explicit |
| 48 | DummyTransportBase(const std::string& localUri = "dummy://", |
| 49 | const std::string& remoteUri = "dummy://", |
| 50 | ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 51 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 52 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT, |
| 53 | ssize_t mtu = MTU_UNLIMITED, |
| 54 | ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED) |
| 55 | : NullTransport(FaceUri(localUri), FaceUri(remoteUri), scope, persistency) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 56 | { |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 57 | this->setLinkType(linkType); |
Junxiao Shi | 57df288 | 2015-11-11 06:12:35 -0700 | [diff] [blame] | 58 | this->setMtu(mtu); |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 59 | this->setSendQueueCapacity(sendQueueCapacity); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 62 | using NullTransport::setMtu; |
| 63 | using NullTransport::setState; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 64 | |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 65 | ssize_t |
| 66 | getSendQueueLength() override |
| 67 | { |
| 68 | return m_sendQueueLength; |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | setSendQueueLength(ssize_t sendQueueLength) |
| 73 | { |
| 74 | m_sendQueueLength = sendQueueLength; |
| 75 | } |
| 76 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 77 | void |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 78 | receivePacket(Block block) |
| 79 | { |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 80 | receive(Packet(std::move(block))); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 83 | protected: |
Yanbiao Li | 32dab97 | 2016-11-27 12:26:09 +0800 | [diff] [blame] | 84 | bool |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 85 | canChangePersistencyToImpl(ndn::nfd::FacePersistency) const override |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 86 | { |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 87 | return CAN_CHANGE_PERSISTENCY; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | afterChangePersistency(ndn::nfd::FacePersistency old) override |
| 92 | { |
| 93 | persistencyHistory.push_back(old); |
Davide Pesavento | 8728a25 | 2015-11-06 04:01:22 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 96 | private: |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 97 | void |
Davide Pesavento | b84bd3a | 2016-04-22 02:21:45 +0200 | [diff] [blame] | 98 | doSend(Packet&& packet) override |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 99 | { |
| 100 | sentPackets.push_back(std::move(packet)); |
| 101 | } |
| 102 | |
| 103 | public: |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 104 | std::vector<ndn::nfd::FacePersistency> persistencyHistory; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 105 | std::vector<Packet> sentPackets; |
Eric Newberry | b49313d | 2017-12-24 20:22:27 -0700 | [diff] [blame] | 106 | |
| 107 | private: |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 108 | ssize_t m_sendQueueLength = 0; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 111 | using DummyTransport = DummyTransportBase<true>; |
| 112 | |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 113 | } // namespace tests |
| 114 | } // namespace face |
| 115 | } // namespace nfd |
| 116 | |
| 117 | #endif // NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |