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_FACE_HPP
27 #define NFD_DAEMON_FACE_FACE_HPP
28 
29 #include "common.hpp"
30 #include "core/logger.hpp"
31 #include "face-counters.hpp"
32 
33 #include <ndn-cxx/management/nfd-face-status.hpp>
34 
35 namespace nfd {
36 
40 typedef int FaceId;
41 
43 const FaceId INVALID_FACEID = -1;
44 
46 const FaceId FACEID_INTERNAL_FACE = 1;
48 const FaceId FACEID_CONTENT_STORE = 254;
50 const FaceId FACEID_NULL = 255;
52 const FaceId FACEID_RESERVED_MAX = 255;
53 
54 
57 class Face : noncopyable, public enable_shared_from_this<Face>
58 {
59 public:
63  class Error : public std::runtime_error
64  {
65  public:
66  explicit
67  Error(const std::string& what)
68  : std::runtime_error(what)
69  {
70  }
71  };
72 
73  Face(const FaceUri& remoteUri, const FaceUri& localUri,
74  bool isLocal = false, bool isMultiAccess = false);
75 
76  virtual
77  ~Face();
78 
81 
84 
87 
90 
92  signal::Signal<Face, std::string/*reason*/> onFail;
93 
95  virtual void
96  sendInterest(const Interest& interest) = 0;
97 
99  virtual void
100  sendData(const Data& data) = 0;
101 
107  virtual void
108  close() = 0;
109 
110 public: // attributes
111  FaceId
112  getId() const;
113 
116  const std::string&
117  getDescription() const;
118 
123  void
124  setDescription(const std::string& description);
125 
126  void
127  setMetric(uint64_t metric);
128 
129  uint64_t
130  getMetric() const;
131 
134  bool
135  isLocal() const;
136 
140  getPersistency() const;
141 
144  bool
145  isMultiAccess() const;
146 
151  virtual bool
152  isUp() const;
153 
154  const FaceCounters&
155  getCounters() const;
156 
159  const FaceUri&
160  getRemoteUri() const;
161 
164  const FaceUri&
165  getLocalUri() const;
166 
169  template<typename FaceTraits>
170  void
171  copyStatusTo(FaceTraits& traits) const;
172 
175  virtual ndn::nfd::FaceStatus
176  getFaceStatus() const;
177 
179  void
181 
182 protected:
183  bool
184  decodeAndDispatchInput(const Block& element);
185 
188  void
189  fail(const std::string& reason);
190 
191  FaceCounters&
193 
194  DECLARE_SIGNAL_EMIT(onReceiveInterest)
195  DECLARE_SIGNAL_EMIT(onReceiveData)
196  DECLARE_SIGNAL_EMIT(onSendInterest)
197  DECLARE_SIGNAL_EMIT(onSendData)
198 
199 private:
200  // this method should be used only by the FaceTable
201  void
202  setId(FaceId faceId);
203 
204 private:
205  FaceId m_id;
206  std::string m_description;
207  FaceCounters m_counters;
208  const FaceUri m_remoteUri;
209  const FaceUri m_localUri;
210  const bool m_isLocal;
211  ndn::nfd::FacePersistency m_persistency;
212  const bool m_isMultiAccess;
213  bool m_isFailed;
214  uint64_t m_metric;
215 
216  // allow setting FaceId
217  friend class FaceTable;
218 };
219 
220 inline FaceId
221 Face::getId() const
222 {
223  return m_id;
224 }
225 
226 inline void
227 Face::setId(FaceId faceId)
228 {
229  m_id = faceId;
230 }
231 
232 inline const std::string&
234 {
235  return m_description;
236 }
237 
238 inline void
239 Face::setDescription(const std::string& description)
240 {
241  m_description = description;
242 }
243 
244 inline bool
246 {
247  return m_isLocal;
248 }
249 
252 {
253  return m_persistency;
254 }
255 
256 inline void
258 {
259  m_persistency = persistency;
260 }
261 
262 inline bool
264 {
265  return m_isMultiAccess;
266 }
267 
268 inline const FaceCounters&
270 {
271  return m_counters;
272 }
273 
274 inline FaceCounters&
276 {
277  return m_counters;
278 }
279 
280 inline const FaceUri&
282 {
283  return m_remoteUri;
284 }
285 
286 inline const FaceUri&
288 {
289  return m_localUri;
290 }
291 
292 
302 inline void
303 Face::setMetric(uint64_t metric)
304 {
305  m_metric = metric;
306 }
307 
308 inline uint64_t
310 {
311  return m_metric;
312 }
313 
314 #define NFD_LOG_FACE(level, msg) \
315  NFD_LOG_##level("[id=" << this->getId() << \
316  ",local=" << this->getLocalUri() << \
317  ",remote=" << this->getRemoteUri() << \
318  "] " << msg)
319 
321 #define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
322 
324 #define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
325 
327 #define NFD_LOG_FACE_INFO(msg) NFD_LOG_FACE(INFO, msg)
328 
330 #define NFD_LOG_FACE_WARN(msg) NFD_LOG_FACE(WARN, msg)
331 
333 #define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
334 
337 } // namespace nfd
338 
339 #endif // NFD_DAEMON_FACE_FACE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const std::string & getDescription() const
Get the description.
Definition: face.hpp:233
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
Definition: face.hpp:46
const FaceCounters & getCounters() const
Definition: face.hpp:269
virtual ndn::nfd::FaceStatus getFaceStatus() const
Definition: face.cpp:118
Face-related error.
Definition: face.hpp:63
void copyStatusTo(FaceTraits &traits) const
Definition: face.cpp:99
virtual bool isUp() const
Get whether underlying communication is up.
Definition: face.cpp:53
const FaceId FACEID_RESERVED_MAX
upper bound of reserved FaceIds
Definition: face.hpp:52
ndn::nfd::FacePersistency getPersistency() const
Get the persistency setting.
Definition: face.hpp:251
signal::Signal< Face, Interest > onSendInterest
fires when an Interest is sent out
Definition: face.hpp:86
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
void setPersistency(ndn::nfd::FacePersistency persistency)
Definition: face.hpp:257
Error(const std::string &what)
Definition: face.hpp:67
contains counters on face
STL namespace.
bool decodeAndDispatchInput(const Block &element)
Definition: face.cpp:59
signal::Signal< Face, Data > onReceiveData
fires when a Data is received
Definition: face.hpp:83
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
provides a lightweight signal / event system
virtual void sendData(const Data &data)=0
send a Data
const FaceUri & getRemoteUri() const
Definition: face.hpp:281
virtual ~Face()
Definition: face.cpp:48
signal::Signal< Face, Data > onSendData
fires when a Data is sent out
Definition: face.hpp:89
represents a face
Definition: face.hpp:57
void fail(const std::string &reason)
fail the face and raise onFail event if it&#39;s UP; otherwise do nothing
Definition: face.cpp:87
container of all Faces
Definition: face-table.hpp:38
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
void setMetric(uint64_t metric)
Definition: face.hpp:303
signal::Signal< Face, std::string > onFail
fires when face disconnects or fails to perform properly
Definition: face.hpp:92
FaceCounters & getMutableCounters()
Definition: face.hpp:275
represents Face status
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:38
#define DECLARE_SIGNAL_EMIT(signalName)
(implementation detail) declares a &#39;emit_signalName&#39; method
Definition: signal-emit.hpp:59
const FaceId FACEID_NULL
identifies the NullFace that drops every packet
Definition: face.hpp:50
const FaceId FACEID_CONTENT_STORE
identifies a packet comes from the ContentStore, in LocalControlHeader incomingFaceId ...
Definition: face.hpp:48
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:43
Face(const FaceUri &remoteUri, const FaceUri &localUri, bool isLocal=false, bool isMultiAccess=false)
Definition: face.cpp:32
bool isMultiAccess() const
Get whether packets sent by this face may reach multiple peers.
Definition: face.hpp:263
signal::Signal< Face, Interest > onReceiveInterest
fires when an Interest is received
Definition: face.hpp:80
void setDescription(const std::string &description)
Set the face description.
Definition: face.hpp:239
FaceId getId() const
Definition: face.hpp:221
uint64_t getMetric() const
Definition: face.hpp:309
const FaceUri & getLocalUri() const
Definition: face.hpp:287
represents a Data packet
Definition: data.hpp:39
virtual void close()=0
Close the face.
bool isLocal() const
Get whether face is connected to a local app.
Definition: face.hpp:245
int FaceId
Definition: face.hpp:40
virtual void sendInterest(const Interest &interest)=0
send an Interest