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-2019, 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 FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
68 {
69 public:
70  Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
71 
73  getLinkService() const;
74 
75  Transport*
76  getTransport() const;
77 
78 public: // upper interface connected to forwarding
81  void
82  sendInterest(const Interest& interest);
83 
86  void
87  sendData(const Data& data);
88 
91  void
92  sendNack(const lp::Nack& nack);
93 
96  signal::Signal<LinkService, Interest>& afterReceiveInterest;
97 
100  signal::Signal<LinkService, Data>& afterReceiveData;
101 
104  signal::Signal<LinkService, lp::Nack>& afterReceiveNack;
105 
108  signal::Signal<LinkService, Interest>& onDroppedInterest;
109 
110 public: // static properties
113  FaceId
114  getId() const;
115 
119  void
120  setId(FaceId id);
121 
124  FaceUri
125  getLocalUri() const;
126 
129  FaceUri
130  getRemoteUri() const;
131 
134  ndn::nfd::FaceScope
135  getScope() const;
136 
139  ndn::nfd::FacePersistency
140  getPersistency() const;
141 
144  void
145  setPersistency(ndn::nfd::FacePersistency persistency);
146 
149  ndn::nfd::LinkType
150  getLinkType() const;
151 
152 public: // dynamic properties
155  FaceState
156  getState() const;
157 
160  signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
161 
165  time::steady_clock::TimePoint
166  getExpirationTime() const;
167 
178  void
179  close();
180 
181  const FaceCounters&
182  getCounters() const;
183 
184 private:
185  FaceId m_id;
186  unique_ptr<LinkService> m_service;
187  unique_ptr<Transport> m_transport;
188  FaceCounters m_counters;
189 };
190 
191 inline LinkService*
193 {
194  return m_service.get();
195 }
196 
197 inline Transport*
199 {
200  return m_transport.get();
201 }
202 
203 inline void
204 Face::sendInterest(const Interest& interest)
205 {
206  m_service->sendInterest(interest);
207 }
208 
209 inline void
210 Face::sendData(const Data& data)
211 {
212  m_service->sendData(data);
213 }
214 
215 inline void
216 Face::sendNack(const lp::Nack& nack)
217 {
218  m_service->sendNack(nack);
219 }
220 
221 inline FaceId
222 Face::getId() const
223 {
224  return m_id;
225 }
226 
227 inline void
228 Face::setId(FaceId id)
229 {
230  m_id = id;
231 }
232 
233 inline FaceUri
235 {
236  return m_transport->getLocalUri();
237 }
238 
239 inline FaceUri
241 {
242  return m_transport->getRemoteUri();
243 }
244 
245 inline ndn::nfd::FaceScope
247 {
248  return m_transport->getScope();
249 }
250 
251 inline ndn::nfd::FacePersistency
253 {
254  return m_transport->getPersistency();
255 }
256 
257 inline void
258 Face::setPersistency(ndn::nfd::FacePersistency persistency)
259 {
260  return m_transport->setPersistency(persistency);
261 }
262 
263 inline ndn::nfd::LinkType
265 {
266  return m_transport->getLinkType();
267 }
268 
269 inline FaceState
271 {
272  return m_transport->getState();
273 }
274 
275 inline time::steady_clock::TimePoint
277 {
278  return m_transport->getExpirationTime();
279 }
280 
281 inline void
283 {
284  m_transport->close();
285 }
286 
287 inline const FaceCounters&
289 {
290  return m_counters;
291 }
292 
293 std::ostream&
294 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
295 
296 } // namespace face
297 
298 using face::EndpointId;
299 using face::FaceId;
300 using face::Face;
301 
302 } // namespace nfd
303 
304 #endif // NFD_DAEMON_FACE_FACE_HPP
LinkService * getLinkService() const
Definition: face.hpp:192
TransportState
indicates the state of a transport
Definition: transport.hpp:46
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
Definition: face.hpp:258
Transport * getTransport() const
Definition: face.hpp:198
signal::Signal< LinkService, lp::Nack > & afterReceiveNack
signals on Nack received
Definition: face.hpp:104
signal::Signal< LinkService, Interest > & afterReceiveInterest
signals on Interest received
Definition: face.hpp:96
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
Definition: face.hpp:44
const FaceCounters & getCounters() const
Definition: face.hpp:288
FaceUri getRemoteUri() const
Definition: face.hpp:240
FaceState getState() const
Definition: face.hpp:270
the lower part of a Face
Definition: transport.hpp:117
void setId(FaceId id)
sets face ID
Definition: face.hpp:228
void close()
request the face to be closed
Definition: face.hpp:282
signal::Signal< LinkService, Data > & afterReceiveData
signals on Data received
Definition: face.hpp:100
uint64_t EndpointId
identifies an endpoint on the link
Definition: transport.hpp:38
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:276
generalization of a network interface
Definition: face.hpp:67
FaceId getId() const
Definition: face.hpp:222
void sendData(const Data &data)
sends Data on Face
Definition: face.hpp:210
gives access to counters provided by Face
FaceUri getLocalUri() const
Definition: face.hpp:234
Face(unique_ptr< LinkService > service, unique_ptr< Transport > transport)
Definition: face.cpp:31
ndn::nfd::LinkType getLinkType() const
Definition: face.hpp:264
void sendNack(const lp::Nack &nack)
sends Nack on Face
Definition: face.hpp:216
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
signals after face state changed
Definition: face.hpp:160
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:108
void sendInterest(const Interest &interest)
sends Interest on Face
Definition: face.hpp:204
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:252
#define FINAL_UNLESS_WITH_TESTS
Definition: common.hpp:44
ndn::nfd::FaceScope getScope() const
Definition: face.hpp:246
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:42