Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [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_LINK_SERVICE_HPP |
| 27 | #define NFD_TESTS_DAEMON_FACE_DUMMY_LINK_SERVICE_HPP |
| 28 | |
| 29 | #include "face/link-service.hpp" |
| 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 31 | namespace nfd::tests { |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 32 | |
| 33 | enum PacketLoggingFlags : unsigned { |
| 34 | LogNothing = 0, ///< disable packet logging |
| 35 | LogSentInterests = 1 << 0, ///< log sent Interest packets |
| 36 | LogSentData = 1 << 1, ///< log sent Data packets |
| 37 | LogSentNacks = 1 << 2, ///< log sent Nack packets |
| 38 | LogSentPackets = LogSentInterests | LogSentData | LogSentNacks, ///< log all sent packets |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 39 | LogReceivedPackets = 1 << 3, ///< log all received link-layer packets |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 40 | LogAllPackets = LogSentPackets | LogReceivedPackets, ///< log all sent and received packets |
| 41 | }; |
| 42 | |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 43 | struct RxPacket |
| 44 | { |
| 45 | Block packet; |
| 46 | EndpointId endpoint; |
| 47 | }; |
| 48 | |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 49 | /** \brief A dummy LinkService that logs all sent and received packets. |
| 50 | */ |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 51 | class DummyLinkService final : public face::LinkService |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 52 | { |
| 53 | public: |
| 54 | /** \brief Emitted after a network-layer packet is sent through this link service. |
| 55 | * |
| 56 | * The packet type is reported via the argument, whose value will be one of |
| 57 | * tlv::Interest, tlv::Data, or lp::tlv::Nack. Signal handlers may retrieve |
| 58 | * the packet via `sentInterests.back()`, `sentData.back()`, or `sentNacks.back()`. |
| 59 | */ |
| 60 | signal::Signal<DummyLinkService, uint32_t> afterSend; |
| 61 | |
| 62 | using LinkService::receiveInterest; |
| 63 | using LinkService::receiveData; |
| 64 | using LinkService::receiveNack; |
| 65 | |
| 66 | void |
| 67 | setPacketLogging(std::underlying_type_t<PacketLoggingFlags> flags) |
| 68 | { |
| 69 | m_loggingFlags = static_cast<PacketLoggingFlags>(flags); |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 74 | doSendInterest(const Interest& interest) final; |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 75 | |
| 76 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 77 | doSendData(const Data& data) final; |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 78 | |
| 79 | void |
Teng Liang | f3bc3ae | 2020-06-08 10:19:25 -0700 | [diff] [blame] | 80 | doSendNack(const lp::Nack& nack) final; |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 81 | |
| 82 | void |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 83 | doReceivePacket(const Block& packet, const EndpointId& endpoint) final; |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 84 | |
| 85 | public: |
| 86 | std::vector<Interest> sentInterests; |
| 87 | std::vector<Data> sentData; |
| 88 | std::vector<lp::Nack> sentNacks; |
Davide Pesavento | b3a23ca | 2019-05-04 20:40:21 -0400 | [diff] [blame] | 89 | std::vector<RxPacket> receivedPackets; |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 90 | |
| 91 | private: |
| 92 | PacketLoggingFlags m_loggingFlags = LogAllPackets; |
| 93 | }; |
| 94 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 95 | } // namespace nfd::tests |
Davide Pesavento | a809858 | 2019-03-31 15:48:02 -0400 | [diff] [blame] | 96 | |
| 97 | #endif // NFD_TESTS_DAEMON_FACE_DUMMY_LINK_SERVICE_HPP |