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