blob: 5c9895b120b95f5d7c6d9471eace61c6c6fc31ca [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventob84bd3a2016-04-22 02:21:45 +02003 * Copyright (c) 2014-2016, Regents of the University of California,
Eric Newberrya98bf932015-09-21 00:58:47 -07004 * 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
Junxiao Shicde37ad2015-12-24 01:02:05 -070026#include "dummy-face.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070027#include "dummy-transport.hpp"
28
29namespace nfd {
30namespace face {
31namespace tests {
32
Junxiao Shicde37ad2015-12-24 01:02:05 -070033class DummyFace::LinkService : public face::LinkService
Eric Newberrya98bf932015-09-21 00:58:47 -070034{
35public:
36 void
37 receiveInterest(const Interest& interest)
38 {
39 this->face::LinkService::receiveInterest(interest);
40 }
41
42 void
43 receiveData(const Data& data)
44 {
45 this->face::LinkService::receiveData(data);
46 }
47
48 void
49 receiveNack(const lp::Nack& nack)
50 {
51 this->face::LinkService::receiveNack(nack);
52 }
53
Junxiao Shicde37ad2015-12-24 01:02:05 -070054 signal::Signal<LinkService, uint32_t> afterSend;
Eric Newberrya98bf932015-09-21 00:58:47 -070055
56private:
57 virtual void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020058 doSendInterest(const Interest& interest) override
Eric Newberrya98bf932015-09-21 00:58:47 -070059 {
60 this->sentInterests.push_back(interest);
Junxiao Shicde37ad2015-12-24 01:02:05 -070061 this->afterSend(tlv::Interest);
Eric Newberrya98bf932015-09-21 00:58:47 -070062 }
63
64 virtual void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020065 doSendData(const Data& data) override
Eric Newberrya98bf932015-09-21 00:58:47 -070066 {
67 this->sentData.push_back(data);
Junxiao Shicde37ad2015-12-24 01:02:05 -070068 this->afterSend(tlv::Data);
Eric Newberrya98bf932015-09-21 00:58:47 -070069 }
70
71 virtual void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020072 doSendNack(const lp::Nack& nack) override
Eric Newberrya98bf932015-09-21 00:58:47 -070073 {
74 this->sentNacks.push_back(nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -070075 this->afterSend(lp::tlv::Nack);
Eric Newberrya98bf932015-09-21 00:58:47 -070076 }
77
78 virtual void
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020079 doReceivePacket(Transport::Packet&& packet) override
Eric Newberrya98bf932015-09-21 00:58:47 -070080 {
81 BOOST_ASSERT(false);
82 }
83
84public:
85 std::vector<Interest> sentInterests;
86 std::vector<Data> sentData;
87 std::vector<lp::Nack> sentNacks;
88};
89
Junxiao Shicde37ad2015-12-24 01:02:05 -070090DummyFace::DummyFace(const std::string& localUri, const std::string& remoteUri,
91 ndn::nfd::FaceScope scope, ndn::nfd::FacePersistency persistency,
92 ndn::nfd::LinkType linkType)
93 : Face(make_unique<LinkService>(),
94 make_unique<DummyTransport>(localUri, remoteUri, scope, persistency, linkType))
Eric Newberrya98bf932015-09-21 00:58:47 -070095 , afterSend(this->getLinkServiceInternal()->afterSend)
96 , sentInterests(this->getLinkServiceInternal()->sentInterests)
97 , sentData(this->getLinkServiceInternal()->sentData)
98 , sentNacks(this->getLinkServiceInternal()->sentNacks)
99{
100}
101
102void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700103DummyFace::setState(FaceState state)
Eric Newberrya98bf932015-09-21 00:58:47 -0700104{
105 this->getTransportInternal()->setState(state);
106}
107
108void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700109DummyFace::receiveInterest(const Interest& interest)
Eric Newberrya98bf932015-09-21 00:58:47 -0700110{
111 this->getLinkServiceInternal()->receiveInterest(interest);
112}
113
114void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700115DummyFace::receiveData(const Data& data)
Eric Newberrya98bf932015-09-21 00:58:47 -0700116{
117 this->getLinkServiceInternal()->receiveData(data);
118}
119
120void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700121DummyFace::receiveNack(const lp::Nack& nack)
Eric Newberrya98bf932015-09-21 00:58:47 -0700122{
123 this->getLinkServiceInternal()->receiveNack(nack);
124}
125
Junxiao Shicde37ad2015-12-24 01:02:05 -0700126DummyFace::LinkService*
127DummyFace::getLinkServiceInternal()
Eric Newberrya98bf932015-09-21 00:58:47 -0700128{
129 return static_cast<LinkService*>(this->getLinkService());
130}
131
132DummyTransport*
Junxiao Shicde37ad2015-12-24 01:02:05 -0700133DummyFace::getTransportInternal()
Eric Newberrya98bf932015-09-21 00:58:47 -0700134{
135 return static_cast<DummyTransport*>(this->getTransport());
136}
137
138} // namespace tests
139} // namespace face
140} // namespace nfd