blob: 4a5948b13883e085fc0e654d633c2ceca76c1c18 [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/*
Eric Newberrycb6551e2020-03-02 14:12:16 -08003 * Copyright (c) 2014-2020, 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
Eric Newberrycb6551e2020-03-02 14:12:16 -080063 /** \brief Request that the face be closed
64 *
65 * This operation is effective only if face is in the UP or DOWN state; otherwise, it has no effect.
66 * The face will change state to CLOSING, and then perform a cleanup procedure.
67 * When the cleanup is complete, the state will be changed to CLOSED, which may happen
68 * synchronously or asynchronously.
69 *
70 * \warning The face must not be deallocated until its state changes to CLOSED.
71 */
72 void
73 close();
74
Junxiao Shicde37ad2015-12-24 01:02:05 -070075public: // upper interface connected to forwarding
ashiqopu075bb7d2019-03-10 01:38:21 +000076 /** \brief send Interest to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080077 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070078 void
ashiqopu075bb7d2019-03-10 01:38:21 +000079 sendInterest(const Interest& interest, const EndpointId& endpointId);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080080
ashiqopu075bb7d2019-03-10 01:38:21 +000081 /** \brief send Data to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080082 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070083 void
ashiqopu075bb7d2019-03-10 01:38:21 +000084 sendData(const Data& data, const EndpointId& endpointId);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070085
ashiqopu075bb7d2019-03-10 01:38:21 +000086 /** \brief send Nack to \p endpointId
Junxiao Shicde37ad2015-12-24 01:02:05 -070087 */
88 void
ashiqopu075bb7d2019-03-10 01:38:21 +000089 sendNack(const lp::Nack& nack, const EndpointId& endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -070090
91 /** \brief signals on Interest received
92 */
ashiqopu075bb7d2019-03-10 01:38:21 +000093 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
Junxiao Shicde37ad2015-12-24 01:02:05 -070094
95 /** \brief signals on Data received
96 */
ashiqopu075bb7d2019-03-10 01:38:21 +000097 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
Junxiao Shicde37ad2015-12-24 01:02:05 -070098
99 /** \brief signals on Nack received
100 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000101 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700102
Eric Newberry41aba102017-11-01 16:42:13 -0700103 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
104 */
105 signal::Signal<LinkService, Interest>& onDroppedInterest;
106
Eric Newberrycb6551e2020-03-02 14:12:16 -0800107public: // properties
Junxiao Shicde37ad2015-12-24 01:02:05 -0700108 /** \return face ID
109 */
Junxiao Shi79494162014-04-02 18:25:11 -0700110 FaceId
111 getId() const;
112
Junxiao Shicde37ad2015-12-24 01:02:05 -0700113 /** \brief sets face ID
114 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100115 */
116 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700117 setId(FaceId id);
Davide Pesavento94279412015-02-27 01:29:32 +0100118
Junxiao Shicde37ad2015-12-24 01:02:05 -0700119 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100120 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700121 FaceUri
122 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100123
Junxiao Shicde37ad2015-12-24 01:02:05 -0700124 /** \return a FaceUri representing remote endpoint
125 */
126 FaceUri
127 getRemoteUri() const;
128
129 /** \return whether face is local or non-local for scope control purpose
130 */
131 ndn::nfd::FaceScope
132 getScope() const;
133
134 /** \return face persistency setting
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700135 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800136 ndn::nfd::FacePersistency
137 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100138
Junxiao Shicde37ad2015-12-24 01:02:05 -0700139 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700140 */
141 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700142 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700143
Junxiao Shicde37ad2015-12-24 01:02:05 -0700144 /** \return whether face is point-to-point or multi-access
145 */
146 ndn::nfd::LinkType
147 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100148
Eric Newberrycb6551e2020-03-02 14:12:16 -0800149 /** \brief Returns face effective MTU
150 *
151 * This function is a wrapper. The effective MTU of a face is determined by the link service.
152 */
153 ssize_t
154 getMtu() const;
155
Junxiao Shicde37ad2015-12-24 01:02:05 -0700156 /** \return face state
157 */
158 FaceState
159 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700160
Junxiao Shicde37ad2015-12-24 01:02:05 -0700161 /** \brief signals after face state changed
162 */
163 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
164
Eric Newberryc64d30a2015-12-26 11:07:27 -0700165 /** \return expiration time of the face
166 * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
167 */
168 time::steady_clock::TimePoint
169 getExpirationTime() const;
170
Junxiao Shicde37ad2015-12-24 01:02:05 -0700171 const FaceCounters&
172 getCounters() const;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700173
174private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700175 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700176 unique_ptr<LinkService> m_service;
177 unique_ptr<Transport> m_transport;
178 FaceCounters m_counters;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700179};
180
Junxiao Shicde37ad2015-12-24 01:02:05 -0700181inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700182Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700183{
184 return m_service.get();
185}
186
187inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700188Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700189{
190 return m_transport.get();
191}
192
193inline void
Eric Newberrycb6551e2020-03-02 14:12:16 -0800194Face::close()
195{
196 m_transport->close();
197}
198
199inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000200Face::sendInterest(const Interest& interest, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700201{
ashiqopu075bb7d2019-03-10 01:38:21 +0000202 m_service->sendInterest(interest, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700203}
204
205inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000206Face::sendData(const Data& data, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700207{
ashiqopu075bb7d2019-03-10 01:38:21 +0000208 m_service->sendData(data, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700209}
210
211inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000212Face::sendNack(const lp::Nack& nack, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700213{
ashiqopu075bb7d2019-03-10 01:38:21 +0000214 m_service->sendNack(nack, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700215}
216
Davide Pesavento94279412015-02-27 01:29:32 +0100217inline FaceId
218Face::getId() const
219{
220 return m_id;
221}
222
223inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700224Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100225{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700226 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100227}
228
Junxiao Shicde37ad2015-12-24 01:02:05 -0700229inline FaceUri
230Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100231{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700232 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100233}
234
Junxiao Shicde37ad2015-12-24 01:02:05 -0700235inline FaceUri
236Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100237{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700238 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100239}
240
Junxiao Shicde37ad2015-12-24 01:02:05 -0700241inline ndn::nfd::FaceScope
242Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100243{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700244 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100245}
246
Yukai Tu731f0d72015-07-04 11:14:44 +0800247inline ndn::nfd::FacePersistency
248Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100249{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700250 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100251}
252
253inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800254Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100255{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700256 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100257}
258
Junxiao Shicde37ad2015-12-24 01:02:05 -0700259inline ndn::nfd::LinkType
260Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100261{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700262 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100263}
264
Eric Newberrycb6551e2020-03-02 14:12:16 -0800265inline ssize_t
266Face::getMtu() const
267{
268 return m_service->getEffectiveMtu();
269}
270
Junxiao Shicde37ad2015-12-24 01:02:05 -0700271inline FaceState
272Face::getState() const
273{
274 return m_transport->getState();
275}
276
Eric Newberryc64d30a2015-12-26 11:07:27 -0700277inline time::steady_clock::TimePoint
278Face::getExpirationTime() const
279{
280 return m_transport->getExpirationTime();
281}
282
Junxiao Shicde37ad2015-12-24 01:02:05 -0700283inline const FaceCounters&
Junxiao Shi7860d482014-02-21 23:57:20 -0700284Face::getCounters() const
285{
Junxiao Shi7860d482014-02-21 23:57:20 -0700286 return m_counters;
287}
288
Junxiao Shicde37ad2015-12-24 01:02:05 -0700289std::ostream&
290operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000291
Junxiao Shicde37ad2015-12-24 01:02:05 -0700292} // namespace face
293
Junxiao Shicde37ad2015-12-24 01:02:05 -0700294using face::Face;
295
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800296} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700297
Eric Newberry41aba102017-11-01 16:42:13 -0700298#endif // NFD_DAEMON_FACE_FACE_HPP