blob: 4ea845ec465321d291ab03e11850deaa637a44a9 [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
Davide Pesaventocb425e82019-07-14 21:48:22 -040029#include "face-common.hpp"
Junxiao Shi33152f12014-07-16 19:54:32 -070030#include "face-counters.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 indicates the state of a face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070038 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070039typedef 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 Pesavento16916ae2019-03-29 23:53:26 -040052class Face FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070053{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070054public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070055 Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
56
57 LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -070058 getLinkService() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070059
60 Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -070061 getTransport() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070062
63public: // upper interface connected to forwarding
ashiqopu075bb7d2019-03-10 01:38:21 +000064 /** \brief send Interest to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080065 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070066 void
ashiqopu075bb7d2019-03-10 01:38:21 +000067 sendInterest(const Interest& interest, const EndpointId& endpointId);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080068
ashiqopu075bb7d2019-03-10 01:38:21 +000069 /** \brief send Data to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080070 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070071 void
ashiqopu075bb7d2019-03-10 01:38:21 +000072 sendData(const Data& data, const EndpointId& endpointId);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070073
ashiqopu075bb7d2019-03-10 01:38:21 +000074 /** \brief send Nack to \p endpointId
Junxiao Shicde37ad2015-12-24 01:02:05 -070075 */
76 void
ashiqopu075bb7d2019-03-10 01:38:21 +000077 sendNack(const lp::Nack& nack, const EndpointId& endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -070078
79 /** \brief signals on Interest received
80 */
ashiqopu075bb7d2019-03-10 01:38:21 +000081 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
Junxiao Shicde37ad2015-12-24 01:02:05 -070082
83 /** \brief signals on Data received
84 */
ashiqopu075bb7d2019-03-10 01:38:21 +000085 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
Junxiao Shicde37ad2015-12-24 01:02:05 -070086
87 /** \brief signals on Nack received
88 */
ashiqopu075bb7d2019-03-10 01:38:21 +000089 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
Junxiao Shicde37ad2015-12-24 01:02:05 -070090
Eric Newberry41aba102017-11-01 16:42:13 -070091 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
92 */
93 signal::Signal<LinkService, Interest>& onDroppedInterest;
94
Junxiao Shicde37ad2015-12-24 01:02:05 -070095public: // static properties
96 /** \return face ID
97 */
Junxiao Shi79494162014-04-02 18:25:11 -070098 FaceId
99 getId() const;
100
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101 /** \brief sets face ID
102 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100103 */
104 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700105 setId(FaceId id);
Davide Pesavento94279412015-02-27 01:29:32 +0100106
Alexander Afanasyev939a6712014-12-31 00:11:43 -0800107 void
108 setMetric(uint64_t metric);
109
110 uint64_t
111 getMetric() const;
112
Junxiao Shicde37ad2015-12-24 01:02:05 -0700113 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100114 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700115 FaceUri
116 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100117
Junxiao Shicde37ad2015-12-24 01:02:05 -0700118 /** \return a FaceUri representing remote endpoint
119 */
120 FaceUri
121 getRemoteUri() const;
122
123 /** \return whether face is local or non-local for scope control purpose
124 */
125 ndn::nfd::FaceScope
126 getScope() const;
127
128 /** \return face persistency setting
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700129 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800130 ndn::nfd::FacePersistency
131 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100132
Junxiao Shicde37ad2015-12-24 01:02:05 -0700133 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700134 */
135 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700136 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700137
Junxiao Shicde37ad2015-12-24 01:02:05 -0700138 /** \return whether face is point-to-point or multi-access
139 */
140 ndn::nfd::LinkType
141 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100142
Junxiao Shicde37ad2015-12-24 01:02:05 -0700143public: // dynamic properties
144 /** \return face state
145 */
146 FaceState
147 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700148
Junxiao Shicde37ad2015-12-24 01:02:05 -0700149 /** \brief signals after face state changed
150 */
151 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
152
Eric Newberryc64d30a2015-12-26 11:07:27 -0700153 /** \return expiration time of the face
154 * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
155 */
156 time::steady_clock::TimePoint
157 getExpirationTime() const;
158
Junxiao Shicde37ad2015-12-24 01:02:05 -0700159 /** \brief request the face to be closed
160 *
161 * This operation is effective only if face is in UP or DOWN state,
162 * otherwise it has no effect.
163 * The face changes state to CLOSING, and performs cleanup procedure.
164 * The state will be changed to CLOSED when cleanup is complete, which may
165 * happen synchronously or asynchronously.
166 *
167 * \warning the face must not be deallocated until its state changes to CLOSED
168 */
169 void
170 close();
171
172 const FaceCounters&
173 getCounters() const;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700174
175private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700176 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700177 unique_ptr<LinkService> m_service;
178 unique_ptr<Transport> m_transport;
179 FaceCounters m_counters;
Alexander Afanasyev939a6712014-12-31 00:11:43 -0800180 uint64_t m_metric;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700181};
182
Junxiao Shicde37ad2015-12-24 01:02:05 -0700183inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700184Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700185{
186 return m_service.get();
187}
188
189inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700190Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700191{
192 return m_transport.get();
193}
194
195inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000196Face::sendInterest(const Interest& interest, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700197{
ashiqopu075bb7d2019-03-10 01:38:21 +0000198 m_service->sendInterest(interest, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700199}
200
201inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000202Face::sendData(const Data& data, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700203{
ashiqopu075bb7d2019-03-10 01:38:21 +0000204 m_service->sendData(data, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700205}
206
207inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000208Face::sendNack(const lp::Nack& nack, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700209{
ashiqopu075bb7d2019-03-10 01:38:21 +0000210 m_service->sendNack(nack, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700211}
212
Davide Pesavento94279412015-02-27 01:29:32 +0100213inline FaceId
214Face::getId() const
215{
216 return m_id;
217}
218
219inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700220Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100221{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700222 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100223}
224
Alexander Afanasyev939a6712014-12-31 00:11:43 -0800225inline void
226Face::setMetric(uint64_t metric)
227{
228 m_metric = metric;
229}
230
231inline uint64_t
232Face::getMetric() const
233{
234 return m_metric;
235}
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
Junxiao Shicde37ad2015-12-24 01:02:05 -0700302using face::Face;
303
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800304} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700305
Eric Newberry41aba102017-11-01 16:42:13 -0700306#endif // NFD_DAEMON_FACE_FACE_HPP