blob: f99bece976424489dc6f399ce199ec46a300e11b [file] [log] [blame]
Junxiao Shi2c29f3a2014-01-24 19:59:00 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry41aba102017-11-01 16:42:13 -07002/*
ashiqopu77d0bfd2019-02-20 20:37:31 +00003 * Copyright (c) 2014-2019, Regents of the University of California,
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08004 * 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
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 Shi33152f12014-07-16 19:54:32 -070024 */
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070025
Eric Newberry41aba102017-11-01 16:42:13 -070026#ifndef NFD_DAEMON_FACE_FACE_HPP
27#define NFD_DAEMON_FACE_FACE_HPP
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070028
Junxiao Shi33152f12014-07-16 19:54:32 -070029#include "face-counters.hpp"
Eric Newberrya98bf932015-09-21 00:58:47 -070030#include "face-log.hpp"
Eric Newberry41aba102017-11-01 16:42:13 -070031#include "link-service.hpp"
32#include "transport.hpp"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070033
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080034namespace nfd {
Junxiao Shicde37ad2015-12-24 01:02:05 -070035namespace face {
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070036
Junxiao Shicde37ad2015-12-24 01:02:05 -070037/** \brief identifies a face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070038 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070039typedef uint64_t FaceId;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070040
Junxiao Shi7b984c62014-07-17 22:18:34 -070041/// indicates an invalid FaceId
Junxiao Shicde37ad2015-12-24 01:02:05 -070042const FaceId INVALID_FACEID = 0;
Junxiao Shi7b984c62014-07-17 22:18:34 -070043/// identifies the InternalFace used in management
44const FaceId FACEID_INTERNAL_FACE = 1;
Junxiao Shi0de23a22015-12-03 20:07:02 +000045/// identifies a packet comes from the ContentStore
Junxiao Shi7b984c62014-07-17 22:18:34 -070046const FaceId FACEID_CONTENT_STORE = 254;
47/// identifies the NullFace that drops every packet
48const FaceId FACEID_NULL = 255;
49/// upper bound of reserved FaceIds
50const FaceId FACEID_RESERVED_MAX = 255;
51
Junxiao Shicde37ad2015-12-24 01:02:05 -070052/** \brief indicates the state of a face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070053 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070054typedef 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 */
67class Face
68#ifndef WITH_TESTS
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020069final
Junxiao Shicde37ad2015-12-24 01:02:05 -070070#endif
Davide Pesaventoc0822fa2018-05-10 21:54:10 -040071 : public std::enable_shared_from_this<Face>, noncopyable
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070072{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070073public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070074 Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
75
76 LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -070077 getLinkService() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070078
79 Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -070080 getTransport() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070081
82public: // upper interface connected to forwarding
83 /** \brief sends Interest on Face
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080084 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070085 void
86 sendInterest(const Interest& interest);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080087
Junxiao Shicde37ad2015-12-24 01:02:05 -070088 /** \brief sends Data on Face
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080089 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070090 void
91 sendData(const Data& data);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070092
Junxiao Shicde37ad2015-12-24 01:02:05 -070093 /** \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 Newberry41aba102017-11-01 16:42:13 -0700110 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
111 */
112 signal::Signal<LinkService, Interest>& onDroppedInterest;
113
Junxiao Shicde37ad2015-12-24 01:02:05 -0700114public: // static properties
115 /** \return face ID
116 */
Junxiao Shi79494162014-04-02 18:25:11 -0700117 FaceId
118 getId() const;
119
Junxiao Shicde37ad2015-12-24 01:02:05 -0700120 /** \brief sets face ID
121 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100122 */
123 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700124 setId(FaceId id);
Davide Pesavento94279412015-02-27 01:29:32 +0100125
Junxiao Shicde37ad2015-12-24 01:02:05 -0700126 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100127 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700128 FaceUri
129 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100130
Junxiao Shicde37ad2015-12-24 01:02:05 -0700131 /** \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 Shi32bfeb32014-01-25 18:22:02 -0700142 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800143 ndn::nfd::FacePersistency
144 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100145
Junxiao Shicde37ad2015-12-24 01:02:05 -0700146 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700147 */
148 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700149 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700150
Junxiao Shicde37ad2015-12-24 01:02:05 -0700151 /** \return whether face is point-to-point or multi-access
152 */
153 ndn::nfd::LinkType
154 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100155
Junxiao Shicde37ad2015-12-24 01:02:05 -0700156public: // dynamic properties
157 /** \return face state
158 */
159 FaceState
160 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700161
Junxiao Shicde37ad2015-12-24 01:02:05 -0700162 /** \brief signals after face state changed
163 */
164 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
165
Eric Newberryc64d30a2015-12-26 11:07:27 -0700166 /** \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 Shicde37ad2015-12-24 01:02:05 -0700172 /** \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 Shi8c8d2182014-01-30 22:33:00 -0700187
188private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700189 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700190 unique_ptr<LinkService> m_service;
191 unique_ptr<Transport> m_transport;
192 FaceCounters m_counters;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700193};
194
Junxiao Shicde37ad2015-12-24 01:02:05 -0700195inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700196Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700197{
198 return m_service.get();
199}
200
201inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700202Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700203{
204 return m_transport.get();
205}
206
207inline void
208Face::sendInterest(const Interest& interest)
209{
210 m_service->sendInterest(interest);
211}
212
213inline void
214Face::sendData(const Data& data)
215{
216 m_service->sendData(data);
217}
218
219inline void
220Face::sendNack(const lp::Nack& nack)
221{
222 m_service->sendNack(nack);
223}
224
Davide Pesavento94279412015-02-27 01:29:32 +0100225inline FaceId
226Face::getId() const
227{
228 return m_id;
229}
230
231inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700232Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100233{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700234 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100235}
236
Junxiao Shicde37ad2015-12-24 01:02:05 -0700237inline FaceUri
238Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100239{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700240 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100241}
242
Junxiao Shicde37ad2015-12-24 01:02:05 -0700243inline FaceUri
244Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100245{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700246 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100247}
248
Junxiao Shicde37ad2015-12-24 01:02:05 -0700249inline ndn::nfd::FaceScope
250Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100251{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700252 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100253}
254
Yukai Tu731f0d72015-07-04 11:14:44 +0800255inline ndn::nfd::FacePersistency
256Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100257{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700258 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100259}
260
261inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800262Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100263{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700264 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100265}
266
Junxiao Shicde37ad2015-12-24 01:02:05 -0700267inline ndn::nfd::LinkType
268Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100269{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700270 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100271}
272
Junxiao Shicde37ad2015-12-24 01:02:05 -0700273inline FaceState
274Face::getState() const
275{
276 return m_transport->getState();
277}
278
Eric Newberryc64d30a2015-12-26 11:07:27 -0700279inline time::steady_clock::TimePoint
280Face::getExpirationTime() const
281{
282 return m_transport->getExpirationTime();
283}
284
Junxiao Shicde37ad2015-12-24 01:02:05 -0700285inline void
286Face::close()
287{
288 m_transport->close();
289}
290
291inline const FaceCounters&
Junxiao Shi7860d482014-02-21 23:57:20 -0700292Face::getCounters() const
293{
Junxiao Shi7860d482014-02-21 23:57:20 -0700294 return m_counters;
295}
296
Junxiao Shicde37ad2015-12-24 01:02:05 -0700297std::ostream&
298operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000299
Junxiao Shicde37ad2015-12-24 01:02:05 -0700300} // namespace face
301
ashiqopu77d0bfd2019-02-20 20:37:31 +0000302using face::EndpointId;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700303using face::FaceId;
304using face::Face;
305
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800306} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700307
Eric Newberry41aba102017-11-01 16:42:13 -0700308#endif // NFD_DAEMON_FACE_FACE_HPP