blob: dc8c20d53903bd48515cd0f85f89a14c3a855ee2 [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/*
ashiqopu77d0bfd2019-02-20 20:37:31 +00003 * Copyright (c) 2014-2019, 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
Junxiao Shicde37ad2015-12-24 01:02:05 -070037/** \brief indicates the state of a face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070038 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070039typedef TransportState FaceState;
40
41/** \brief generalization of a network interface
42 *
43 * A face generalizes a network interface.
44 * It provides best-effort network-layer packet delivery services
45 * on a physical interface, an overlay tunnel, or a link to a local application.
46 *
47 * A face combines two parts: LinkService and Transport.
48 * Transport is the lower part, which provides best-effort TLV block deliveries.
49 * LinkService is the upper part, which translates between network-layer packets
50 * and TLV blocks, and may provide additional services such as fragmentation and reassembly.
51 */
Davide Pesavento16916ae2019-03-29 23:53:26 -040052class Face FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070053{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070054public:
Junxiao Shicde37ad2015-12-24 01:02:05 -070055 Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
56
57 LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -070058 getLinkService() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070059
60 Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -070061 getTransport() const;
Junxiao Shicde37ad2015-12-24 01:02:05 -070062
63public: // upper interface connected to forwarding
ashiqopu075bb7d2019-03-10 01:38:21 +000064 /** \brief send Interest to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080065 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070066 void
ashiqopu075bb7d2019-03-10 01:38:21 +000067 sendInterest(const Interest& interest, const EndpointId& endpointId);
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080068
ashiqopu075bb7d2019-03-10 01:38:21 +000069 /** \brief send Data to \p endpointId
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080070 */
Junxiao Shicde37ad2015-12-24 01:02:05 -070071 void
ashiqopu075bb7d2019-03-10 01:38:21 +000072 sendData(const Data& data, const EndpointId& endpointId);
Junxiao Shi16b8bc92014-02-17 22:24:55 -070073
ashiqopu075bb7d2019-03-10 01:38:21 +000074 /** \brief send Nack to \p endpointId
Junxiao Shicde37ad2015-12-24 01:02:05 -070075 */
76 void
ashiqopu075bb7d2019-03-10 01:38:21 +000077 sendNack(const lp::Nack& nack, const EndpointId& endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -070078
79 /** \brief signals on Interest received
80 */
ashiqopu075bb7d2019-03-10 01:38:21 +000081 signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
Junxiao Shicde37ad2015-12-24 01:02:05 -070082
83 /** \brief signals on Data received
84 */
ashiqopu075bb7d2019-03-10 01:38:21 +000085 signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
Junxiao Shicde37ad2015-12-24 01:02:05 -070086
87 /** \brief signals on Nack received
88 */
ashiqopu075bb7d2019-03-10 01:38:21 +000089 signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
Junxiao Shicde37ad2015-12-24 01:02:05 -070090
Eric Newberry41aba102017-11-01 16:42:13 -070091 /** \brief signals on Interest dropped by reliability system for exceeding allowed number of retx
92 */
93 signal::Signal<LinkService, Interest>& onDroppedInterest;
94
Junxiao Shicde37ad2015-12-24 01:02:05 -070095public: // static properties
96 /** \return face ID
97 */
Junxiao Shi79494162014-04-02 18:25:11 -070098 FaceId
99 getId() const;
100
Junxiao Shicde37ad2015-12-24 01:02:05 -0700101 /** \brief sets face ID
102 * \note Normally, this should only be invoked by FaceTable.
Davide Pesavento94279412015-02-27 01:29:32 +0100103 */
104 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700105 setId(FaceId id);
Davide Pesavento94279412015-02-27 01:29:32 +0100106
Junxiao Shicde37ad2015-12-24 01:02:05 -0700107 /** \return a FaceUri representing local endpoint
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100108 */
Junxiao Shicde37ad2015-12-24 01:02:05 -0700109 FaceUri
110 getLocalUri() const;
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100111
Junxiao Shicde37ad2015-12-24 01:02:05 -0700112 /** \return a FaceUri representing remote endpoint
113 */
114 FaceUri
115 getRemoteUri() const;
116
117 /** \return whether face is local or non-local for scope control purpose
118 */
119 ndn::nfd::FaceScope
120 getScope() const;
121
122 /** \return face persistency setting
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700123 */
Yukai Tu731f0d72015-07-04 11:14:44 +0800124 ndn::nfd::FacePersistency
125 getPersistency() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100126
Junxiao Shicde37ad2015-12-24 01:02:05 -0700127 /** \brief changes face persistency setting
Junxiao Shi08d07a72014-06-09 23:17:57 -0700128 */
129 void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700130 setPersistency(ndn::nfd::FacePersistency persistency);
Junxiao Shi08d07a72014-06-09 23:17:57 -0700131
Junxiao Shicde37ad2015-12-24 01:02:05 -0700132 /** \return whether face is point-to-point or multi-access
133 */
134 ndn::nfd::LinkType
135 getLinkType() const;
Davide Pesavento94279412015-02-27 01:29:32 +0100136
Junxiao Shicde37ad2015-12-24 01:02:05 -0700137public: // dynamic properties
138 /** \return face state
139 */
140 FaceState
141 getState() const;
Junxiao Shic099ddb2014-12-25 20:53:20 -0700142
Junxiao Shicde37ad2015-12-24 01:02:05 -0700143 /** \brief signals after face state changed
144 */
145 signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
146
Eric Newberryc64d30a2015-12-26 11:07:27 -0700147 /** \return expiration time of the face
148 * \retval time::steady_clock::TimePoint::max() the face has an indefinite lifetime
149 */
150 time::steady_clock::TimePoint
151 getExpirationTime() const;
152
Junxiao Shicde37ad2015-12-24 01:02:05 -0700153 /** \brief request the face to be closed
154 *
155 * This operation is effective only if face is in UP or DOWN state,
156 * otherwise it has no effect.
157 * The face changes state to CLOSING, and performs cleanup procedure.
158 * The state will be changed to CLOSED when cleanup is complete, which may
159 * happen synchronously or asynchronously.
160 *
161 * \warning the face must not be deallocated until its state changes to CLOSED
162 */
163 void
164 close();
165
166 const FaceCounters&
167 getCounters() const;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700168
169private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700170 FaceId m_id;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700171 unique_ptr<LinkService> m_service;
172 unique_ptr<Transport> m_transport;
173 FaceCounters m_counters;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700174};
175
Junxiao Shicde37ad2015-12-24 01:02:05 -0700176inline LinkService*
Eric Newberryc05918c2016-09-29 10:38:13 -0700177Face::getLinkService() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700178{
179 return m_service.get();
180}
181
182inline Transport*
Eric Newberryc05918c2016-09-29 10:38:13 -0700183Face::getTransport() const
Junxiao Shicde37ad2015-12-24 01:02:05 -0700184{
185 return m_transport.get();
186}
187
188inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000189Face::sendInterest(const Interest& interest, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700190{
ashiqopu075bb7d2019-03-10 01:38:21 +0000191 m_service->sendInterest(interest, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700192}
193
194inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000195Face::sendData(const Data& data, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700196{
ashiqopu075bb7d2019-03-10 01:38:21 +0000197 m_service->sendData(data, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700198}
199
200inline void
ashiqopu075bb7d2019-03-10 01:38:21 +0000201Face::sendNack(const lp::Nack& nack, const EndpointId& endpointId)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700202{
ashiqopu075bb7d2019-03-10 01:38:21 +0000203 m_service->sendNack(nack, endpointId);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700204}
205
Davide Pesavento94279412015-02-27 01:29:32 +0100206inline FaceId
207Face::getId() const
208{
209 return m_id;
210}
211
212inline void
Junxiao Shicde37ad2015-12-24 01:02:05 -0700213Face::setId(FaceId id)
Davide Pesavento94279412015-02-27 01:29:32 +0100214{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700215 m_id = id;
Davide Pesavento94279412015-02-27 01:29:32 +0100216}
217
Junxiao Shicde37ad2015-12-24 01:02:05 -0700218inline FaceUri
219Face::getLocalUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100220{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700221 return m_transport->getLocalUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100222}
223
Junxiao Shicde37ad2015-12-24 01:02:05 -0700224inline FaceUri
225Face::getRemoteUri() const
Davide Pesavento94279412015-02-27 01:29:32 +0100226{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700227 return m_transport->getRemoteUri();
Davide Pesavento94279412015-02-27 01:29:32 +0100228}
229
Junxiao Shicde37ad2015-12-24 01:02:05 -0700230inline ndn::nfd::FaceScope
231Face::getScope() const
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100232{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700233 return m_transport->getScope();
Davide Pesavento0ff10db2014-02-28 03:12:27 +0100234}
235
Yukai Tu731f0d72015-07-04 11:14:44 +0800236inline ndn::nfd::FacePersistency
237Face::getPersistency() const
Davide Pesavento94279412015-02-27 01:29:32 +0100238{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700239 return m_transport->getPersistency();
Davide Pesavento94279412015-02-27 01:29:32 +0100240}
241
242inline void
Yukai Tu731f0d72015-07-04 11:14:44 +0800243Face::setPersistency(ndn::nfd::FacePersistency persistency)
Davide Pesavento94279412015-02-27 01:29:32 +0100244{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700245 return m_transport->setPersistency(persistency);
Davide Pesavento94279412015-02-27 01:29:32 +0100246}
247
Junxiao Shicde37ad2015-12-24 01:02:05 -0700248inline ndn::nfd::LinkType
249Face::getLinkType() const
Davide Pesavento94279412015-02-27 01:29:32 +0100250{
Junxiao Shicde37ad2015-12-24 01:02:05 -0700251 return m_transport->getLinkType();
Davide Pesavento94279412015-02-27 01:29:32 +0100252}
253
Junxiao Shicde37ad2015-12-24 01:02:05 -0700254inline FaceState
255Face::getState() const
256{
257 return m_transport->getState();
258}
259
Eric Newberryc64d30a2015-12-26 11:07:27 -0700260inline time::steady_clock::TimePoint
261Face::getExpirationTime() const
262{
263 return m_transport->getExpirationTime();
264}
265
Junxiao Shicde37ad2015-12-24 01:02:05 -0700266inline void
267Face::close()
268{
269 m_transport->close();
270}
271
272inline const FaceCounters&
Junxiao Shi7860d482014-02-21 23:57:20 -0700273Face::getCounters() const
274{
Junxiao Shi7860d482014-02-21 23:57:20 -0700275 return m_counters;
276}
277
Junxiao Shicde37ad2015-12-24 01:02:05 -0700278std::ostream&
279operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000280
Junxiao Shicde37ad2015-12-24 01:02:05 -0700281} // namespace face
282
Junxiao Shicde37ad2015-12-24 01:02:05 -0700283using face::Face;
284
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800285} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700286
Eric Newberry41aba102017-11-01 16:42:13 -0700287#endif // NFD_DAEMON_FACE_FACE_HPP