blob: e96bc310dedfc930d3552b2487e8220877f6c24c [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 */
Davide Pesavento16916ae2019-03-29 23:53:26 -040067class Face FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070068{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070069public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070070 Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
71
72 LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -070073 getLinkService() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070074
75 Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -070076 getTransport() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070077
78public: // upper interface connected to forwarding
ashiqopu075bb7d2019-03-10 01:38:21 +000079 /** \brief send Interest to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080080 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070081 void
ashiqopu075bb7d2019-03-10 01:38:21 +000082 sendInterest(const Interest& interest, const EndpointId& endpointId);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080083
ashiqopu075bb7d2019-03-10 01:38:21 +000084 /** \brief send Data to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080085 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070086 void
ashiqopu075bb7d2019-03-10 01:38:21 +000087 sendData(const Data& data, const EndpointId& endpointId);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070088
ashiqopu075bb7d2019-03-10 01:38:21 +000089 /** \brief send Nack to \p endpointId
Junxiao Shicde37ad2015-12-24 01:02:05 -070090 */
91 void
ashiqopu075bb7d2019-03-10 01:38:21 +000092 sendNack(const lp::Nack& nack, const EndpointId& endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -070093
94 /** \brief signals on Interest received
95 */
ashiqopu075bb7d2019-03-10 01:38:21 +000096 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
Junxiao Shicde37ad2015-12-24 01:02:05 -070097
98 /** \brief signals on Data received
99 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000100 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101
102 /** \brief signals on Nack received
103 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000104 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700105
Eric Newberry41aba102017-11-01 16:42:13 -0700106 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
107 */
108 signal::Signal<LinkService, Interest>& onDroppedInterest;
109
Junxiao Shicde37ad2015-12-24 01:02:05 -0700110public: // static properties
111 /** \return face ID
112 */
Junxiao Shi79494162014-04-02 18:25:11 -0700113 FaceId
114 getId() const;
115
Junxiao Shicde37ad2015-12-24 01:02:05 -0700116 /** \brief sets face ID
117 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100118 */
119 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700120 setId(FaceId id);
Davide Pesavento94279412015-02-27 01:29:32 +0100121
Junxiao Shicde37ad2015-12-24 01:02:05 -0700122 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100123 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700124 FaceUri
125 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100126
Junxiao Shicde37ad2015-12-24 01:02:05 -0700127 /** \return a FaceUri representing remote endpoint
128 */
129 FaceUri
130 getRemoteUri() const;
131
132 /** \return whether face is local or non-local for scope control purpose
133 */
134 ndn::nfd::FaceScope
135 getScope() const;
136
137 /** \return face persistency setting
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700138 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800139 ndn::nfd::FacePersistency
140 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100141
Junxiao Shicde37ad2015-12-24 01:02:05 -0700142 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700143 */
144 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700145 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700146
Junxiao Shicde37ad2015-12-24 01:02:05 -0700147 /** \return whether face is point-to-point or multi-access
148 */
149 ndn::nfd::LinkType
150 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100151
Junxiao Shicde37ad2015-12-24 01:02:05 -0700152public: // dynamic properties
153 /** \return face state
154 */
155 FaceState
156 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700157
Junxiao Shicde37ad2015-12-24 01:02:05 -0700158 /** \brief signals after face state changed
159 */
160 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
161
Eric Newberryc64d30a2015-12-26 11:07:27 -0700162 /** \return expiration time of the face
163 * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
164 */
165 time::steady_clock::TimePoint
166 getExpirationTime() const;
167
Junxiao Shicde37ad2015-12-24 01:02:05 -0700168 /** \brief request the face to be closed
169 *
170 * This operation is effective only if face is in UP or DOWN state,
171 * otherwise it has no effect.
172 * The face changes state to CLOSING, and performs cleanup procedure.
173 * The state will be changed to CLOSED when cleanup is complete, which may
174 * happen synchronously or asynchronously.
175 *
176 * \warning the face must not be deallocated until its state changes to CLOSED
177 */
178 void
179 close();
180
181 const FaceCounters&
182 getCounters() const;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700183
184private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700185 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700186 unique_ptr<LinkService> m_service;
187 unique_ptr<Transport> m_transport;
188 FaceCounters m_counters;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700189};
190
Junxiao Shicde37ad2015-12-24 01:02:05 -0700191inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700192Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700193{
194 return m_service.get();
195}
196
197inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700198Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700199{
200 return m_transport.get();
201}
202
203inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000204Face::sendInterest(const Interest& interest, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700205{
ashiqopu075bb7d2019-03-10 01:38:21 +0000206 m_service->sendInterest(interest, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700207}
208
209inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000210Face::sendData(const Data& data, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700211{
ashiqopu075bb7d2019-03-10 01:38:21 +0000212 m_service->sendData(data, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700213}
214
215inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000216Face::sendNack(const lp::Nack& nack, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700217{
ashiqopu075bb7d2019-03-10 01:38:21 +0000218 m_service->sendNack(nack, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700219}
220
Davide Pesavento94279412015-02-27 01:29:32 +0100221inline FaceId
222Face::getId() const
223{
224 return m_id;
225}
226
227inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700228Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100229{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700230 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100231}
232
Junxiao Shicde37ad2015-12-24 01:02:05 -0700233inline FaceUri
234Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100235{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700236 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100237}
238
Junxiao Shicde37ad2015-12-24 01:02:05 -0700239inline FaceUri
240Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100241{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700242 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100243}
244
Junxiao Shicde37ad2015-12-24 01:02:05 -0700245inline ndn::nfd::FaceScope
246Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100247{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700248 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100249}
250
Yukai Tu731f0d72015-07-04 11:14:44 +0800251inline ndn::nfd::FacePersistency
252Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100253{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700254 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100255}
256
257inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800258Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100259{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700260 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100261}
262
Junxiao Shicde37ad2015-12-24 01:02:05 -0700263inline ndn::nfd::LinkType
264Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100265{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700266 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100267}
268
Junxiao Shicde37ad2015-12-24 01:02:05 -0700269inline FaceState
270Face::getState() const
271{
272 return m_transport->getState();
273}
274
Eric Newberryc64d30a2015-12-26 11:07:27 -0700275inline time::steady_clock::TimePoint
276Face::getExpirationTime() const
277{
278 return m_transport->getExpirationTime();
279}
280
Junxiao Shicde37ad2015-12-24 01:02:05 -0700281inline void
282Face::close()
283{
284 m_transport->close();
285}
286
287inline const FaceCounters&
Junxiao Shi7860d482014-02-21 23:57:20 -0700288Face::getCounters() const
289{
Junxiao Shi7860d482014-02-21 23:57:20 -0700290 return m_counters;
291}
292
Junxiao Shicde37ad2015-12-24 01:02:05 -0700293std::ostream&
294operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000295
Junxiao Shicde37ad2015-12-24 01:02:05 -0700296} // namespace face
297
ashiqopu77d0bfd2019-02-20 20:37:31 +0000298using face::EndpointId;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700299using face::FaceId;
300using face::Face;
301
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800302} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700303
Eric Newberry41aba102017-11-01 16:42:13 -0700304#endif // NFD_DAEMON_FACE_FACE_HPP