blob: c91e78a45f135da64b6494ffd19f5a5fa47a2cd7 [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/*
Davide Pesavento264af772021-02-09 21:48:24 -05003 * Copyright (c) 2014-2021, 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
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -040037class Channel;
38
Junxiao Shicde37ad2015-12-24 01:02:05 -070039/** \brief indicates the state of a face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070040 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070041typedef TransportState FaceState;
42
43/** \brief generalization of a network interface
44 *
45 * A face generalizes a network interface.
46 * It provides best-effort network-layer packet delivery services
47 * on a physical interface, an overlay tunnel, or a link to a local application.
48 *
49 * A face combines two parts: LinkService and Transport.
50 * Transport is the lower part, which provides best-effort TLV block deliveries.
51 * LinkService is the upper part, which translates between network-layer packets
52 * and TLV blocks, and may provide additional services such as fragmentation and reassembly.
53 */
Davide Pesavento264af772021-02-09 21:48:24 -050054class Face NFD_FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070055{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070056public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070057 Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
58
59 LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -070060 getLinkService() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070061
62 Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -070063 getTransport() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070064
Eric Newberrycb6551e2020-03-02 14:12:16 -080065 /** \brief Request that the face be closed
66 *
67 * This operation is effective only if face is in the UP or DOWN state; otherwise, it has no effect.
68 * The face will change state to CLOSING, and then perform a cleanup procedure.
69 * When the cleanup is complete, the state will be changed to CLOSED, which may happen
70 * synchronously or asynchronously.
71 *
72 * \warning The face must not be deallocated until its state changes to CLOSED.
73 */
74 void
75 close();
76
Junxiao Shicde37ad2015-12-24 01:02:05 -070077public: // upper interface connected to forwarding
Teng Liangf3bc3ae2020-06-08 10:19:25 -070078 /** \brief send Interest
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080079 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070080 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070081 sendInterest(const Interest& interest);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080082
Teng Liangf3bc3ae2020-06-08 10:19:25 -070083 /** \brief send Data
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080084 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070085 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070086 sendData(const Data& data);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070087
Teng Liangf3bc3ae2020-06-08 10:19:25 -070088 /** \brief send Nack
Junxiao Shicde37ad2015-12-24 01:02:05 -070089 */
90 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070091 sendNack(const lp::Nack& nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -070092
93 /** \brief signals on Interest received
94 */
ashiqopu075bb7d2019-03-10 01:38:21 +000095 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
Junxiao Shicde37ad2015-12-24 01:02:05 -070096
97 /** \brief signals on Data received
98 */
ashiqopu075bb7d2019-03-10 01:38:21 +000099 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700100
101 /** \brief signals on Nack received
102 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000103 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700104
Eric Newberry41aba102017-11-01 16:42:13 -0700105 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
106 */
107 signal::Signal<LinkService, Interest>& onDroppedInterest;
108
Eric Newberrycb6551e2020-03-02 14:12:16 -0800109public: // properties
Junxiao Shicde37ad2015-12-24 01:02:05 -0700110 /** \return face ID
111 */
Junxiao Shi79494162014-04-02 18:25:11 -0700112 FaceId
113 getId() const;
114
Junxiao Shicde37ad2015-12-24 01:02:05 -0700115 /** \brief sets face ID
116 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100117 */
118 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700119 setId(FaceId id);
Davide Pesavento94279412015-02-27 01:29:32 +0100120
Junxiao Shicde37ad2015-12-24 01:02:05 -0700121 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100122 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700123 FaceUri
124 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100125
Junxiao Shicde37ad2015-12-24 01:02:05 -0700126 /** \return a FaceUri representing remote endpoint
127 */
128 FaceUri
129 getRemoteUri() const;
130
131 /** \return whether face is local or non-local for scope control purpose
132 */
133 ndn::nfd::FaceScope
134 getScope() const;
135
136 /** \return face persistency setting
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700137 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800138 ndn::nfd::FacePersistency
139 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100140
Junxiao Shicde37ad2015-12-24 01:02:05 -0700141 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700142 */
143 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700144 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700145
Junxiao Shicde37ad2015-12-24 01:02:05 -0700146 /** \return whether face is point-to-point or multi-access
147 */
148 ndn::nfd::LinkType
149 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100150
Eric Newberrycb6551e2020-03-02 14:12:16 -0800151 /** \brief Returns face effective MTU
152 *
153 * This function is a wrapper. The effective MTU of a face is determined by the link service.
154 */
155 ssize_t
156 getMtu() const;
157
Junxiao Shicde37ad2015-12-24 01:02:05 -0700158 /** \return face state
159 */
160 FaceState
161 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700162
Junxiao Shicde37ad2015-12-24 01:02:05 -0700163 /** \brief signals after face state changed
164 */
165 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
166
Eric Newberryc64d30a2015-12-26 11:07:27 -0700167 /** \return expiration time of the face
168 * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
169 */
170 time::steady_clock::TimePoint
171 getExpirationTime() const;
172
Junxiao Shicde37ad2015-12-24 01:02:05 -0700173 const FaceCounters&
Davide Pesavento0498ce82021-06-14 02:02:21 -0400174 getCounters() const
175 {
176 return m_counters;
177 }
178
179 FaceCounters&
180 getCounters()
181 {
182 return m_counters;
183 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700184
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400185 /**
186 * \brief Get channel on which face was created (unicast) or the associated channel (multicast)
187 */
188 weak_ptr<Channel>
189 getChannel() const
190 {
191 return m_channel;
192 }
193
194 /**
195 * \brief Set channel on which face was created (unicast) or the associated channel (multicast)
196 */
197 void
198 setChannel(weak_ptr<Channel> channel)
199 {
200 m_channel = std::move(channel);
201 }
202
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700203private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700204 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700205 unique_ptr<LinkService> m_service;
206 unique_ptr<Transport> m_transport;
207 FaceCounters m_counters;
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400208 weak_ptr<Channel> m_channel;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700209};
210
Junxiao Shicde37ad2015-12-24 01:02:05 -0700211inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700212Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700213{
214 return m_service.get();
215}
216
217inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700218Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700219{
220 return m_transport.get();
221}
222
223inline void
Eric Newberrycb6551e2020-03-02 14:12:16 -0800224Face::close()
225{
226 m_transport->close();
227}
228
229inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700230Face::sendInterest(const Interest& interest)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700231{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700232 m_service->sendInterest(interest);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700233}
234
235inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700236Face::sendData(const Data& data)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700237{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700238 m_service->sendData(data);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700239}
240
241inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700242Face::sendNack(const lp::Nack& nack)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700243{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700244 m_service->sendNack(nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700245}
246
Davide Pesavento94279412015-02-27 01:29:32 +0100247inline FaceId
248Face::getId() const
249{
250 return m_id;
251}
252
253inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700254Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100255{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700256 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100257}
258
Junxiao Shicde37ad2015-12-24 01:02:05 -0700259inline FaceUri
260Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100261{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700262 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100263}
264
Junxiao Shicde37ad2015-12-24 01:02:05 -0700265inline FaceUri
266Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100267{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700268 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100269}
270
Junxiao Shicde37ad2015-12-24 01:02:05 -0700271inline ndn::nfd::FaceScope
272Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100273{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700274 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100275}
276
Yukai Tu731f0d72015-07-04 11:14:44 +0800277inline ndn::nfd::FacePersistency
278Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100279{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700280 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100281}
282
283inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800284Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100285{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700286 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100287}
288
Junxiao Shicde37ad2015-12-24 01:02:05 -0700289inline ndn::nfd::LinkType
290Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100291{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700292 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100293}
294
Eric Newberrycb6551e2020-03-02 14:12:16 -0800295inline ssize_t
296Face::getMtu() const
297{
298 return m_service->getEffectiveMtu();
299}
300
Junxiao Shicde37ad2015-12-24 01:02:05 -0700301inline FaceState
302Face::getState() const
303{
304 return m_transport->getState();
305}
306
Eric Newberryc64d30a2015-12-26 11:07:27 -0700307inline time::steady_clock::TimePoint
308Face::getExpirationTime() const
309{
310 return m_transport->getExpirationTime();
311}
312
Junxiao Shicde37ad2015-12-24 01:02:05 -0700313std::ostream&
314operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000315
Junxiao Shicde37ad2015-12-24 01:02:05 -0700316} // namespace face
317
Junxiao Shicde37ad2015-12-24 01:02:05 -0700318using face::Face;
319
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800320} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700321
Eric Newberry41aba102017-11-01 16:42:13 -0700322#endif // NFD_DAEMON_FACE_FACE_HPP