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-common.hpp"
30 #include "face-counters.hpp"
31 #include "link-service.hpp"
32 #include "transport.hpp"
33 
34 namespace nfd {
35 namespace face {
36 
40 
52 class Face FINAL_UNLESS_WITH_TESTS : public std::enable_shared_from_this<Face>, noncopyable
53 {
54 public:
55  Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
56 
58  getLinkService() const;
59 
60  Transport*
61  getTransport() const;
62 
63 public: // upper interface connected to forwarding
66  void
67  sendInterest(const Interest& interest, const EndpointId& endpointId);
68 
71  void
72  sendData(const Data& data, const EndpointId& endpointId);
73 
76  void
77  sendNack(const lp::Nack& nack, const EndpointId& endpointId);
78 
81  signal::Signal<LinkService, Interest, EndpointId>& afterReceiveInterest;
82 
85  signal::Signal<LinkService, Data, EndpointId>& afterReceiveData;
86 
89  signal::Signal<LinkService, lp::Nack, EndpointId>& afterReceiveNack;
90 
93  signal::Signal<LinkService, Interest>& onDroppedInterest;
94 
95 public: // static properties
98  FaceId
99  getId() const;
100 
104  void
105  setId(FaceId id);
106 
109  FaceUri
110  getLocalUri() const;
111 
114  FaceUri
115  getRemoteUri() const;
116 
119  ndn::nfd::FaceScope
120  getScope() const;
121 
124  ndn::nfd::FacePersistency
125  getPersistency() const;
126 
129  void
130  setPersistency(ndn::nfd::FacePersistency persistency);
131 
134  ndn::nfd::LinkType
135  getLinkType() const;
136 
137 public: // dynamic properties
140  FaceState
141  getState() const;
142 
145  signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
146 
150  time::steady_clock::TimePoint
151  getExpirationTime() const;
152 
163  void
164  close();
165 
166  const FaceCounters&
167  getCounters() const;
168 
169 private:
170  FaceId m_id;
171  unique_ptr<LinkService> m_service;
172  unique_ptr<Transport> m_transport;
173  FaceCounters m_counters;
174 };
175 
176 inline LinkService*
178 {
179  return m_service.get();
180 }
181 
182 inline Transport*
184 {
185  return m_transport.get();
186 }
187 
188 inline void
189 Face::sendInterest(const Interest& interest, const EndpointId& endpointId)
190 {
191  m_service->sendInterest(interest, endpointId);
192 }
193 
194 inline void
195 Face::sendData(const Data& data, const EndpointId& endpointId)
196 {
197  m_service->sendData(data, endpointId);
198 }
199 
200 inline void
201 Face::sendNack(const lp::Nack& nack, const EndpointId& endpointId)
202 {
203  m_service->sendNack(nack, endpointId);
204 }
205 
206 inline FaceId
207 Face::getId() const
208 {
209  return m_id;
210 }
211 
212 inline void
214 {
215  m_id = id;
216 }
217 
218 inline FaceUri
220 {
221  return m_transport->getLocalUri();
222 }
223 
224 inline FaceUri
226 {
227  return m_transport->getRemoteUri();
228 }
229 
230 inline ndn::nfd::FaceScope
232 {
233  return m_transport->getScope();
234 }
235 
236 inline ndn::nfd::FacePersistency
238 {
239  return m_transport->getPersistency();
240 }
241 
242 inline void
243 Face::setPersistency(ndn::nfd::FacePersistency persistency)
244 {
245  return m_transport->setPersistency(persistency);
246 }
247 
248 inline ndn::nfd::LinkType
250 {
251  return m_transport->getLinkType();
252 }
253 
254 inline FaceState
256 {
257  return m_transport->getState();
258 }
259 
260 inline time::steady_clock::TimePoint
262 {
263  return m_transport->getExpirationTime();
264 }
265 
266 inline void
268 {
269  m_transport->close();
270 }
271 
272 inline const FaceCounters&
274 {
275  return m_counters;
276 }
277 
278 std::ostream&
279 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
280 
281 } // namespace face
282 
283 using face::Face;
284 
285 } // namespace nfd
286 
287 #endif // NFD_DAEMON_FACE_FACE_HPP
FaceUri getRemoteUri() const
Definition: face.hpp:225
FaceState getState() const
Definition: face.hpp:255
const FaceCounters & getCounters() const
Definition: face.hpp:273
TransportState
Indicates the state of a transport.
Definition: transport.hpp:37
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
Definition: face.hpp:243
signal::Signal< LinkService, Interest, EndpointId > & afterReceiveInterest
signals on Interest received
Definition: face.hpp:81
void sendData(const Data &data, const EndpointId &endpointId)
send Data to endpointId
Definition: face.hpp:195
signal::Signal< LinkService, Data, EndpointId > & afterReceiveData
signals on Data received
Definition: face.hpp:85
ndn::nfd::FacePersistency getPersistency() const
Definition: face.hpp:237
The lower half of a Face.
Definition: transport.hpp:108
void sendInterest(const Interest &interest, const EndpointId &endpointId)
send Interest to endpointId
Definition: face.hpp:189
uint64_t EndpointId
Identifies a remote endpoint on the link.
Definition: face-common.hpp:65
ndn::nfd::LinkType getLinkType() const
Definition: face.hpp:249
void setId(FaceId id)
sets face ID
Definition: face.hpp:213
ndn::nfd::FaceScope getScope() const
Definition: face.hpp:231
void close()
request the face to be closed
Definition: face.hpp:267
Transport * getTransport() const
Definition: face.hpp:183
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:39
FaceUri getLocalUri() const
Definition: face.hpp:219
generalization of a network interface
Definition: face.hpp:52
gives access to counters provided by Face
LinkService * getLinkService() const
Definition: face.hpp:177
FaceId getId() const
Definition: face.hpp:207
Face(unique_ptr< LinkService > service, unique_ptr< Transport > transport)
Definition: face.cpp:31
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
signals after face state changed
Definition: face.hpp:145
signal::Signal< LinkService, lp::Nack, EndpointId > & afterReceiveNack
signals on Nack received
Definition: face.hpp:89
signal::Signal< LinkService, Interest > & onDroppedInterest
signals on Interest dropped by reliability system for exceeding allowed number of retx ...
Definition: face.hpp:93
#define FINAL_UNLESS_WITH_TESTS
Definition: common.hpp:44
uint64_t FaceId
Identifies a face.
Definition: face-common.hpp:44
time::steady_clock::TimePoint getExpirationTime() const
Definition: face.hpp:261
void sendNack(const lp::Nack &nack, const EndpointId &endpointId)
send Nack to endpointId
Definition: face.hpp:201