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-2020, 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 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 
179  weak_ptr<Channel>
180  getChannel() const
181  {
182  return m_channel;
183  }
184 
188  void
189  setChannel(weak_ptr<Channel> channel)
190  {
191  m_channel = std::move(channel);
192  }
193 
194 private:
195  FaceId m_id;
196  unique_ptr<LinkService> m_service;
197  unique_ptr<Transport> m_transport;
198  FaceCounters m_counters;
199  weak_ptr<Channel> m_channel;
200 };
201 
202 inline LinkService*
204 {
205  return m_service.get();
206 }
207 
208 inline Transport*
210 {
211  return m_transport.get();
212 }
213 
214 inline void
216 {
217  m_transport->close();
218 }
219 
220 inline void
221 Face::sendInterest(const Interest& interest)
222 {
223  m_service->sendInterest(interest);
224 }
225 
226 inline void
227 Face::sendData(const Data& data)
228 {
229  m_service->sendData(data);
230 }
231 
232 inline void
233 Face::sendNack(const lp::Nack& nack)
234 {
235  m_service->sendNack(nack);
236 }
237 
238 inline FaceId
239 Face::getId() const
240 {
241  return m_id;
242 }
243 
244 inline void
246 {
247  m_id = id;
248 }
249 
250 inline FaceUri
252 {
253  return m_transport->getLocalUri();
254 }
255 
256 inline FaceUri
258 {
259  return m_transport->getRemoteUri();
260 }
261 
262 inline ndn::nfd::FaceScope
264 {
265  return m_transport->getScope();
266 }
267 
268 inline ndn::nfd::FacePersistency
270 {
271  return m_transport->getPersistency();
272 }
273 
274 inline void
275 Face::setPersistency(ndn::nfd::FacePersistency persistency)
276 {
277  return m_transport->setPersistency(persistency);
278 }
279 
280 inline ndn::nfd::LinkType
282 {
283  return m_transport->getLinkType();
284 }
285 
286 inline ssize_t
288 {
289  return m_service->getEffectiveMtu();
290 }
291 
292 inline FaceState
294 {
295  return m_transport->getState();
296 }
297 
298 inline time::steady_clock::TimePoint
300 {
301  return m_transport->getExpirationTime();
302 }
303 
304 inline const FaceCounters&
306 {
307  return m_counters;
308 }
309 
310 std::ostream&
311 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
312 
313 } // namespace face
314 
315 using face::Face;
316 
317 } // namespace nfd
318 
319 #endif // NFD_DAEMON_FACE_FACE_HPP
FaceUri getRemoteUri() const
Definition: face.hpp:257
FaceState getState() const
Definition: face.hpp:293
const FaceCounters & getCounters() const
Definition: face.hpp:305
TransportState
Indicates the state of a transport.
Definition: transport.hpp:37
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
Definition: face.hpp:275
signal::Signal< LinkService, Interest, EndpointId > & afterReceiveInterest
signals on Interest received
Definition: face.hpp:95
signal::Signal< LinkService, Data, EndpointId > & afterReceiveData
signals on Data received
Definition: face.hpp:99
ndn::nfd::FacePersistency getPersistency() const
Definition: face.hpp:269
The lower half of a Face.
Definition: transport.hpp:108
ndn::nfd::LinkType getLinkType() const
Definition: face.hpp:281
void setId(FaceId id)
sets face ID
Definition: face.hpp:245
ndn::nfd::FaceScope getScope() const
Definition: face.hpp:263
void close()
Request that the face be closed.
Definition: face.hpp:215
Transport * getTransport() const
Definition: face.hpp:209
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
TransportState FaceState
indicates the state of a face
Definition: face.hpp:37
FaceUri getLocalUri() const
Definition: face.hpp:251
weak_ptr< Channel > getChannel() const
Get channel on which face was created (unicast) or the associated channel (multicast) ...
Definition: face.hpp:180
generalization of a network interface
Definition: face.hpp:54
void sendData(const Data &data)
send Data
Definition: face.hpp:227
gives access to counters provided by Face
LinkService * getLinkService() const
Definition: face.hpp:203
FaceId getId() const
Definition: face.hpp:239
Face(unique_ptr< LinkService > service, unique_ptr< Transport > transport)
Definition: face.cpp:31
Represents a channel that listens on a local endpoint.
Definition: channel.hpp:41
void sendNack(const lp::Nack &nack)
send Nack
Definition: face.hpp:233
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
signals after face state changed
Definition: face.hpp:165
signal::Signal< LinkService, lp::Nack, EndpointId > & afterReceiveNack
signals on Nack received
Definition: face.hpp:103
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:221
void setChannel(weak_ptr< Channel > channel)
Set channel on which face was created (unicast) or the associated channel (multicast) ...
Definition: face.hpp:189
#define FINAL_UNLESS_WITH_TESTS
Definition: common.hpp:44
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:44
ssize_t getMtu() const
Returns face effective MTU.
Definition: face.hpp:287
time::steady_clock::TimePoint getExpirationTime() const
Definition: face.hpp:299