Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 2 | /* |
ashiqopu | 77d0bfd | 2019-02-20 20:37:31 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 25 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FACE_FACE_HPP |
| 27 | #define NFD_DAEMON_FACE_FACE_HPP |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 28 | |
Davide Pesavento | cb425e8 | 2019-07-14 21:48:22 -0400 | [diff] [blame] | 29 | #include "face-common.hpp" |
Junxiao Shi | 33152f1 | 2014-07-16 19:54:32 -0700 | [diff] [blame] | 30 | #include "face-counters.hpp" |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 31 | #include "link-service.hpp" |
| 32 | #include "transport.hpp" |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 34 | namespace nfd { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 35 | namespace face { |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 36 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 37 | /** \brief indicates the state of a face |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 38 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 39 | typedef TransportState FaceState; |
| 40 | |
| 41 | /** \brief generalization of a network interface |
| 42 | * |
| 43 | * A face generalizes a network interface. |
| 44 | * It provides best-effort network-layer packet delivery services |
| 45 | * on a physical interface, an overlay tunnel, or a link to a local application. |
| 46 | * |
| 47 | * A face combines two parts: LinkService and Transport. |
| 48 | * Transport is the lower part, which provides best-effort TLV block deliveries. |
| 49 | * LinkService is the upper part, which translates between network-layer packets |
| 50 | * and TLV blocks, and may provide additional services such as fragmentation and reassembly. |
| 51 | */ |
Davide Pesavento | 16916ae | 2019-03-29 23:53:26 -0400 | [diff] [blame] | 52 | class Face FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 53 | { |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 54 | public: |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 55 | Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport); |
| 56 | |
| 57 | LinkService* |
Eric Newberry | c05918c | 2016-09-29 10:38:13 -0700 | [diff] [blame] | 58 | getLinkService() const; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 59 | |
| 60 | Transport* |
Eric Newberry | c05918c | 2016-09-29 10:38:13 -0700 | [diff] [blame] | 61 | getTransport() const; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 62 | |
| 63 | public: // upper interface connected to forwarding |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 64 | /** \brief send Interest to \p endpointId |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 65 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 66 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 67 | sendInterest(const Interest& interest, const EndpointId& endpointId); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 68 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 69 | /** \brief send Data to \p endpointId |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 70 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 71 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 72 | sendData(const Data& data, const EndpointId& endpointId); |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 73 | |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 74 | /** \brief send Nack to \p endpointId |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 75 | */ |
| 76 | void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 77 | sendNack(const lp::Nack& nack, const EndpointId& endpointId); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 78 | |
| 79 | /** \brief signals on Interest received |
| 80 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 81 | signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 82 | |
| 83 | /** \brief signals on Data received |
| 84 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 85 | signal::Signal<LinkService, Data, EndpointId>& afterReceiveData; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 86 | |
| 87 | /** \brief signals on Nack received |
| 88 | */ |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 89 | signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 90 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 91 | /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx |
| 92 | */ |
| 93 | signal::Signal<LinkService, Interest>& onDroppedInterest; |
| 94 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 95 | public: // static properties |
| 96 | /** \return face ID |
| 97 | */ |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 98 | FaceId |
| 99 | getId() const; |
| 100 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 101 | /** \brief sets face ID |
| 102 | * \note Normally, this should only be invoked by FaceTable. |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 103 | */ |
| 104 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 105 | setId(FaceId id); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 106 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 107 | /** \return a FaceUri representing local endpoint |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 108 | */ |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 109 | FaceUri |
| 110 | getLocalUri() const; |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 111 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 112 | /** \return a FaceUri representing remote endpoint |
| 113 | */ |
| 114 | FaceUri |
| 115 | getRemoteUri() const; |
| 116 | |
| 117 | /** \return whether face is local or non-local for scope control purpose |
| 118 | */ |
| 119 | ndn::nfd::FaceScope |
| 120 | getScope() const; |
| 121 | |
| 122 | /** \return face persistency setting |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 123 | */ |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 124 | ndn::nfd::FacePersistency |
| 125 | getPersistency() const; |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 126 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 127 | /** \brief changes face persistency setting |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 128 | */ |
| 129 | void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 130 | setPersistency(ndn::nfd::FacePersistency persistency); |
Junxiao Shi | 08d07a7 | 2014-06-09 23:17:57 -0700 | [diff] [blame] | 131 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 132 | /** \return whether face is point-to-point or multi-access |
| 133 | */ |
| 134 | ndn::nfd::LinkType |
| 135 | getLinkType() const; |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 136 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 137 | public: // dynamic properties |
| 138 | /** \return face state |
| 139 | */ |
| 140 | FaceState |
| 141 | getState() const; |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 142 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 143 | /** \brief signals after face state changed |
| 144 | */ |
| 145 | signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange; |
| 146 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 147 | /** \return expiration time of the face |
| 148 | * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime |
| 149 | */ |
| 150 | time::steady_clock::TimePoint |
| 151 | getExpirationTime() const; |
| 152 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 153 | /** \brief request the face to be closed |
| 154 | * |
| 155 | * This operation is effective only if face is in UP or DOWN state, |
| 156 | * otherwise it has no effect. |
| 157 | * The face changes state to CLOSING, and performs cleanup procedure. |
| 158 | * The state will be changed to CLOSED when cleanup is complete, which may |
| 159 | * happen synchronously or asynchronously. |
| 160 | * |
| 161 | * \warning the face must not be deallocated until its state changes to CLOSED |
| 162 | */ |
| 163 | void |
| 164 | close(); |
| 165 | |
| 166 | const FaceCounters& |
| 167 | getCounters() const; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 168 | |
| 169 | private: |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 170 | FaceId m_id; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 171 | unique_ptr<LinkService> m_service; |
| 172 | unique_ptr<Transport> m_transport; |
| 173 | FaceCounters m_counters; |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 176 | inline LinkService* |
Eric Newberry | c05918c | 2016-09-29 10:38:13 -0700 | [diff] [blame] | 177 | Face::getLinkService() const |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 178 | { |
| 179 | return m_service.get(); |
| 180 | } |
| 181 | |
| 182 | inline Transport* |
Eric Newberry | c05918c | 2016-09-29 10:38:13 -0700 | [diff] [blame] | 183 | Face::getTransport() const |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 184 | { |
| 185 | return m_transport.get(); |
| 186 | } |
| 187 | |
| 188 | inline void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 189 | Face::sendInterest(const Interest& interest, const EndpointId& endpointId) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 190 | { |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 191 | m_service->sendInterest(interest, endpointId); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | inline void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 195 | Face::sendData(const Data& data, const EndpointId& endpointId) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 196 | { |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 197 | m_service->sendData(data, endpointId); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | inline void |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 201 | Face::sendNack(const lp::Nack& nack, const EndpointId& endpointId) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 202 | { |
ashiqopu | 075bb7d | 2019-03-10 01:38:21 +0000 | [diff] [blame] | 203 | m_service->sendNack(nack, endpointId); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 206 | inline FaceId |
| 207 | Face::getId() const |
| 208 | { |
| 209 | return m_id; |
| 210 | } |
| 211 | |
| 212 | inline void |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 213 | Face::setId(FaceId id) |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 214 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 215 | m_id = id; |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 218 | inline FaceUri |
| 219 | Face::getLocalUri() const |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 220 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 221 | return m_transport->getLocalUri(); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 224 | inline FaceUri |
| 225 | Face::getRemoteUri() const |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 226 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 227 | return m_transport->getRemoteUri(); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 230 | inline ndn::nfd::FaceScope |
| 231 | Face::getScope() const |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 232 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 233 | return m_transport->getScope(); |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 236 | inline ndn::nfd::FacePersistency |
| 237 | Face::getPersistency() const |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 238 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 239 | return m_transport->getPersistency(); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | inline void |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 243 | Face::setPersistency(ndn::nfd::FacePersistency persistency) |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 244 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 245 | return m_transport->setPersistency(persistency); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 248 | inline ndn::nfd::LinkType |
| 249 | Face::getLinkType() const |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 250 | { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 251 | return m_transport->getLinkType(); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 254 | inline FaceState |
| 255 | Face::getState() const |
| 256 | { |
| 257 | return m_transport->getState(); |
| 258 | } |
| 259 | |
Eric Newberry | c64d30a | 2015-12-26 11:07:27 -0700 | [diff] [blame] | 260 | inline time::steady_clock::TimePoint |
| 261 | Face::getExpirationTime() const |
| 262 | { |
| 263 | return m_transport->getExpirationTime(); |
| 264 | } |
| 265 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 266 | inline void |
| 267 | Face::close() |
| 268 | { |
| 269 | m_transport->close(); |
| 270 | } |
| 271 | |
| 272 | inline const FaceCounters& |
Junxiao Shi | 7860d48 | 2014-02-21 23:57:20 -0700 | [diff] [blame] | 273 | Face::getCounters() const |
| 274 | { |
Junxiao Shi | 7860d48 | 2014-02-21 23:57:20 -0700 | [diff] [blame] | 275 | return m_counters; |
| 276 | } |
| 277 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 278 | std::ostream& |
| 279 | operator<<(std::ostream& os, const FaceLogHelper<Face>& flh); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 280 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 281 | } // namespace face |
| 282 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 283 | using face::Face; |
| 284 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 285 | } // namespace nfd |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 286 | |
Eric Newberry | 41aba10 | 2017-11-01 16:42:13 -0700 | [diff] [blame] | 287 | #endif // NFD_DAEMON_FACE_FACE_HPP |