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-2018, 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-counters.hpp"
30 #include "face-log.hpp"
31 #include "link-service.hpp"
32 #include "transport.hpp"
33 
34 namespace nfd {
35 namespace face {
36 
39 typedef uint64_t FaceId;
40 
42 const FaceId INVALID_FACEID = 0;
44 const FaceId FACEID_INTERNAL_FACE = 1;
46 const FaceId FACEID_CONTENT_STORE = 254;
48 const FaceId FACEID_NULL = 255;
50 const FaceId FACEID_RESERVED_MAX = 255;
51 
55 
67 class Face
68 #ifndef WITH_TESTS
69 final
70 #endif
71  : public std::enable_shared_from_this<Face>, noncopyable
72 {
73 public:
74  Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
75 
77  getLinkService() const;
78 
79  Transport*
80  getTransport() const;
81 
82 public: // upper interface connected to forwarding
85  void
86  sendInterest(const Interest& interest);
87 
90  void
91  sendData(const Data& data);
92 
95  void
96  sendNack(const lp::Nack& nack);
97 
100  signal::Signal<LinkService, Interest>& afterReceiveInterest;
101 
104  signal::Signal<LinkService, Data>& afterReceiveData;
105 
108  signal::Signal<LinkService, lp::Nack>& afterReceiveNack;
109 
112  signal::Signal<LinkService, Interest>& onDroppedInterest;
113 
114 public: // static properties
117  FaceId
118  getId() const;
119 
123  void
124  setId(FaceId id);
125 
128  FaceUri
129  getLocalUri() const;
130 
133  FaceUri
134  getRemoteUri() const;
135 
138  ndn::nfd::FaceScope
139  getScope() const;
140 
143  ndn::nfd::FacePersistency
144  getPersistency() const;
145 
148  void
149  setPersistency(ndn::nfd::FacePersistency persistency);
150 
153  ndn::nfd::LinkType
154  getLinkType() const;
155 
156 public: // dynamic properties
159  FaceState
160  getState() const;
161 
164  signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
165 
169  time::steady_clock::TimePoint
170  getExpirationTime() const;
171 
182  void
183  close();
184 
185  const FaceCounters&
186  getCounters() const;
187 
188 private:
189  FaceId m_id;
190  unique_ptr<LinkService> m_service;
191  unique_ptr<Transport> m_transport;
192  FaceCounters m_counters;
193 };
194 
195 inline LinkService*
197 {
198  return m_service.get();
199 }
200 
201 inline Transport*
203 {
204  return m_transport.get();
205 }
206 
207 inline void
208 Face::sendInterest(const Interest& interest)
209 {
210  m_service->sendInterest(interest);
211 }
212 
213 inline void
214 Face::sendData(const Data& data)
215 {
216  m_service->sendData(data);
217 }
218 
219 inline void
220 Face::sendNack(const lp::Nack& nack)
221 {
222  m_service->sendNack(nack);
223 }
224 
225 inline FaceId
226 Face::getId() const
227 {
228  return m_id;
229 }
230 
231 inline void
232 Face::setId(FaceId id)
233 {
234  m_id = id;
235 }
236 
237 inline FaceUri
239 {
240  return m_transport->getLocalUri();
241 }
242 
243 inline FaceUri
245 {
246  return m_transport->getRemoteUri();
247 }
248 
249 inline ndn::nfd::FaceScope
251 {
252  return m_transport->getScope();
253 }
254 
255 inline ndn::nfd::FacePersistency
257 {
258  return m_transport->getPersistency();
259 }
260 
261 inline void
262 Face::setPersistency(ndn::nfd::FacePersistency persistency)
263 {
264  return m_transport->setPersistency(persistency);
265 }
266 
267 inline ndn::nfd::LinkType
269 {
270  return m_transport->getLinkType();
271 }
272 
273 inline FaceState
275 {
276  return m_transport->getState();
277 }
278 
279 inline time::steady_clock::TimePoint
281 {
282  return m_transport->getExpirationTime();
283 }
284 
285 inline void
287 {
288  m_transport->close();
289 }
290 
291 inline const FaceCounters&
293 {
294  return m_counters;
295 }
296 
297 std::ostream&
298 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
299 
300 } // namespace face
301 
302 using face::FaceId;
303 using face::Face;
304 
305 } // namespace nfd
306 
307 #endif // NFD_DAEMON_FACE_FACE_HPP
LinkService * getLinkService() const
Definition: face.hpp:196
TransportState
indicates the state of a transport
Definition: transport.hpp:42
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
Definition: face.hpp:262
Transport * getTransport() const
Definition: face.hpp:202
signal::Signal< LinkService, lp::Nack > & afterReceiveNack
signals on Nack received
Definition: face.hpp:108
signal::Signal< LinkService, Interest > & afterReceiveInterest
signals on Interest received
Definition: face.hpp:100
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
Definition: face.hpp:44
const FaceCounters & getCounters() const
Definition: face.hpp:292
FaceUri getRemoteUri() const
Definition: face.hpp:244
FaceState getState() const
Definition: face.hpp:274
the lower part of a Face
Definition: transport.hpp:113
void setId(FaceId id)
sets face ID
Definition: face.hpp:232
void close()
request the face to be closed
Definition: face.hpp:286
signal::Signal< LinkService, Data > & afterReceiveData
signals on Data received
Definition: face.hpp:104
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:54
const FaceId FACEID_RESERVED_MAX
upper bound of reserved FaceIds
Definition: face.hpp:50
time::steady_clock::TimePoint getExpirationTime() const
Definition: face.hpp:280
generalization of a network interface
Definition: face.hpp:67
FaceId getId() const
Definition: face.hpp:226
void sendData(const Data &data)
sends Data on Face
Definition: face.hpp:214
gives access to counters provided by Face
FaceUri getLocalUri() const
Definition: face.hpp:238
Face(unique_ptr< LinkService > service, unique_ptr< Transport > transport)
Definition: face.cpp:31
ndn::nfd::LinkType getLinkType() const
Definition: face.hpp:268
void sendNack(const lp::Nack &nack)
sends Nack on Face
Definition: face.hpp:220
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
signals after face state changed
Definition: face.hpp:164
const FaceId FACEID_NULL
identifies the NullFace that drops every packet
Definition: face.hpp:48
signal::Signal< LinkService, Interest > & onDroppedInterest
signals on Interest dropped by reliability system for exceeding allowed number of retx ...
Definition: face.hpp:112
void sendInterest(const Interest &interest)
sends Interest on Face
Definition: face.hpp:208
uint64_t FaceId
identifies a face
Definition: face.hpp:39
const FaceId FACEID_CONTENT_STORE
identifies a packet comes from the ContentStore
Definition: face.hpp:46
ndn::nfd::FacePersistency getPersistency() const
Definition: face.hpp:256
ndn::nfd::FaceScope getScope() const
Definition: face.hpp:250
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:42