blob: 3d7796859102b0a4d48af7a4cb1ca8de953d1bcb [file] [log] [blame]
Davide Pesaventoa8098582019-03-31 15:48:02 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Teng Liangf3bc3ae2020-06-08 10:19:25 -07003 * Copyright (c) 2014-2020, 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
31namespace nfd {
32namespace face {
33namespace tests {
34
35enum 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 Pesaventob3a23ca2019-05-04 20:40:21 -040041 LogReceivedPackets = 1 << 3, ///< log all received link-layer packets
Davide Pesaventoa8098582019-03-31 15:48:02 -040042 LogAllPackets = LogSentPackets | LogReceivedPackets, ///< log all sent and received packets
43};
44
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040045struct RxPacket
46{
47 Block packet;
48 EndpointId endpoint;
49};
50
Davide Pesaventoa8098582019-03-31 15:48:02 -040051/** \brief A dummy LinkService that logs all sent and received packets.
52 */
53class DummyLinkService final : public LinkService
54{
55public:
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
74private:
75 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070076 doSendInterest(const Interest& interest) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040077
78 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070079 doSendData(const Data& data) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040080
81 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070082 doSendNack(const lp::Nack& nack) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040083
84 void
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040085 doReceivePacket(const Block& packet, const EndpointId& endpoint) final;
Davide Pesaventoa8098582019-03-31 15:48:02 -040086
87public:
88 std::vector<Interest> sentInterests;
89 std::vector<Data> sentData;
90 std::vector<lp::Nack> sentNacks;
Davide Pesaventob3a23ca2019-05-04 20:40:21 -040091 std::vector<RxPacket> receivedPackets;
Davide Pesaventoa8098582019-03-31 15:48:02 -040092
93private:
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