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-2021, 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 
42 
54 class Face NFD_FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
55 {
56 public:
57  Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
58 
60  getLinkService() const;
61 
62  Transport*
63  getTransport() const;
64 
74  void
75  close();
76 
77 public: // upper interface connected to forwarding
80  void
81  sendInterest(const Interest& interest);
82 
85  void
86  sendData(const Data& data);
87 
90  void
91  sendNack(const lp::Nack& nack);
92 
95  signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
96 
99  signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
100 
103  signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
104 
107  signal::Signal<LinkService, Interest>& onDroppedInterest;
108 
109 public: // properties
112  FaceId
113  getId() const;
114 
118  void
119  setId(FaceId id);
120 
123  FaceUri
124  getLocalUri() const;
125 
128  FaceUri
129  getRemoteUri() const;
130 
133  ndn::nfd::FaceScope
134  getScope() const;
135 
138  ndn::nfd::FacePersistency
139  getPersistency() const;
140 
143  void
144  setPersistency(ndn::nfd::FacePersistency persistency);
145 
148  ndn::nfd::LinkType
149  getLinkType() const;
150 
155  ssize_t
156  getMtu() const;
157 
160  FaceState
161  getState() const;
162 
165  signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
166 
170  time::steady_clock::TimePoint
171  getExpirationTime() const;
172 
173  const FaceCounters&
174  getCounters() const
175  {
176  return m_counters;
177  }
178 
179  FaceCounters&
181  {
182  return m_counters;
183  }
184 
188  weak_ptr<Channel>
189  getChannel() const
190  {
191  return m_channel;
192  }
193 
197  void
198  setChannel(weak_ptr<Channel> channel)
199  {
200  m_channel = std::move(channel);
201  }
202 
203 private:
204  FaceId m_id;
205  unique_ptr<LinkService> m_service;
206  unique_ptr<Transport> m_transport;
207  FaceCounters m_counters;
208  weak_ptr<Channel> m_channel;
209 };
210 
211 inline LinkService*
213 {
214  return m_service.get();
215 }
216 
217 inline Transport*
219 {
220  return m_transport.get();
221 }
222 
223 inline void
225 {
226  m_transport->close();
227 }
228 
229 inline void
230 Face::sendInterest(const Interest& interest)
231 {
232  m_service->sendInterest(interest);
233 }
234 
235 inline void
236 Face::sendData(const Data& data)
237 {
238  m_service->sendData(data);
239 }
240 
241 inline void
242 Face::sendNack(const lp::Nack& nack)
243 {
244  m_service->sendNack(nack);
245 }
246 
247 inline FaceId
248 Face::getId() const
249 {
250  return m_id;
251 }
252 
253 inline void
255 {
256  m_id = id;
257 }
258 
259 inline FaceUri
261 {
262  return m_transport->getLocalUri();
263 }
264 
265 inline FaceUri
267 {
268  return m_transport->getRemoteUri();
269 }
270 
271 inline ndn::nfd::FaceScope
273 {
274  return m_transport->getScope();
275 }
276 
277 inline ndn::nfd::FacePersistency
279 {
280  return m_transport->getPersistency();
281 }
282 
283 inline void
284 Face::setPersistency(ndn::nfd::FacePersistency persistency)
285 {
286  return m_transport->setPersistency(persistency);
287 }
288 
289 inline ndn::nfd::LinkType
291 {
292  return m_transport->getLinkType();
293 }
294 
295 inline ssize_t
297 {
298  return m_service->getEffectiveMtu();
299 }
300 
301 inline FaceState
303 {
304  return m_transport->getState();
305 }
306 
307 inline time::steady_clock::TimePoint
309 {
310  return m_transport->getExpirationTime();
311 }
312 
313 std::ostream&
314 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
315 
316 } // namespace face
317 
318 using face::Face;
319 
320 } // namespace nfd
321 
322 #endif // NFD_DAEMON_FACE_FACE_HPP
gives access to counters provided by Face
generalization of a network interface
Definition: face.hpp:55
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
signals after face state changed
Definition: face.hpp:165
Face(unique_ptr< LinkService > service, unique_ptr< Transport > transport)
Definition: face.cpp:31
ndn::nfd::FaceScope getScope() const
Definition: face.hpp:272
FaceUri getRemoteUri() const
Definition: face.hpp:266
signal::Signal< LinkService, Data, EndpointId > & afterReceiveData
signals on Data received
Definition: face.hpp:99
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
Definition: face.hpp:284
signal::Signal< LinkService, Interest > & onDroppedInterest
signals on Interest dropped by reliability system for exceeding allowed number of retx
Definition: face.hpp:107
void sendInterest(const Interest &interest)
send Interest
Definition: face.hpp:230
signal::Signal< LinkService, lp::Nack, EndpointId > & afterReceiveNack
signals on Nack received
Definition: face.hpp:103
time::steady_clock::TimePoint getExpirationTime() const
Definition: face.hpp:308
Transport * getTransport() const
Definition: face.hpp:218
ndn::nfd::FacePersistency getPersistency() const
Definition: face.hpp:278
weak_ptr< Channel > getChannel() const
Get channel on which face was created (unicast) or the associated channel (multicast)
Definition: face.hpp:189
void setChannel(weak_ptr< Channel > channel)
Set channel on which face was created (unicast) or the associated channel (multicast)
Definition: face.hpp:198
ssize_t getMtu() const
Returns face effective MTU.
Definition: face.hpp:296
LinkService * getLinkService() const
Definition: face.hpp:212
void sendNack(const lp::Nack &nack)
send Nack
Definition: face.hpp:242
signal::Signal< LinkService, Interest, EndpointId > & afterReceiveInterest
signals on Interest received
Definition: face.hpp:95
void close()
Request that the face be closed.
Definition: face.hpp:224
FaceId getId() const
Definition: face.hpp:248
FaceUri getLocalUri() const
Definition: face.hpp:260
FaceState getState() const
Definition: face.hpp:302
void sendData(const Data &data)
send Data
Definition: face.hpp:236
const FaceCounters & getCounters() const
Definition: face.hpp:174
void setId(FaceId id)
sets face ID
Definition: face.hpp:254
FaceCounters & getCounters()
Definition: face.hpp:180
ndn::nfd::LinkType getLinkType() const
Definition: face.hpp:290
For internal use by FaceLogging macros.
Definition: face-common.hpp:99
The lower half of a Face.
Definition: transport.hpp:109
#define NFD_FINAL_UNLESS_WITH_TESTS
Definition: common.hpp:44
std::ostream & operator<<(std::ostream &os, const FaceLogHelper< Face > &flh)
Definition: face.cpp:47
TransportState
Indicates the state of a transport.
Definition: transport.hpp:37
TransportState FaceState
indicates the state of a face
Definition: face.hpp:37
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:44
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents,...
Definition: algorithm.hpp:32