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