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 | |
| 26 | #ifndef NFD_DAEMON_FACE_LINK_SERVICE_HPP |
| 27 | #define NFD_DAEMON_FACE_LINK_SERVICE_HPP |
| 28 | |
| 29 | #include "transport.hpp" |
| 30 | #include "face-log.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace face { |
| 34 | |
| 35 | class LpFace; |
| 36 | |
| 37 | /** \brief the upper part of an LpFace |
| 38 | * \sa LpFace |
| 39 | */ |
| 40 | class LinkService : noncopyable |
| 41 | { |
| 42 | public: |
| 43 | LinkService(); |
| 44 | |
| 45 | virtual |
| 46 | ~LinkService(); |
| 47 | |
| 48 | /** \brief set Face and Transport for LinkService |
| 49 | * \pre setFaceAndTransport has not been called |
| 50 | */ |
| 51 | void |
| 52 | setFaceAndTransport(LpFace& face, Transport& transport); |
| 53 | |
| 54 | /** \return Face to which this LinkService is attached |
| 55 | */ |
| 56 | const LpFace* |
| 57 | getFace() const; |
| 58 | |
| 59 | /** \return Transport to which this LinkService is attached |
| 60 | */ |
| 61 | const Transport* |
| 62 | getTransport() const; |
| 63 | |
| 64 | /** \return Transport to which this LinkService is attached |
| 65 | */ |
| 66 | Transport* |
| 67 | getTransport(); |
| 68 | |
| 69 | public: // upper interface to be used by forwarding |
| 70 | /** \brief send Interest |
| 71 | * \pre setTransport has been called |
| 72 | */ |
| 73 | void |
| 74 | sendInterest(const Interest& interest); |
| 75 | |
| 76 | /** \brief send Data |
| 77 | * \pre setTransport has been called |
| 78 | */ |
| 79 | void |
| 80 | sendData(const Data& data); |
| 81 | |
| 82 | /** \brief send Nack |
| 83 | * \pre setTransport has been called |
| 84 | */ |
| 85 | void |
| 86 | sendNack(const ndn::lp::Nack& nack); |
| 87 | |
| 88 | /** \brief signals on Interest received |
| 89 | */ |
| 90 | signal::Signal<LinkService, Interest> afterReceiveInterest; |
| 91 | |
| 92 | /** \brief signals on Data received |
| 93 | */ |
| 94 | signal::Signal<LinkService, Data> afterReceiveData; |
| 95 | |
| 96 | /** \brief signals on Nack received |
| 97 | */ |
| 98 | signal::Signal<LinkService, lp::Nack> afterReceiveNack; |
| 99 | |
| 100 | private: // upper interface to be overridden in subclass (send path entrypoint) |
| 101 | /** \brief performs LinkService specific operations to send an Interest |
| 102 | */ |
| 103 | virtual void |
| 104 | doSendInterest(const Interest& interest) = 0; |
| 105 | |
| 106 | /** \brief performs LinkService specific operations to send a Data |
| 107 | */ |
| 108 | virtual void |
| 109 | doSendData(const Data& data) = 0; |
| 110 | |
| 111 | /** \brief performs LinkService specific operations to send a Nack |
| 112 | */ |
| 113 | virtual void |
| 114 | doSendNack(const lp::Nack& nack) = 0; |
| 115 | |
| 116 | protected: // upper interface to be invoked in subclass (receive path termination) |
| 117 | /** \brief delivers received Interest to forwarding |
| 118 | */ |
| 119 | void |
| 120 | receiveInterest(const Interest& interest); |
| 121 | |
| 122 | /** \brief delivers received Data to forwarding |
| 123 | */ |
| 124 | void |
| 125 | receiveData(const Data& data); |
| 126 | |
| 127 | /** \brief delivers received Nack to forwarding |
| 128 | */ |
| 129 | void |
| 130 | receiveNack(const lp::Nack& nack); |
| 131 | |
| 132 | public: // lower interface to be invoked by Transport |
| 133 | /** \brief performs LinkService specific operations to receive a lower-layer packet |
| 134 | */ |
| 135 | void |
| 136 | receivePacket(Transport::Packet&& packet); |
| 137 | |
| 138 | protected: // lower interface to be invoked in subclass (send path termination) |
| 139 | /** \brief sends a lower-layer packet via Transport |
| 140 | */ |
| 141 | void |
| 142 | sendPacket(Transport::Packet&& packet); |
| 143 | |
| 144 | private: // lower interface to be overridden in subclass |
| 145 | virtual void |
| 146 | doReceivePacket(Transport::Packet&& packet) = 0; |
| 147 | |
| 148 | private: |
| 149 | LpFace* m_face; |
| 150 | Transport* m_transport; |
| 151 | NetworkLayerCounters* m_counters; // TODO#3177 change into NetCounters |
| 152 | }; |
| 153 | |
| 154 | inline const LpFace* |
| 155 | LinkService::getFace() const |
| 156 | { |
| 157 | return m_face; |
| 158 | } |
| 159 | |
| 160 | inline const Transport* |
| 161 | LinkService::getTransport() const |
| 162 | { |
| 163 | return m_transport; |
| 164 | } |
| 165 | |
| 166 | inline Transport* |
| 167 | LinkService::getTransport() |
| 168 | { |
| 169 | return m_transport; |
| 170 | } |
| 171 | |
| 172 | inline void |
| 173 | LinkService::receivePacket(Transport::Packet&& packet) |
| 174 | { |
| 175 | doReceivePacket(std::move(packet)); |
| 176 | } |
| 177 | |
| 178 | inline void |
| 179 | LinkService::sendPacket(Transport::Packet&& packet) |
| 180 | { |
| 181 | m_transport->send(std::move(packet)); |
| 182 | } |
| 183 | |
| 184 | std::ostream& |
| 185 | operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh); |
| 186 | |
| 187 | template<typename T> |
| 188 | typename std::enable_if<std::is_base_of<LinkService, T>::value && |
| 189 | !std::is_same<LinkService, T>::value, std::ostream&>::type |
| 190 | operator<<(std::ostream& os, const FaceLogHelper<T>& flh) |
| 191 | { |
| 192 | return os << FaceLogHelper<LinkService>(flh.obj); |
| 193 | } |
| 194 | |
| 195 | } // namespace face |
| 196 | } // namespace nfd |
| 197 | |
| 198 | #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP |