NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "face-counters.hpp"
31 
32 #include <ndn-cxx/util/face-uri.hpp>
33 #include <ndn-cxx/management/nfd-face-status.hpp>
34 #include <ndn-cxx/management/nfd-face-event-notification.hpp>
35 
36 namespace nfd {
37 
41 typedef int FaceId;
42 
45 
51 const FaceId FACEID_NULL = 255;
54 
55 using ndn::util::FaceUri;
56 
59 class Face : noncopyable, public enable_shared_from_this<Face>
60 {
61 public:
65  class Error : public std::runtime_error
66  {
67  public:
68  explicit
69  Error(const std::string& what)
70  : std::runtime_error(what)
71  {
72  }
73  };
74 
75  Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal = false);
76 
77  virtual
78  ~Face();
79 
81  EventEmitter<Interest> onReceiveInterest;
82 
84  EventEmitter<Data> onReceiveData;
85 
87  EventEmitter<Interest> onSendInterest;
88 
90  EventEmitter<Data> onSendData;
91 
93  EventEmitter<std::string/*reason*/> onFail;
94 
96  virtual void
97  sendInterest(const Interest& interest) = 0;
98 
100  virtual void
101  sendData(const Data& data) = 0;
102 
108  virtual void
109  close() = 0;
110 
111 public: // attributes
112  FaceId
113  getId() const;
114 
119  virtual void
120  setDescription(const std::string& description);
121 
123  virtual const std::string&
124  getDescription() const;
125 
126  void
127  setMetric(uint64_t metric);
128 
129  uint64_t
130  getMetric() const;
131 
134  bool
135  isLocal() const;
136 
141  virtual bool
142  isMultiAccess() const;
143 
148  virtual bool
149  isUp() const;
150 
153  bool
154  isOnDemand() const;
155 
156  const FaceCounters&
157  getCounters() const;
158 
161  const FaceUri&
162  getRemoteUri() const;
163 
166  const FaceUri&
167  getLocalUri() const;
168 
171  template<typename FaceTraits>
172  void
173  copyStatusTo(FaceTraits& traits) const;
174 
177  virtual ndn::nfd::FaceStatus
178  getFaceStatus() const;
179 
180 protected:
181  // this is a non-virtual method
182  bool
183  decodeAndDispatchInput(const Block& element);
184 
185  FaceCounters&
187 
188  void
189  setOnDemand(bool isOnDemand);
190 
193  void
194  fail(const std::string& reason);
195 
196 private:
197  void
198  setId(FaceId faceId);
199 
200 private:
201  FaceId m_id;
202  std::string m_description;
203  bool m_isLocal; // for scoping purposes
204  FaceCounters m_counters;
205  FaceUri m_remoteUri;
206  FaceUri m_localUri;
207  bool m_isOnDemand;
208  bool m_isFailed;
209  uint64_t m_metric;
210 
211  // allow setting FaceId
212  friend class FaceTable;
213 };
214 
215 inline bool
217 {
218  return m_isLocal;
219 }
220 
221 inline const FaceCounters&
223 {
224  return m_counters;
225 }
226 
227 inline FaceCounters&
229 {
230  return m_counters;
231 }
232 
233 inline const FaceUri&
235 {
236  return m_remoteUri;
237 }
238 
239 inline const FaceUri&
241 {
242  return m_localUri;
243 }
244 
245 inline void
246 Face::setOnDemand(bool isOnDemand)
247 {
248  m_isOnDemand = isOnDemand;
249 }
250 
251 inline bool
253 {
254  return m_isOnDemand;
255 }
256 
257 inline void
258 Face::setMetric(uint64_t metric)
259 {
260  m_metric = metric;
261 }
262 
263 inline uint64_t
265 {
266  return m_metric;
267 }
268 
269 } // namespace nfd
270 
271 #endif // NFD_DAEMON_FACE_FACE_HPP
void setOnDemand(bool isOnDemand)
Definition: face.hpp:246
virtual const std::string & getDescription() const
Get the description.
Definition: face.cpp:70
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
Definition: face.hpp:47
const FaceCounters & getCounters() const
Definition: face.hpp:222
virtual ndn::nfd::FaceStatus getFaceStatus() const
Definition: face.cpp:158
Face-related error.
Definition: face.hpp:65
void copyStatusTo(FaceTraits &traits) const
Definition: face.cpp:130
virtual bool isUp() const
Get whether underlying communication is up.
Definition: face.cpp:82
const FaceId FACEID_RESERVED_MAX
upper bound of reserved FaceIds
Definition: face.hpp:53
EventEmitter< Data > onReceiveData
fires when a Data is received
Definition: face.hpp:84
Error(const std::string &what)
Definition: face.hpp:69
contains counters on face
bool decodeAndDispatchInput(const Block &element)
Definition: face.cpp:88
EventEmitter< Interest > onSendInterest
fires when an Interest is sent out
Definition: face.hpp:87
uint64_t getMetric() const
Definition: face.hpp:264
virtual void sendData(const Data &data)=0
send a Data
const FaceUri & getRemoteUri() const
Definition: face.hpp:234
bool isOnDemand() const
Get whether face is created on demand or explicitly via FaceManagement protocol.
Definition: face.hpp:252
virtual ~Face()
Definition: face.cpp:46
represents a face
Definition: face.hpp:59
EventEmitter< std::string > onFail
fires when face disconnects or fails to perform properly
Definition: face.hpp:93
void fail(const std::string &reason)
fail the face and raise onFail event if it's UP; otherwise do nothing
Definition: face.cpp:116
container of all Faces
Definition: face-table.hpp:38
EventEmitter< Data > onSendData
fires when a Data is sent out
Definition: face.hpp:90
FaceCounters & getMutableCounters()
Definition: face.hpp:228
void setMetric(uint64_t metric)
Definition: face.hpp:258
identifies a face
const FaceId FACEID_NULL
identifies the NullFace that drops every packet
Definition: face.hpp:51
const FaceId FACEID_CONTENT_STORE
identifies a packet comes from the ContentStore, in LocalControlHeader incomingFaceId ...
Definition: face.hpp:49
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:44
virtual bool isMultiAccess() const
Get whether packets sent this Face may reach multiple peers.
Definition: face.cpp:76
virtual void setDescription(const std::string &description)
Set the description.
Definition: face.cpp:64
FaceId getId() const
Definition: face.cpp:51
const FaceUri & getLocalUri() const
Definition: face.hpp:240
virtual void close()=0
Close the face.
bool isLocal() const
Get whether face is connected to a local app.
Definition: face.hpp:216
int FaceId
Definition: face.hpp:41
Face(const FaceUri &remoteUri, const FaceUri &localUri, bool isLocal=false)
Definition: face.cpp:31
virtual void sendInterest(const Interest &interest)=0
send an Interest
EventEmitter< Interest > onReceiveInterest
fires when an Interest is received
Definition: face.hpp:81