| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /* |
| * Copyright (c) 2014-2020, Regents of the University of California, |
| * Arizona Board of Regents, |
| * Colorado State University, |
| * University Pierre & Marie Curie, Sorbonne University, |
| * Washington University in St. Louis, |
| * Beijing Institute of Technology, |
| * The University of Memphis. |
| * |
| * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| * See AUTHORS.md for complete list of NFD authors and contributors. |
| * |
| * NFD is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, |
| * either version 3 of the License, or (at your option) any later version. |
| * |
| * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| * PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License along with |
| * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| |
| #ifndef NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |
| #define NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |
| |
| #include "core/common.hpp" |
| |
| #include "face/null-transport.hpp" |
| |
| namespace nfd { |
| namespace face { |
| namespace tests { |
| |
| /** \brief Dummy Transport type used in unit tests. |
| * |
| * All packets sent through this transport are stored in `sentPackets`. |
| * Reception of a packet can be simulated by invoking `receivePacket()`. |
| * All persistency changes are recorded in `persistencyHistory`. |
| */ |
| template<bool CAN_CHANGE_PERSISTENCY> |
| class DummyTransportBase : public NullTransport |
| { |
| public: |
| explicit |
| DummyTransportBase(const std::string& localUri = "dummy://", |
| const std::string& remoteUri = "dummy://", |
| ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT, |
| ssize_t mtu = MTU_UNLIMITED, |
| ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED) |
| : NullTransport(FaceUri(localUri), FaceUri(remoteUri), scope, persistency) |
| { |
| this->setLinkType(linkType); |
| this->setMtu(mtu); |
| this->setSendQueueCapacity(sendQueueCapacity); |
| } |
| |
| using NullTransport::setMtu; |
| using NullTransport::setState; |
| |
| ssize_t |
| getSendQueueLength() override |
| { |
| return m_sendQueueLength; |
| } |
| |
| void |
| setSendQueueLength(ssize_t sendQueueLength) |
| { |
| m_sendQueueLength = sendQueueLength; |
| } |
| |
| void |
| receivePacket(const Block& block) |
| { |
| receive(block); |
| } |
| |
| protected: |
| bool |
| canChangePersistencyToImpl(ndn::nfd::FacePersistency) const override |
| { |
| return CAN_CHANGE_PERSISTENCY; |
| } |
| |
| void |
| afterChangePersistency(ndn::nfd::FacePersistency old) override |
| { |
| persistencyHistory.push_back(old); |
| } |
| |
| private: |
| void |
| doSend(const Block& packet) override |
| { |
| sentPackets.push_back(packet); |
| } |
| |
| public: |
| std::vector<ndn::nfd::FacePersistency> persistencyHistory; |
| std::vector<Block> sentPackets; |
| |
| private: |
| ssize_t m_sendQueueLength = 0; |
| }; |
| |
| using DummyTransport = DummyTransportBase<true>; |
| |
| } // namespace tests |
| } // namespace face |
| } // namespace nfd |
| |
| #endif // NFD_TESTS_DAEMON_FACE_DUMMY_TRANSPORT_HPP |