NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_HPP
27 #define NFD_DAEMON_FACE_HPP
28 
29 #include "transport.hpp"
30 #include "link-service.hpp"
31 #include "face-counters.hpp"
32 #include "face-log.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
70 #endif
71  : public enable_shared_from_this<Face>, noncopyable
72 {
73 public:
74  Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
75 
77  getLinkService();
78 
79  Transport*
80  getTransport();
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 
101 
105 
109 
110 public: // static properties
113  FaceId
114  getId() const;
115 
119  void
120  setId(FaceId id);
121 
122  void
123  setMetric(uint64_t metric);
124 
125  uint64_t
126  getMetric() const;
127 
130  FaceUri
131  getLocalUri() const;
132 
135  FaceUri
136  getRemoteUri() const;
137 
141  getScope() const;
142 
146  getPersistency() const;
147 
150  void
151  setPersistency(ndn::nfd::FacePersistency persistency);
152 
156  getLinkType() const;
157 
158 public: // dynamic properties
161  FaceState
162  getState() const;
163 
166  signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
167 
172  getExpirationTime() const;
173 
184  void
185  close();
186 
187  const FaceCounters&
188  getCounters() const;
189 
190 private:
191  FaceId m_id;
192  unique_ptr<LinkService> m_service;
193  unique_ptr<Transport> m_transport;
194  FaceCounters m_counters;
195  uint64_t m_metric;
196 };
197 
198 inline LinkService*
199 Face::getLinkService()
200 {
201  return m_service.get();
202 }
203 
204 inline Transport*
205 Face::getTransport()
206 {
207  return m_transport.get();
208 }
209 
210 inline void
211 Face::sendInterest(const Interest& interest)
212 {
213  m_service->sendInterest(interest);
214 }
215 
216 inline void
217 Face::sendData(const Data& data)
218 {
219  m_service->sendData(data);
220 }
221 
222 inline void
223 Face::sendNack(const lp::Nack& nack)
224 {
225  m_service->sendNack(nack);
226 }
227 
228 inline FaceId
229 Face::getId() const
230 {
231  return m_id;
232 }
233 
234 inline void
235 Face::setId(FaceId id)
236 {
237  m_id = id;
238 }
239 
240 inline void
241 Face::setMetric(uint64_t metric)
242 {
243  m_metric = metric;
244 }
245 
246 inline uint64_t
247 Face::getMetric() const
248 {
249  return m_metric;
250 }
251 
252 inline FaceUri
253 Face::getLocalUri() const
254 {
255  return m_transport->getLocalUri();
256 }
257 
258 inline FaceUri
259 Face::getRemoteUri() const
260 {
261  return m_transport->getRemoteUri();
262 }
263 
264 inline ndn::nfd::FaceScope
265 Face::getScope() const
266 {
267  return m_transport->getScope();
268 }
269 
271 Face::getPersistency() const
272 {
273  return m_transport->getPersistency();
274 }
275 
276 inline void
277 Face::setPersistency(ndn::nfd::FacePersistency persistency)
278 {
279  return m_transport->setPersistency(persistency);
280 }
281 
282 inline ndn::nfd::LinkType
283 Face::getLinkType() const
284 {
285  return m_transport->getLinkType();
286 }
287 
288 inline FaceState
289 Face::getState() const
290 {
291  return m_transport->getState();
292 }
293 
295 Face::getExpirationTime() const
296 {
297  return m_transport->getExpirationTime();
298 }
299 
300 inline void
301 Face::close()
302 {
303  m_transport->close();
304 }
305 
306 inline const FaceCounters&
307 Face::getCounters() const
308 {
309  return m_counters;
310 }
311 
312 std::ostream&
313 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
314 
315 template<typename T>
316 typename std::enable_if<std::is_base_of<Face, T>::value, std::ostream&>::type
317 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
318 {
319  return os << FaceLogHelper<Face>(flh.obj);
320 }
321 
322 } // namespace face
323 
324 using face::FaceId;
325 using face::Face;
326 
327 } // namespace nfd
328 
329 #endif // NFD_DAEMON_FACE_HPP
time_point TimePoint
Definition: time.hpp:108
the upper part of a Face
signal::Signal< LinkService, Interest > & afterReceiveInterest
signals on Interest received
Definition: face.hpp:100
TransportState
indicates the state of a transport
Definition: transport.hpp:41
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
Definition: face.hpp:44
represents an Interest packet
Definition: interest.hpp:45
provides a lightweight signal / event system
represents a Network Nack
Definition: nack.hpp:40
signal::Signal< LinkService, lp::Nack > & afterReceiveNack
signals on Nack received
Definition: face.hpp:108
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
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
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
signals after face state changed
Definition: face.hpp:166
A multicast Transport that uses raw Ethernet II frames.
signal::Signal< LinkService, Data > & afterReceiveData
signals on Data received
Definition: face.hpp:104
const FaceId FACEID_NULL
identifies the NullFace that drops every packet
Definition: face.hpp:48
uint64_t FaceId
identifies a face
Definition: face.hpp:39
represents a Data packet
Definition: data.hpp:39
const FaceId FACEID_CONTENT_STORE
identifies a packet comes from the ContentStore
Definition: face.hpp:46
the lower part of a Face
Definition: transport.hpp:104
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:42
gives access to counters provided by Face