blob: e9731ee395d642d7c2a7911a9364c344b21da119 [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
44/** \brief generalization of a network interface
45 *
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*
Eric Newberryc05918c2016-09-29 10:38:13 -070061 getLinkService() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070062
63 Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -070064 getTransport() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070065
Eric Newberrycb6551e2020-03-02 14:12:16 -080066 /** \brief Request that the face be closed
67 *
68 * This operation is effective only if face is in the UP or DOWN state; otherwise, it has no effect.
69 * The face will change state to CLOSING, and then perform a cleanup procedure.
70 * When the cleanup is complete, the state will be changed to CLOSED, which may happen
71 * synchronously or asynchronously.
72 *
73 * \warning The face must not be deallocated until its state changes to CLOSED.
74 */
75 void
76 close();
77
Junxiao Shicde37ad2015-12-24 01:02:05 -070078public: // upper interface connected to forwarding
Teng Liangf3bc3ae2020-06-08 10:19:25 -070079 /** \brief send Interest
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080080 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070081 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070082 sendInterest(const Interest& interest);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080083
Teng Liangf3bc3ae2020-06-08 10:19:25 -070084 /** \brief send Data
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080085 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070086 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070087 sendData(const Data& data);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070088
Teng Liangf3bc3ae2020-06-08 10:19:25 -070089 /** \brief send Nack
Junxiao Shicde37ad2015-12-24 01:02:05 -070090 */
91 void
Teng Liangf3bc3ae2020-06-08 10:19:25 -070092 sendNack(const lp::Nack& nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -070093
94 /** \brief signals on Interest received
95 */
ashiqopu075bb7d2019-03-10 01:38:21 +000096 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
Junxiao Shicde37ad2015-12-24 01:02:05 -070097
98 /** \brief signals on Data received
99 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000100 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101
102 /** \brief signals on Nack received
103 */
ashiqopu075bb7d2019-03-10 01:38:21 +0000104 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700105
Eric Newberry41aba102017-11-01 16:42:13 -0700106 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
107 */
108 signal::Signal<LinkService, Interest>& onDroppedInterest;
109
Eric Newberrycb6551e2020-03-02 14:12:16 -0800110public: // properties
Junxiao Shicde37ad2015-12-24 01:02:05 -0700111 /** \return face ID
112 */
Junxiao Shi79494162014-04-02 18:25:11 -0700113 FaceId
114 getId() const;
115
Junxiao Shicde37ad2015-12-24 01:02:05 -0700116 /** \brief sets face ID
117 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100118 */
119 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700120 setId(FaceId id);
Davide Pesavento94279412015-02-27 01:29:32 +0100121
Junxiao Shicde37ad2015-12-24 01:02:05 -0700122 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100123 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700124 FaceUri
125 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100126
Junxiao Shicde37ad2015-12-24 01:02:05 -0700127 /** \return a FaceUri representing remote endpoint
128 */
129 FaceUri
130 getRemoteUri() const;
131
132 /** \return whether face is local or non-local for scope control purpose
133 */
134 ndn::nfd::FaceScope
135 getScope() const;
136
137 /** \return face persistency setting
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700138 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800139 ndn::nfd::FacePersistency
140 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100141
Junxiao Shicde37ad2015-12-24 01:02:05 -0700142 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700143 */
144 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700145 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700146
Junxiao Shicde37ad2015-12-24 01:02:05 -0700147 /** \return whether face is point-to-point or multi-access
148 */
149 ndn::nfd::LinkType
150 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100151
Eric Newberrycb6551e2020-03-02 14:12:16 -0800152 /** \brief Returns face effective MTU
153 *
154 * This function is a wrapper. The effective MTU of a face is determined by the link service.
155 */
156 ssize_t
157 getMtu() const;
158
Junxiao Shicde37ad2015-12-24 01:02:05 -0700159 /** \return face state
160 */
161 FaceState
162 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700163
Junxiao Shicde37ad2015-12-24 01:02:05 -0700164 /** \brief signals after face state changed
165 */
166 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
167
Eric Newberryc64d30a2015-12-26 11:07:27 -0700168 /** \return expiration time of the face
169 * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
170 */
171 time::steady_clock::TimePoint
172 getExpirationTime() const;
173
Junxiao Shicde37ad2015-12-24 01:02:05 -0700174 const FaceCounters&
Davide Pesavento0498ce82021-06-14 02:02:21 -0400175 getCounters() const
176 {
177 return m_counters;
178 }
179
180 FaceCounters&
181 getCounters()
182 {
183 return m_counters;
184 }
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700185
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400186 /**
187 * \brief Get channel on which face was created (unicast) or the associated channel (multicast)
188 */
189 weak_ptr<Channel>
190 getChannel() const
191 {
192 return m_channel;
193 }
194
195 /**
196 * \brief Set channel on which face was created (unicast) or the associated channel (multicast)
197 */
198 void
199 setChannel(weak_ptr<Channel> channel)
200 {
201 m_channel = std::move(channel);
202 }
203
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700204private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700205 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700206 unique_ptr<LinkService> m_service;
207 unique_ptr<Transport> m_transport;
208 FaceCounters m_counters;
Alexander Afanasyev3a2339a2020-05-27 23:05:06 -0400209 weak_ptr<Channel> m_channel;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700210};
211
Junxiao Shicde37ad2015-12-24 01:02:05 -0700212inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700213Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700214{
215 return m_service.get();
216}
217
218inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700219Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700220{
221 return m_transport.get();
222}
223
224inline void
Eric Newberrycb6551e2020-03-02 14:12:16 -0800225Face::close()
226{
227 m_transport->close();
228}
229
230inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700231Face::sendInterest(const Interest& interest)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700232{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700233 m_service->sendInterest(interest);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700234}
235
236inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700237Face::sendData(const Data& data)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700238{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700239 m_service->sendData(data);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700240}
241
242inline void
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700243Face::sendNack(const lp::Nack& nack)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700244{
Teng Liangf3bc3ae2020-06-08 10:19:25 -0700245 m_service->sendNack(nack);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700246}
247
Davide Pesavento94279412015-02-27 01:29:32 +0100248inline FaceId
249Face::getId() const
250{
251 return m_id;
252}
253
254inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700255Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100256{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700257 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100258}
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
Eric Newberryc64d30a2015-12-26 11:07:27 -0700308inline time::steady_clock::TimePoint
309Face::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