Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [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, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 25 | |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 26 | #ifndef NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 28 | |
| 29 | #include "face/face.hpp" |
| 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 31 | namespace nfd::tests { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 33 | class DummyLinkService; |
| 34 | |
| 35 | /** \brief A Face for unit testing. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 36 | * |
| 37 | * The DummyFace has no underlying transport, but allows observing outgoing packets |
| 38 | * and injecting incoming packets at network layer. |
| 39 | * It's primarily used for forwarding test suites, but can be used in other tests as well. |
| 40 | * |
| 41 | * Outgoing network-layer packets sent through the DummyFace are recorded in sent* vectors, |
| 42 | * which can be observed in test cases. |
| 43 | * Incoming network-layer packets can be injected from test cases through receive* method. |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 44 | */ |
Junxiao Shi | 0de23a2 | 2015-12-03 20:07:02 +0000 | [diff] [blame] | 45 | class DummyFace : public Face |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 48 | explicit |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 49 | DummyFace(const std::string& localUri = "dummy://", 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 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 54 | /** \brief Changes face state. |
Junxiao Shi | 02b73f5 | 2016-07-28 01:48:27 +0000 | [diff] [blame] | 55 | * \throw std::runtime_error state transition is invalid |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 56 | */ |
Davide Pesavento | 66ff098 | 2015-01-29 22:39:00 +0100 | [diff] [blame] | 57 | void |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 58 | setState(face::FaceState state); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 59 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 60 | /** \brief Causes the face to receive an Interest. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 61 | */ |
Davide Pesavento | 66ff098 | 2015-01-29 22:39:00 +0100 | [diff] [blame] | 62 | void |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 63 | receiveInterest(const Interest& interest, const EndpointId& endpointId = {}); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 64 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 65 | /** \brief Causes the face to receive a Data. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 66 | */ |
Davide Pesavento | 66ff098 | 2015-01-29 22:39:00 +0100 | [diff] [blame] | 67 | void |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 68 | receiveData(const Data& data, const EndpointId& endpointId = {}); |
Alexander Afanasyev | 93ce75e | 2014-02-18 19:45:34 -0800 | [diff] [blame] | 69 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 70 | /** \brief Causes the face to receive a Nack. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 71 | */ |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 72 | void |
Teng Liang | d94b7b3 | 2022-07-10 21:29:37 +0800 | [diff] [blame] | 73 | receiveNack(const lp::Nack& nack, const EndpointId& endpointId = {}); |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 74 | |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 75 | /** \brief Emitted after a network-layer packet is sent. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 76 | * |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 77 | * The packet type is reported via the argument, whose value will be one of |
| 78 | * tlv::Interest, tlv::Data, or lp::tlv::Nack. Signal handlers may retrieve |
| 79 | * the packet via `sentInterests.back()`, `sentData.back()`, or `sentNacks.back()`. |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 80 | */ |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 81 | signal::Signal<DummyLinkService, uint32_t>& afterSend; |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 82 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 83 | private: |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 84 | DummyLinkService* |
| 85 | getDummyLinkService() const; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 86 | |
Junxiao Shi | 9b27bd2 | 2014-02-26 20:29:58 -0700 | [diff] [blame] | 87 | public: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 88 | std::vector<Interest>& sentInterests; |
| 89 | std::vector<Data>& sentData; |
| 90 | std::vector<lp::Nack>& sentNacks; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 93 | } // namespace nfd::tests |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 94 | |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 95 | #endif // NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP |