blob: 3717336d4747dbb394537712748c49f801aacb7e [file] [log] [blame]
Davide Pesaventoa8098582019-03-31 15:48:02 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
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
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
41 LogReceivedPackets = 1 << 3, ///< log all received packets (as Transport::Packet)
42 LogAllPackets = LogSentPackets | LogReceivedPackets, ///< log all sent and received packets
43};
44
45/** \brief A dummy LinkService that logs all sent and received packets.
46 */
47class DummyLinkService final : public LinkService
48{
49public:
50 /** \brief Emitted after a network-layer packet is sent through this link service.
51 *
52 * The packet type is reported via the argument, whose value will be one of
53 * tlv::Interest, tlv::Data, or lp::tlv::Nack. Signal handlers may retrieve
54 * the packet via `sentInterests.back()`, `sentData.back()`, or `sentNacks.back()`.
55 */
56 signal::Signal<DummyLinkService, uint32_t> afterSend;
57
58 using LinkService::receiveInterest;
59 using LinkService::receiveData;
60 using LinkService::receiveNack;
61
62 void
63 setPacketLogging(std::underlying_type_t<PacketLoggingFlags> flags)
64 {
65 m_loggingFlags = static_cast<PacketLoggingFlags>(flags);
66 }
67
68private:
69 void
70 doSendInterest(const Interest& interest) final;
71
72 void
73 doSendData(const Data& data) final;
74
75 void
76 doSendNack(const lp::Nack& nack) final;
77
78 void
79 doReceivePacket(Transport::Packet&& packet) final;
80
81public:
82 std::vector<Interest> sentInterests;
83 std::vector<Data> sentData;
84 std::vector<lp::Nack> sentNacks;
85 std::vector<Transport::Packet> receivedPackets;
86
87private:
88 PacketLoggingFlags m_loggingFlags = LogAllPackets;
89};
90
91} // namespace tests
92} // namespace face
93} // namespace nfd
94
95#endif // NFD_TESTS_DAEMON_FACE_DUMMY_LINK_SERVICE_HPP