face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, Regents of the University of California,
4  * 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.
10  *
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/>.
24  */
25 
26 #ifndef NFD_DAEMON_FACE_FACE_HPP
27 #define NFD_DAEMON_FACE_FACE_HPP
28 
29 #include "face-common.hpp"
30 #include "face-counters.hpp"
31 #include "link-service.hpp"
32 #include "transport.hpp"
33 
34 namespace nfd {
35 namespace face {
36 
37 class Channel;
38 
43 
55 class Face NFD_FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
56 {
57 public:
58  Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
59 
61  getLinkService() const noexcept
62  {
63  return m_service.get();
64  }
65 
66  Transport*
67  getTransport() const noexcept
68  {
69  return m_transport.get();
70  }
71 
81  void
82  close();
83 
84 public: // upper interface connected to forwarding
87  void
88  sendInterest(const Interest& interest);
89 
92  void
93  sendData(const Data& data);
94 
97  void
98  sendNack(const lp::Nack& nack);
99 
102  signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
103 
106  signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
107 
110  signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
111 
114  signal::Signal<LinkService, Interest>& onDroppedInterest;
115 
116 public: // properties
120  FaceId
121  getId() const noexcept
122  {
123  return m_id;
124  }
125 
130  void
131  setId(FaceId id) noexcept
132  {
133  m_id = id;
134  }
135 
139  FaceUri
140  getLocalUri() const;
141 
145  FaceUri
146  getRemoteUri() const;
147 
151  ndn::nfd::FaceScope
152  getScope() const;
153 
157  ndn::nfd::FacePersistency
158  getPersistency() const;
159 
163  void
164  setPersistency(ndn::nfd::FacePersistency persistency);
165 
169  ndn::nfd::LinkType
170  getLinkType() const;
171 
177  ssize_t
178  getMtu() const;
179 
183  FaceState
184  getState() const;
185 
189  signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
190 
195  time::steady_clock::time_point
196  getExpirationTime() const;
197 
198  const FaceCounters&
199  getCounters() const noexcept
200  {
201  return m_counters;
202  }
203 
204  FaceCounters&
205  getCounters() noexcept
206  {
207  return m_counters;
208  }
209 
213  weak_ptr<Channel>
214  getChannel() const
215  {
216  return m_channel;
217  }
218 
222  void
223  setChannel(weak_ptr<Channel> channel)
224  {
225  m_channel = std::move(channel);
226  }
227 
228 private:
229  FaceId m_id = INVALID_FACEID;
230  unique_ptr<LinkService> m_service;
231  unique_ptr<Transport> m_transport;
232  FaceCounters m_counters;
233  weak_ptr<Channel> m_channel;
234 };
235 
236 inline void
238 {
239  m_transport->close();
240 }
241 
242 inline void
243 Face::sendInterest(const Interest& interest)
244 {
245  m_service->sendInterest(interest);
246 }
247 
248 inline void
249 Face::sendData(const Data& data)
250 {
251  m_service->sendData(data);
252 }
253 
254 inline void
255 Face::sendNack(const lp::Nack& nack)
256 {
257  m_service->sendNack(nack);
258 }
259 
260 inline FaceUri
262 {
263  return m_transport->getLocalUri();
264 }
265 
266 inline FaceUri
268 {
269  return m_transport->getRemoteUri();
270 }
271 
272 inline ndn::nfd::FaceScope
274 {
275  return m_transport->getScope();
276 }
277 
278 inline ndn::nfd::FacePersistency
280 {
281  return m_transport->getPersistency();
282 }
283 
284 inline void
285 Face::setPersistency(ndn::nfd::FacePersistency persistency)
286 {
287  return m_transport->setPersistency(persistency);
288 }
289 
290 inline ndn::nfd::LinkType
292 {
293  return m_transport->getLinkType();
294 }
295 
296 inline ssize_t
298 {
299  return m_service->getEffectiveMtu();
300 }
301 
302 inline FaceState
304 {
305  return m_transport->getState();
306 }
307 
308 inline time::steady_clock::time_point
310 {
311  return m_transport->getExpirationTime();
312 }
313 
314 std::ostream&
315 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
316 
317 } // namespace face
318 
319 using face::Face;
320 
321 } // namespace nfd
322 
323 #endif // NFD_DAEMON_FACE_FACE_HPP
Gives access to counters provided by Face.
Generalization of a network interface.
Definition: face.hpp:56
time::steady_clock::time_point getExpirationTime() const
Returns the expiration time of the face.
Definition: face.hpp:309
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
Signals after face state changed.
Definition: face.hpp:189
Face(unique_ptr< LinkService > service, unique_ptr< Transport > transport)
Definition: face.cpp:30
ndn::nfd::FaceScope getScope() const
Returns whether the face is local or non-local for scope control purposes.
Definition: face.hpp:273
FaceUri getRemoteUri() const
Returns a FaceUri representing the remote endpoint.
Definition: face.hpp:267
signal::Signal< LinkService, Data, EndpointId > & afterReceiveData
Signals on Data received.
Definition: face.hpp:106
FaceCounters & getCounters() noexcept
Definition: face.hpp:205
void setPersistency(ndn::nfd::FacePersistency persistency)
Changes the face persistency setting.
Definition: face.hpp:285
signal::Signal< LinkService, Interest > & onDroppedInterest
Signals on Interest dropped by reliability system for exceeding allowed number of retx.
Definition: face.hpp:114
void sendInterest(const Interest &interest)
Send Interest.
Definition: face.hpp:243
signal::Signal< LinkService, lp::Nack, EndpointId > & afterReceiveNack
Signals on Nack received.
Definition: face.hpp:110
ndn::nfd::FacePersistency getPersistency() const
Returns the current persistency setting of the face.
Definition: face.hpp:279
weak_ptr< Channel > getChannel() const
Get channel on which face was created (unicast) or the associated channel (multicast).
Definition: face.hpp:214
void setId(FaceId id) noexcept
Sets the face ID.
Definition: face.hpp:131
void setChannel(weak_ptr< Channel > channel)
Set channel on which face was created (unicast) or the associated channel (multicast).
Definition: face.hpp:223
ssize_t getMtu() const
Returns the effective MTU of the face.
Definition: face.hpp:297
LinkService * getLinkService() const noexcept
Definition: face.hpp:61
FaceId getId() const noexcept
Returns the face ID.
Definition: face.hpp:121
void sendNack(const lp::Nack &nack)
Send Nack.
Definition: face.hpp:255
signal::Signal< LinkService, Interest, EndpointId > & afterReceiveInterest
Signals on Interest received.
Definition: face.hpp:102
void close()
Request that the face be closed.
Definition: face.hpp:237
FaceUri getLocalUri() const
Returns a FaceUri representing the local endpoint.
Definition: face.hpp:261
FaceState getState() const
Returns the face state.
Definition: face.hpp:303
const FaceCounters & getCounters() const noexcept
Definition: face.hpp:199
void sendData(const Data &data)
Send Data.
Definition: face.hpp:249
ndn::nfd::LinkType getLinkType() const
Returns the link type of the face (point-to-point, multi-access, ...).
Definition: face.hpp:291
Transport * getTransport() const noexcept
Definition: face.hpp:67
For internal use by FaceLogging macros.
The lower half of a Face.
Definition: transport.hpp:114
#define NFD_FINAL_UNLESS_WITH_TESTS
Definition: common.hpp:44
std::ostream & operator<<(std::ostream &os, const FaceLogHelper< Face > &flh)
Definition: face.cpp:45
TransportState
Indicates the state of a transport.
Definition: transport.hpp:37
constexpr FaceId INVALID_FACEID
Indicates an invalid FaceId.
Definition: face-common.hpp:50
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:47
Definition: common.hpp:77