Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, 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 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 26 | #include "dummy-face.hpp" |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 27 | #include "dummy-transport.hpp" |
| 28 | |
| 29 | namespace nfd { |
| 30 | namespace face { |
| 31 | namespace tests { |
| 32 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 33 | class DummyFace::LinkService : public face::LinkService |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 34 | { |
| 35 | public: |
| 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 Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 54 | signal::Signal<LinkService, uint32_t> afterSend; |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | virtual void |
| 58 | doSendInterest(const Interest& interest) DECL_OVERRIDE |
| 59 | { |
| 60 | this->sentInterests.push_back(interest); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 61 | this->afterSend(tlv::Interest); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | virtual void |
| 65 | doSendData(const Data& data) DECL_OVERRIDE |
| 66 | { |
| 67 | this->sentData.push_back(data); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 68 | this->afterSend(tlv::Data); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | virtual void |
| 72 | doSendNack(const lp::Nack& nack) DECL_OVERRIDE |
| 73 | { |
| 74 | this->sentNacks.push_back(nack); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 75 | this->afterSend(lp::tlv::Nack); |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | virtual void |
| 79 | doReceivePacket(Transport::Packet&& packet) DECL_OVERRIDE |
| 80 | { |
| 81 | BOOST_ASSERT(false); |
| 82 | } |
| 83 | |
| 84 | public: |
| 85 | std::vector<Interest> sentInterests; |
| 86 | std::vector<Data> sentData; |
| 87 | std::vector<lp::Nack> sentNacks; |
| 88 | }; |
| 89 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 90 | DummyFace::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 Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 95 | , afterSend(this->getLinkServiceInternal()->afterSend) |
| 96 | , sentInterests(this->getLinkServiceInternal()->sentInterests) |
| 97 | , sentData(this->getLinkServiceInternal()->sentData) |
| 98 | , sentNacks(this->getLinkServiceInternal()->sentNacks) |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 103 | DummyFace::setState(FaceState state) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 104 | { |
| 105 | this->getTransportInternal()->setState(state); |
| 106 | } |
| 107 | |
| 108 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 109 | DummyFace::receiveInterest(const Interest& interest) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 110 | { |
| 111 | this->getLinkServiceInternal()->receiveInterest(interest); |
| 112 | } |
| 113 | |
| 114 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 115 | DummyFace::receiveData(const Data& data) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 116 | { |
| 117 | this->getLinkServiceInternal()->receiveData(data); |
| 118 | } |
| 119 | |
| 120 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 121 | DummyFace::receiveNack(const lp::Nack& nack) |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 122 | { |
| 123 | this->getLinkServiceInternal()->receiveNack(nack); |
| 124 | } |
| 125 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 126 | DummyFace::LinkService* |
| 127 | DummyFace::getLinkServiceInternal() |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 128 | { |
| 129 | return static_cast<LinkService*>(this->getLinkService()); |
| 130 | } |
| 131 | |
| 132 | DummyTransport* |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 133 | DummyFace::getTransportInternal() |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 134 | { |
| 135 | return static_cast<DummyTransport*>(this->getTransport()); |
| 136 | } |
| 137 | |
| 138 | } // namespace tests |
| 139 | } // namespace face |
| 140 | } // namespace nfd |