NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
local-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_LOCAL_FACE_HPP
27 #define NFD_DAEMON_FACE_LOCAL_FACE_HPP
28 
29 #include "face.hpp"
30 #include <ndn-cxx/management/nfd-control-parameters.hpp>
31 
32 namespace nfd {
33 
37 
40 class LocalFace : public Face
41 {
42 public:
43  LocalFace(const FaceUri& remoteUri, const FaceUri& localUri);
44 
49  bool
51 
57  bool
59 
65  void
66  setLocalControlHeaderFeature(LocalControlFeature feature, bool enabled = true);
67 
68 public:
69 
70  static const size_t LOCAL_CONTROL_FEATURE_MAX = 3;
71  static const size_t LOCAL_CONTROL_FEATURE_ANY = 0;
72 
73 protected:
74  // statically overridden from Face
75 
81  bool
82  decodeAndDispatchInput(const Block& element);
83 
84  // LocalFace-specific methods
85 
90  bool
92 
95  template<class Packet>
96  Block
97  filterAndEncodeLocalControlHeader(const Packet& packet);
98 
99 private:
100  std::vector<bool> m_localControlHeaderFeatures;
101 };
102 
103 inline
104 LocalFace::LocalFace(const FaceUri& remoteUri, const FaceUri& localUri)
105  : Face(remoteUri, localUri, true)
106  , m_localControlHeaderFeatures(LocalFace::LOCAL_CONTROL_FEATURE_MAX)
107 {
108 }
109 
110 inline bool
112 {
113  return m_localControlHeaderFeatures[LOCAL_CONTROL_FEATURE_ANY];
114 }
115 
116 inline bool
118 {
119  BOOST_ASSERT(0 < feature &&
120  static_cast<size_t>(feature) < m_localControlHeaderFeatures.size());
121  return m_localControlHeaderFeatures[feature];
122 }
123 
124 inline void
126 {
127  BOOST_ASSERT(0 < feature &&
128  static_cast<size_t>(feature) < m_localControlHeaderFeatures.size());
129 
130  m_localControlHeaderFeatures[feature] = enabled;
131 
132  m_localControlHeaderFeatures[LOCAL_CONTROL_FEATURE_ANY] =
133  std::find(m_localControlHeaderFeatures.begin() + 1,
134  m_localControlHeaderFeatures.end(), true) <
135  m_localControlHeaderFeatures.end();
136  // 'find(..) < .end()' instead of 'find(..) != .end()' due to LLVM Bug 16816
137 }
138 
139 inline bool
141 {
142  try {
143  const Block& payload = ndn::nfd::LocalControlHeader::getPayload(element);
144 
145  // If received LocalControlHeader, but it is not enabled on the face
146  if ((&payload != &element) && !this->isLocalControlHeaderEnabled())
147  return false;
148 
149  if (payload.type() == tlv::Interest)
150  {
151  shared_ptr<Interest> i = make_shared<Interest>();
152  i->wireDecode(payload);
153  if (&payload != &element)
154  {
155  uint8_t mask = 0;
158  }
159  i->getLocalControlHeader().wireDecode(element, mask);
160  }
161 
162  this->emitSignal(onReceiveInterest, *i);
163  }
164  else if (payload.type() == tlv::Data)
165  {
166  shared_ptr<Data> d = make_shared<Data>();
167  d->wireDecode(payload);
168 
172  // if (&payload != &element)
173  // {
174  //
175  // d->getLocalControlHeader().wireDecode(element,
176  // false,
177  // false);
178  // }
179 
180  this->emitSignal(onReceiveData, *d);
181  }
182  else
183  return false;
184 
185  return true;
186  }
187  catch (const tlv::Error&) {
188  return false;
189  }
190 }
191 
192 inline bool
194 {
195  if (!this->isLocalControlHeaderEnabled())
196  return true;
197 
198  uint8_t mask = 0;
201  }
202  return header.empty(mask);
203 }
204 
205 template<class Packet>
206 inline Block
208 {
209  uint8_t mask = 0;
212  }
213  return packet.getLocalControlHeader().wireEncode(packet, mask);
214 }
215 
216 } // namespace nfd
217 
218 #endif // NFD_DAEMON_FACE_LOCAL_FACE_HPP
static const size_t LOCAL_CONTROL_FEATURE_ANY
upper bound of LocalControlFeature enum
Definition: local-face.hpp:71
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
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
Block filterAndEncodeLocalControlHeader(const Packet &packet)
Create LocalControlHeader, considering enabled features.
Definition: local-face.hpp:207
represents a face
Definition: face.hpp:57
static const Block & getPayload(const Block &wire)
#define emitSignal(...)
(implementation detail)
Definition: signal-emit.hpp:76
bool decodeAndDispatchInput(const Block &element)
any feature
Definition: local-face.hpp:140
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
bool empty(uint8_t encodeMask) const
Class to handle work with LocalControlHeader.
LocalFace(const FaceUri &remoteUri, const FaceUri &localUri)
Definition: local-face.hpp:104
represents a face
Definition: local-face.hpp:40
signal::Signal< Face, Interest > onReceiveInterest
fires when an Interest is received
Definition: face.hpp:80
bool isLocalControlHeaderEnabled() const
get whether any LocalControlHeader feature is enabled
Definition: local-face.hpp:111
static const size_t LOCAL_CONTROL_FEATURE_MAX
Definition: local-face.hpp:70
uint32_t type() const
Definition: block.hpp:346
bool isEmptyFilteredLocalControlHeader(const ndn::nfd::LocalControlHeader &header) const
Check if LocalControlHeader needs to be included, taking into account both set parameters in supplied...
Definition: local-face.hpp:193
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
void setLocalControlHeaderFeature(LocalControlFeature feature, bool enabled=true)
enable or disable a LocalControlHeader feature
Definition: local-face.hpp:125