blob: 6661f0c91cd3041ae87ee137c2f5c40cfda456b0 [file] [log] [blame]
Davide Pesaventoa8098582019-03-31 15:48:02 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Davide Pesaventoa8098582019-03-31 15:48:02 -04004 * 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 Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tests {
Davide Pesaventoa8098582019-03-31 15:48:02 -040032
33enum 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 Pesaventob3a23ca2019-05-04 20:40:21 -040039 LogReceivedPackets = 1 << 3, ///< log all received link-layer packets
Davide Pesaventoa8098582019-03-31 15:48:02 -040040 LogAllPackets = LogSentPackets | LogReceivedPackets, ///< log all sent and received packets
41};
42
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040043struct RxPacket
44{
45 Block packet;
46 EndpointId endpoint;
47};
48
Davide Pesaventoa8098582019-03-31 15:48:02 -040049/** \brief A dummy LinkService that logs all sent and received packets.
50 */
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040051class DummyLinkService final : public face::LinkService
Davide Pesaventoa8098582019-03-31 15:48:02 -040052{
53public:
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
72private:
73 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070074 doSendInterest(const Interest& interest) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040075
76 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070077 doSendData(const Data& data) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040078
79 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070080 doSendNack(const lp::Nack& nack) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040081
82 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040083 doReceivePacket(const Block& packet, const EndpointId& endpoint) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040084
85public:
86 std::vector<Interest> sentInterests;
87 std::vector<Data> sentData;
88 std::vector<lp::Nack> sentNacks;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040089 std::vector<RxPacket> receivedPackets;
Davide Pesaventoa8098582019-03-31 15:48:02 -040090
91private:
92 PacketLoggingFlags m_loggingFlags = LogAllPackets;
93};
94
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040095} // namespace nfd::tests
Davide Pesaventoa8098582019-03-31 15:48:02 -040096
97#endif // NFD_TESTS_DAEMON_FACE_DUMMY_LINK_SERVICE_HPP