Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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_LP_FACE_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP |
| 28 | |
| 29 | #include "face/lp-face.hpp" |
| 30 | |
| 31 | namespace nfd { |
| 32 | namespace face { |
| 33 | namespace tests { |
| 34 | |
| 35 | class DummyTransport; |
| 36 | |
| 37 | /** \brief a LpFace for unit testing |
| 38 | * |
| 39 | * The DummyLpFace allows observing outgoing network-layer packets, |
| 40 | * and allows incoming network-layer packets to be injected from a test suite. |
| 41 | * It's primarily used for forwarding test suites, but can be used in other tests as well. |
| 42 | */ |
| 43 | class DummyLpFace : public LpFace |
| 44 | { |
| 45 | public: |
| 46 | class LinkService; |
| 47 | |
| 48 | DummyLpFace(const std::string& localUri = "dummy://", const std::string& remoteUri = "dummy://", |
| 49 | ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL, |
| 50 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 51 | ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT); |
| 52 | |
| 53 | /** \brief changes face state |
| 54 | * \pre current state is not CLOSED or FAILED |
| 55 | */ |
| 56 | void |
| 57 | setState(FaceState state); |
| 58 | |
| 59 | /** \brief causes the face to receive an Interest |
| 60 | */ |
| 61 | void |
| 62 | receiveInterest(const Interest& interest); |
| 63 | |
| 64 | /** \brief causes the face to receive a Data |
| 65 | */ |
| 66 | void |
| 67 | receiveData(const Data& data); |
| 68 | |
| 69 | /** \brief causes the face to receive a Nack |
| 70 | */ |
| 71 | void |
| 72 | receiveNack(const lp::Nack& nack); |
| 73 | |
| 74 | /** \brief signals after any network-layer packet is sent |
| 75 | */ |
| 76 | signal::Signal<LinkService>& afterSend; |
| 77 | |
| 78 | private: |
| 79 | LinkService* |
| 80 | getLinkServiceInternal(); |
| 81 | |
| 82 | DummyTransport* |
| 83 | getTransportInternal(); |
| 84 | |
| 85 | public: |
| 86 | std::vector<Interest>& sentInterests; |
| 87 | std::vector<Data>& sentData; |
| 88 | std::vector<lp::Nack>& sentNacks; |
| 89 | }; |
| 90 | |
| 91 | } // namespace tests |
| 92 | } // namespace face |
| 93 | |
| 94 | namespace tests { |
| 95 | using nfd::face::tests::DummyLpFace; |
| 96 | } // namespace tests |
| 97 | } // namespace nfd |
| 98 | |
| 99 | #endif // NFD_TESTS_DAEMON_FACE_DUMMY_LP_FACE_HPP |