blob: de01b4b436da04f4b1fcb9de365ee44bf7d9a1e0 [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
Alexander Afanasyevb0a3da32014-12-31 00:11:43 -0800121 void
122 setMetric(uint64_t metric);
123
124 uint64_t
125 getMetric() const;
126
Junxiao Shicde37ad2015-12-24 01:02:05 -0700127 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100128 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700129 FaceUri
130 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100131
Junxiao Shicde37ad2015-12-24 01:02:05 -0700132 /** \return a FaceUri representing remote endpoint
133 */
134 FaceUri
135 getRemoteUri() const;
136
137 /** \return whether face is local or non-local for scope control purpose
138 */
139 ndn::nfd::FaceScope
140 getScope() const;
141
142 /** \return face persistency setting
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700143 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800144 ndn::nfd::FacePersistency
145 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100146
Junxiao Shicde37ad2015-12-24 01:02:05 -0700147 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700148 */
149 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700150 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700151
Junxiao Shicde37ad2015-12-24 01:02:05 -0700152 /** \return whether face is point-to-point or multi-access
153 */
154 ndn::nfd::LinkType
155 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100156
Eric Newberrycb6551e2020-03-02 14:12:16 -0800157 /** \brief Returns face effective MTU
158 *
159 * This function is a wrapper. The effective MTU of a face is determined by the link service.
160 */
161 ssize_t
162 getMtu() const;
163
Junxiao Shicde37ad2015-12-24 01:02:05 -0700164 /** \return face state
165 */
166 FaceState
167 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700168
Junxiao Shicde37ad2015-12-24 01:02:05 -0700169 /** \brief signals after face state changed
170 */
171 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
172
Eric Newberryc64d30a2015-12-26 11:07:27 -0700173 /** \return expiration time of the face
174 * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
175 */
176 time::steady_clock::TimePoint
177 getExpirationTime() const;
178
Junxiao Shicde37ad2015-12-24 01:02:05 -0700179 const FaceCounters&
Davide Pesavento0498ce82021-06-14 02:02:21 -0400180 getCounters() const
181 {
182 return m_counters;
183 }
184
185 FaceCounters&
186 getCounters()
187 {
188 return m_counters;
189 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700190
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400191 /**
192 * \brief Get channel on which face was created (unicast) or the associated channel (multicast)
193 */
194 weak_ptr<Channel>
195 getChannel() const
196 {
197 return m_channel;
198 }
199
200 /**
201 * \brief Set channel on which face was created (unicast) or the associated channel (multicast)
202 */
203 void
204 setChannel(weak_ptr<Channel> channel)
205 {
206 m_channel = std::move(channel);
207 }
208
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700209private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700210 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700211 unique_ptr<LinkService> m_service;
212 unique_ptr<Transport> m_transport;
213 FaceCounters m_counters;
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400214 weak_ptr<Channel> m_channel;
Alexander Afanasyevb0a3da32014-12-31 00:11:43 -0800215 uint64_t m_metric;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700216};
217
Junxiao Shicde37ad2015-12-24 01:02:05 -0700218inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700219Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700220{
221 return m_service.get();
222}
223
224inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700225Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700226{
227 return m_transport.get();
228}
229
230inline void
Eric Newberrycb6551e2020-03-02 14:12:16 -0800231Face::close()
232{
233 m_transport->close();
234}
235
236inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700237Face::sendInterest(const Interest& interest)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700238{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700239 m_service->sendInterest(interest);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700240}
241
242inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700243Face::sendData(const Data& data)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700244{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700245 m_service->sendData(data);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700246}
247
248inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700249Face::sendNack(const lp::Nack& nack)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700250{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700251 m_service->sendNack(nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700252}
253
Davide Pesavento94279412015-02-27 01:29:32 +0100254inline FaceId
255Face::getId() const
256{
257 return m_id;
258}
259
260inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700261Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100262{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700263 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100264}
265
Alexander Afanasyevb0a3da32014-12-31 00:11:43 -0800266inline void
267Face::setMetric(uint64_t metric)
268{
269 m_metric = metric;
270}
271
272inline uint64_t
273Face::getMetric() const
274{
275 return m_metric;
276}
277
Junxiao Shicde37ad2015-12-24 01:02:05 -0700278inline FaceUri
279Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100280{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700281 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100282}
283
Junxiao Shicde37ad2015-12-24 01:02:05 -0700284inline FaceUri
285Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100286{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700287 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100288}
289
Junxiao Shicde37ad2015-12-24 01:02:05 -0700290inline ndn::nfd::FaceScope
291Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100292{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700293 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100294}
295
Yukai Tu731f0d72015-07-04 11:14:44 +0800296inline ndn::nfd::FacePersistency
297Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100298{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700299 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100300}
301
302inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800303Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100304{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700305 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100306}
307
Junxiao Shicde37ad2015-12-24 01:02:05 -0700308inline ndn::nfd::LinkType
309Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100310{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700311 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100312}
313
Eric Newberrycb6551e2020-03-02 14:12:16 -0800314inline ssize_t
315Face::getMtu() const
316{
317 return m_service->getEffectiveMtu();
318}
319
Junxiao Shicde37ad2015-12-24 01:02:05 -0700320inline FaceState
321Face::getState() const
322{
323 return m_transport->getState();
324}
325
Eric Newberryc64d30a2015-12-26 11:07:27 -0700326inline time::steady_clock::TimePoint
327Face::getExpirationTime() const
328{
329 return m_transport->getExpirationTime();
330}
331
Junxiao Shicde37ad2015-12-24 01:02:05 -0700332std::ostream&
333operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000334
Junxiao Shicde37ad2015-12-24 01:02:05 -0700335} // namespace face
336
Junxiao Shicde37ad2015-12-24 01:02:05 -0700337using face::Face;
338
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800339} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700340
Eric Newberry41aba102017-11-01 16:42:13 -0700341#endif // NFD_DAEMON_FACE_FACE_HPP