blob: b18b9ca278106725f8c6244278be67dcc0eea3d9 [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 Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, 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
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040039/**
40 * \brief Indicates the state of a face.
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070041 */
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040042using FaceState = TransportState;
Junxiao Shicde37ad2015-12-24 01:02:05 -070043
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040044/** \brief Generalization of a network interface.
Junxiao Shicde37ad2015-12-24 01:02:05 -070045 *
46 * A face generalizes a network interface.
47 * It provides best-effort network-layer packet delivery services
48 * on a physical interface, an overlay tunnel, or a link to a local application.
49 *
50 * A face combines two parts: LinkService and Transport.
51 * Transport is the lower part, which provides best-effort TLV block deliveries.
52 * LinkService is the upper part, which translates between network-layer packets
53 * and TLV blocks, and may provide additional services such as fragmentation and reassembly.
54 */
Davide Pesavento264af772021-02-09 21:48:24 -050055class Face NFD_FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070056{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070057public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070058 Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
59
60 LinkService*
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040061 getLinkService() const noexcept
62 {
63 return m_service.get();
64 }
Junxiao Shicde37ad2015-12-24 01:02:05 -070065
66 Transport*
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040067 getTransport() const noexcept
68 {
69 return m_transport.get();
70 }
Junxiao Shicde37ad2015-12-24 01:02:05 -070071
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040072 /** \brief Request that the face be closed.
Eric Newberrycb6551e2020-03-02 14:12:16 -080073 *
74 * This operation is effective only if face is in the UP or DOWN state; otherwise, it has no effect.
75 * The face will change state to CLOSING, and then perform a cleanup procedure.
76 * When the cleanup is complete, the state will be changed to CLOSED, which may happen
77 * synchronously or asynchronously.
78 *
79 * \warning The face must not be deallocated until its state changes to CLOSED.
80 */
81 void
82 close();
83
Junxiao Shicde37ad2015-12-24 01:02:05 -070084public: // upper interface connected to forwarding
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040085 /** \brief Send Interest.
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080086 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070087 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070088 sendInterest(const Interest& interest);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080089
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040090 /** \brief Send Data.
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080091 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070092 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070093 sendData(const Data& data);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070094
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040095 /** \brief Send Nack.
Junxiao Shicde37ad2015-12-24 01:02:05 -070096 */
97 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070098 sendNack(const lp::Nack& nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -070099
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400100 /** \brief Signals on Interest received.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000102 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700103
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400104 /** \brief Signals on Data received.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700105 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000106 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700107
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400108 /** \brief Signals on Nack received.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700109 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000110 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700111
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400112 /** \brief Signals on Interest dropped by reliability system for exceeding allowed number of retx.
Eric Newberry41aba102017-11-01 16:42:13 -0700113 */
114 signal::Signal<LinkService, Interest>& onDroppedInterest;
115
Eric Newberrycb6551e2020-03-02 14:12:16 -0800116public: // properties
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400117 /**
118 * \brief Returns the face ID.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700119 */
Junxiao Shi79494162014-04-02 18:25:11 -0700120 FaceId
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400121 getId() const noexcept
122 {
123 return m_id;
124 }
Junxiao Shi79494162014-04-02 18:25:11 -0700125
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400126 /**
127 * \brief Sets the face ID.
128 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100129 */
130 void
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400131 setId(FaceId id) noexcept
132 {
133 m_id = id;
134 }
Davide Pesavento94279412015-02-27 01:29:32 +0100135
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400136 /**
137 * \brief Returns a FaceUri representing the local endpoint.
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100138 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700139 FaceUri
140 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100141
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400142 /**
143 * \brief Returns a FaceUri representing the remote endpoint.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700144 */
145 FaceUri
146 getRemoteUri() const;
147
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400148 /**
149 * \brief Returns whether the face is local or non-local for scope control purposes.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700150 */
151 ndn::nfd::FaceScope
152 getScope() const;
153
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400154 /**
155 * \brief Returns the current persistency setting of the face.
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700156 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800157 ndn::nfd::FacePersistency
158 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100159
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400160 /**
161 * \brief Changes the face persistency setting.
Junxiao Shi08d07a72014-06-09 23:17:57 -0700162 */
163 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700164 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700165
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400166 /**
167 * \brief Returns the link type of the face (point-to-point, multi-access, ...).
Junxiao Shicde37ad2015-12-24 01:02:05 -0700168 */
169 ndn::nfd::LinkType
170 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100171
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400172 /**
173 * \brief Returns the effective MTU of the face.
Eric Newberrycb6551e2020-03-02 14:12:16 -0800174 *
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400175 * This function is a wrapper. The effective MTU of a face is determined by the link service.
Eric Newberrycb6551e2020-03-02 14:12:16 -0800176 */
177 ssize_t
178 getMtu() const;
179
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400180 /**
181 * \brief Returns the face state.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700182 */
183 FaceState
184 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700185
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400186 /**
187 * \brief Signals after face state changed.
Junxiao Shicde37ad2015-12-24 01:02:05 -0700188 */
189 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
190
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400191 /**
192 * \brief Returns the expiration time of the face.
193 * \retval time::steady_clock::time_point::max() The face has an indefinite lifetime.
Eric Newberryc64d30a2015-12-26 11:07:27 -0700194 */
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400195 time::steady_clock::time_point
Eric Newberryc64d30a2015-12-26 11:07:27 -0700196 getExpirationTime() const;
197
Junxiao Shicde37ad2015-12-24 01:02:05 -0700198 const FaceCounters&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400199 getCounters() const noexcept
Davide Pesavento0498ce82021-06-14 02:02:21 -0400200 {
201 return m_counters;
202 }
203
204 FaceCounters&
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400205 getCounters() noexcept
Davide Pesavento0498ce82021-06-14 02:02:21 -0400206 {
207 return m_counters;
208 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700209
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400210 /**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400211 * \brief Get channel on which face was created (unicast) or the associated channel (multicast).
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400212 */
213 weak_ptr<Channel>
214 getChannel() const
215 {
216 return m_channel;
217 }
218
219 /**
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400220 * \brief Set channel on which face was created (unicast) or the associated channel (multicast).
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400221 */
222 void
223 setChannel(weak_ptr<Channel> channel)
224 {
225 m_channel = std::move(channel);
226 }
227
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700228private:
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400229 FaceId m_id = INVALID_FACEID;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700230 unique_ptr<LinkService> m_service;
231 unique_ptr<Transport> m_transport;
232 FaceCounters m_counters;
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400233 weak_ptr<Channel> m_channel;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700234};
235
Junxiao Shicde37ad2015-12-24 01:02:05 -0700236inline void
Eric Newberrycb6551e2020-03-02 14:12:16 -0800237Face::close()
238{
239 m_transport->close();
240}
241
242inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700243Face::sendInterest(const Interest& interest)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700244{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700245 m_service->sendInterest(interest);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700246}
247
248inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700249Face::sendData(const Data& data)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700250{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700251 m_service->sendData(data);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700252}
253
254inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700255Face::sendNack(const lp::Nack& nack)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700256{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700257 m_service->sendNack(nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700258}
259
Junxiao Shicde37ad2015-12-24 01:02:05 -0700260inline FaceUri
261Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100262{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700263 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100264}
265
Junxiao Shicde37ad2015-12-24 01:02:05 -0700266inline FaceUri
267Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100268{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700269 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100270}
271
Junxiao Shicde37ad2015-12-24 01:02:05 -0700272inline ndn::nfd::FaceScope
273Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100274{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700275 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100276}
277
Yukai Tu731f0d72015-07-04 11:14:44 +0800278inline ndn::nfd::FacePersistency
279Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100280{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700281 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100282}
283
284inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800285Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100286{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700287 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100288}
289
Junxiao Shicde37ad2015-12-24 01:02:05 -0700290inline ndn::nfd::LinkType
291Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100292{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700293 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100294}
295
Eric Newberrycb6551e2020-03-02 14:12:16 -0800296inline ssize_t
297Face::getMtu() const
298{
299 return m_service->getEffectiveMtu();
300}
301
Junxiao Shicde37ad2015-12-24 01:02:05 -0700302inline FaceState
303Face::getState() const
304{
305 return m_transport->getState();
306}
307
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400308inline time::steady_clock::time_point
Eric Newberryc64d30a2015-12-26 11:07:27 -0700309Face::getExpirationTime() const
310{
311 return m_transport->getExpirationTime();
312}
313
Junxiao Shicde37ad2015-12-24 01:02:05 -0700314std::ostream&
315operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000316
Junxiao Shicde37ad2015-12-24 01:02:05 -0700317} // namespace face
318
Junxiao Shicde37ad2015-12-24 01:02:05 -0700319using face::Face;
320
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800321} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700322
Eric Newberry41aba102017-11-01 16:42:13 -0700323#endif // NFD_DAEMON_FACE_FACE_HPP