blob: 0076f850a2c570206d91ecc9e52406a250c3adcc [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&
174 getCounters() const;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700175
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400176 /**
177 * \brief Get channel on which face was created (unicast) or the associated channel (multicast)
178 */
179 weak_ptr<Channel>
180 getChannel() const
181 {
182 return m_channel;
183 }
184
185 /**
186 * \brief Set channel on which face was created (unicast) or the associated channel (multicast)
187 */
188 void
189 setChannel(weak_ptr<Channel> channel)
190 {
191 m_channel = std::move(channel);
192 }
193
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700194private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700195 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700196 unique_ptr<LinkService> m_service;
197 unique_ptr<Transport> m_transport;
198 FaceCounters m_counters;
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400199 weak_ptr<Channel> m_channel;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700200};
201
Junxiao Shicde37ad2015-12-24 01:02:05 -0700202inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700203Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700204{
205 return m_service.get();
206}
207
208inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700209Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700210{
211 return m_transport.get();
212}
213
214inline void
Eric Newberrycb6551e2020-03-02 14:12:16 -0800215Face::close()
216{
217 m_transport->close();
218}
219
220inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700221Face::sendInterest(const Interest& interest)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700222{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700223 m_service->sendInterest(interest);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700224}
225
226inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700227Face::sendData(const Data& data)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700228{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700229 m_service->sendData(data);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700230}
231
232inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700233Face::sendNack(const lp::Nack& nack)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700234{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700235 m_service->sendNack(nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700236}
237
Davide Pesavento94279412015-02-27 01:29:32 +0100238inline FaceId
239Face::getId() const
240{
241 return m_id;
242}
243
244inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700245Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100246{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700247 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100248}
249
Junxiao Shicde37ad2015-12-24 01:02:05 -0700250inline FaceUri
251Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100252{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700253 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100254}
255
Junxiao Shicde37ad2015-12-24 01:02:05 -0700256inline FaceUri
257Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100258{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700259 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100260}
261
Junxiao Shicde37ad2015-12-24 01:02:05 -0700262inline ndn::nfd::FaceScope
263Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100264{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700265 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100266}
267
Yukai Tu731f0d72015-07-04 11:14:44 +0800268inline ndn::nfd::FacePersistency
269Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100270{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700271 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100272}
273
274inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800275Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100276{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700277 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100278}
279
Junxiao Shicde37ad2015-12-24 01:02:05 -0700280inline ndn::nfd::LinkType
281Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100282{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700283 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100284}
285
Eric Newberrycb6551e2020-03-02 14:12:16 -0800286inline ssize_t
287Face::getMtu() const
288{
289 return m_service->getEffectiveMtu();
290}
291
Junxiao Shicde37ad2015-12-24 01:02:05 -0700292inline FaceState
293Face::getState() const
294{
295 return m_transport->getState();
296}
297
Eric Newberryc64d30a2015-12-26 11:07:27 -0700298inline time::steady_clock::TimePoint
299Face::getExpirationTime() const
300{
301 return m_transport->getExpirationTime();
302}
303
Junxiao Shicde37ad2015-12-24 01:02:05 -0700304inline const FaceCounters&
Junxiao Shi7860d482014-02-21 23:57:20 -0700305Face::getCounters() const
306{
Junxiao Shi7860d482014-02-21 23:57:20 -0700307 return m_counters;
308}
309
Junxiao Shicde37ad2015-12-24 01:02:05 -0700310std::ostream&
311operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000312
Junxiao Shicde37ad2015-12-24 01:02:05 -0700313} // namespace face
314
Junxiao Shicde37ad2015-12-24 01:02:05 -0700315using face::Face;
316
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800317} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700318
Eric Newberry41aba102017-11-01 16:42:13 -0700319#endif // NFD_DAEMON_FACE_FACE_HPP