blob: e4c68b388c7bbde33d937e85aaf722d3a1464351 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi02b73f52016-07-28 01:48:27 +00003 * Copyright (c) 2014-2016, Regents of the University of California,
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08004 * 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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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/>.
Junxiao Shi08d07a72014-06-09 23:17:57 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
Junxiao Shi08d07a72014-06-09 23:17:57 -070026#ifndef NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP
27#define NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP
Junxiao Shicbba04c2014-01-26 14:21:22 -070028
29#include "face/face.hpp"
30
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shicde37ad2015-12-24 01:02:05 -070032namespace face {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033namespace tests {
Junxiao Shicbba04c2014-01-26 14:21:22 -070034
Junxiao Shicde37ad2015-12-24 01:02:05 -070035class DummyTransport;
36
Junxiao Shi0de23a22015-12-03 20:07:02 +000037/** \brief a Face for unit testing
Junxiao Shicde37ad2015-12-24 01:02:05 -070038 *
39 * The DummyFace has no underlying transport, but allows observing outgoing packets
40 * and injecting incoming packets at network layer.
41 * It's primarily used for forwarding test suites, but can be used in other tests as well.
42 *
43 * Outgoing network-layer packets sent through the DummyFace are recorded in sent* vectors,
44 * which can be observed in test cases.
45 * Incoming network-layer packets can be injected from test cases through receive* method.
Junxiao Shicbba04c2014-01-26 14:21:22 -070046 */
Junxiao Shi0de23a22015-12-03 20:07:02 +000047class DummyFace : public Face
Junxiao Shicbba04c2014-01-26 14:21:22 -070048{
49public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070050 class LinkService;
Chengyu Fan320d2332014-10-29 16:40:33 -060051
Junxiao Shicde37ad2015-12-24 01:02:05 -070052 DummyFace(const std::string& localUri = "dummy://", const std::string& remoteUri = "dummy://",
53 ndn::nfd::FaceScope scope = ndn::nfd::FACE_SCOPE_NON_LOCAL,
54 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
55 ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_POINT_TO_POINT);
56
57 /** \brief changes face state
Junxiao Shi02b73f52016-07-28 01:48:27 +000058 * \throw std::runtime_error state transition is invalid
Junxiao Shicde37ad2015-12-24 01:02:05 -070059 */
Davide Pesavento66ff0982015-01-29 22:39:00 +010060 void
Junxiao Shicde37ad2015-12-24 01:02:05 -070061 setState(FaceState state);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070062
Junxiao Shicde37ad2015-12-24 01:02:05 -070063 /** \brief causes the face to receive an Interest
64 */
Davide Pesavento66ff0982015-01-29 22:39:00 +010065 void
Junxiao Shicde37ad2015-12-24 01:02:05 -070066 receiveInterest(const Interest& interest);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080067
Junxiao Shicde37ad2015-12-24 01:02:05 -070068 /** \brief causes the face to receive a Data
69 */
Davide Pesavento66ff0982015-01-29 22:39:00 +010070 void
Junxiao Shicde37ad2015-12-24 01:02:05 -070071 receiveData(const Data& data);
Alexander Afanasyev93ce75e2014-02-18 19:45:34 -080072
Junxiao Shicde37ad2015-12-24 01:02:05 -070073 /** \brief causes the face to receive a Nack
74 */
Junxiao Shi9b27bd22014-02-26 20:29:58 -070075 void
Junxiao Shicde37ad2015-12-24 01:02:05 -070076 receiveNack(const lp::Nack& nack);
Junxiao Shi9b27bd22014-02-26 20:29:58 -070077
Junxiao Shicde37ad2015-12-24 01:02:05 -070078 /** \brief signals after any network-layer packet is sent
79 *
80 * The network-layer packet type is indicated as an argument,
81 * which is either of tlv::Interest, tlv::Data, or lp::tlv::Nack.
82 * The callback may retrieve the packet from sentInterests.back(), sentData.back(), or sentNacks.back().
83 */
84 signal::Signal<LinkService, uint32_t>& afterSend;
Junxiao Shi9b27bd22014-02-26 20:29:58 -070085
Junxiao Shicde37ad2015-12-24 01:02:05 -070086private:
87 LinkService*
88 getLinkServiceInternal();
89
90 DummyTransport*
91 getTransportInternal();
Junxiao Shi9b27bd22014-02-26 20:29:58 -070092
93public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070094 std::vector<Interest>& sentInterests;
95 std::vector<Data>& sentData;
96 std::vector<lp::Nack>& sentNacks;
Junxiao Shicbba04c2014-01-26 14:21:22 -070097};
98
Junxiao Shicde37ad2015-12-24 01:02:05 -070099} // namespace tests
100} // namespace face
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800101
Junxiao Shicde37ad2015-12-24 01:02:05 -0700102namespace tests {
103using nfd::face::tests::DummyFace;
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700104} // namespace tests
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800105} // namespace nfd
Junxiao Shicbba04c2014-01-26 14:21:22 -0700106
Junxiao Shi08d07a72014-06-09 23:17:57 -0700107#endif // NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP