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