blob: 3d7796859102b0a4d48af7a4cb1ca8de953d1bcb [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NFD_TESTS_DAEMON_FACE_DUMMY_LINK_SERVICE_HPP
#define NFD_TESTS_DAEMON_FACE_DUMMY_LINK_SERVICE_HPP
#include "face/link-service.hpp"
namespace nfd {
namespace face {
namespace tests {
enum PacketLoggingFlags : unsigned {
LogNothing = 0, ///< disable packet logging
LogSentInterests = 1 << 0, ///< log sent Interest packets
LogSentData = 1 << 1, ///< log sent Data packets
LogSentNacks = 1 << 2, ///< log sent Nack packets
LogSentPackets = LogSentInterests | LogSentData | LogSentNacks, ///< log all sent packets
LogReceivedPackets = 1 << 3, ///< log all received link-layer packets
LogAllPackets = LogSentPackets | LogReceivedPackets, ///< log all sent and received packets
};
struct RxPacket
{
Block packet;
EndpointId endpoint;
};
/** \brief A dummy LinkService that logs all sent and received packets.
*/
class DummyLinkService final : public LinkService
{
public:
/** \brief Emitted after a network-layer packet is sent through this link service.
*
* The packet type is reported via the argument, whose value will be one of
* tlv::Interest, tlv::Data, or lp::tlv::Nack. Signal handlers may retrieve
* the packet via `sentInterests.back()`, `sentData.back()`, or `sentNacks.back()`.
*/
signal::Signal<DummyLinkService, uint32_t> afterSend;
using LinkService::receiveInterest;
using LinkService::receiveData;
using LinkService::receiveNack;
void
setPacketLogging(std::underlying_type_t<PacketLoggingFlags> flags)
{
m_loggingFlags = static_cast<PacketLoggingFlags>(flags);
}
private:
void
doSendInterest(const Interest& interest) final;
void
doSendData(const Data& data) final;
void
doSendNack(const lp::Nack& nack) final;
void
doReceivePacket(const Block& packet, const EndpointId& endpoint) final;
public:
std::vector<Interest> sentInterests;
std::vector<Data> sentData;
std::vector<lp::Nack> sentNacks;
std::vector<RxPacket> receivedPackets;
private:
PacketLoggingFlags m_loggingFlags = LogAllPackets;
};
} // namespace tests
} // namespace face
} // namespace nfd
#endif // NFD_TESTS_DAEMON_FACE_DUMMY_LINK_SERVICE_HPP