All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ndnd-forwarding-flags.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
8 #ifndef NDN_FORWARDING_FLAGS_HPP
9 #define NDN_FORWARDING_FLAGS_HPP
10 
11 #include "../encoding/block.hpp"
12 #include "../encoding/tlv-ndnd.hpp"
13 
14 namespace ndn {
15 namespace ndnd {
16 
23 {
24 public:
29  : active_(true)
30  , childInherit_(true)
31  , advertise_(false)
32  , last_(false)
33  , capture_(false)
34  , local_(false)
35  , tap_(false)
36  , captureOk_(false)
37  {
38  }
39 
43  explicit
44  ForwardingFlags(const Block& wire)
45  {
46  wireDecode(wire);
47  }
48 
53  bool getActive() const { return active_; }
54 
59  bool getChildInherit() const { return childInherit_; }
60 
65  bool getAdvertise() const { return advertise_; }
66 
71  bool getLast() const { return last_; }
72 
77  bool getCapture() const { return capture_; }
78 
83  bool getLocal() const { return local_; }
84 
89  bool getTap() const { return tap_; }
90 
95  bool getCaptureOk() const { return captureOk_; }
96 
101  void setActive(bool active) { this->active_ = active; wire_.reset(); }
102 
107  void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); }
108 
113  void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); }
114 
119  void setLast(bool last) { this->last_ = last; wire_.reset(); }
120 
125  void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); }
126 
131  void setLocal(bool local) { this->local_ = local; wire_.reset(); }
132 
137  void setTap(bool tap) { this->tap_ = tap; wire_.reset(); }
138 
143  void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); }
144 
145  inline const Block&
146  wireEncode() const;
147 
148  inline void
149  wireDecode(const Block& block);
150 
151 private:
152  bool active_;
153  bool childInherit_;
154  bool advertise_;
155  bool last_;
156  bool capture_;
157  bool local_;
158  bool tap_;
159  bool captureOk_;
160 
161  mutable Block wire_;
162 };
163 
164 inline const Block&
166 {
167  if (wire_.hasWire())
168  return wire_;
169 
170  uint32_t result = 0;
171  if (active_)
172  result |= tlv::ndnd::FORW_ACTIVE;
173  if (childInherit_)
175  if (advertise_)
176  result |= tlv::ndnd::FORW_ADVERTISE;
177  if (last_)
178  result |= tlv::ndnd::FORW_LAST;
179  if (capture_)
180  result |= tlv::ndnd::FORW_CAPTURE;
181  if (local_)
182  result |= tlv::ndnd::FORW_LOCAL;
183  if (tap_)
184  result |= tlv::ndnd::FORW_TAP;
185  if (captureOk_)
186  result |= tlv::ndnd::FORW_CAPTURE_OK;
187 
189 
190  return wire_;
191 }
192 
193 inline void
195 {
196  wire_ = wire;
197 
198  uint32_t flags = readNonNegativeInteger(wire_);
199 
200  active_ = (flags & tlv::ndnd::FORW_ACTIVE) ? true : false;
201  childInherit_ = (flags & tlv::ndnd::FORW_CHILD_INHERIT) ? true : false;
202  advertise_ = (flags & tlv::ndnd::FORW_ADVERTISE) ? true : false;
203  last_ = (flags & tlv::ndnd::FORW_LAST) ? true : false;
204  capture_ = (flags & tlv::ndnd::FORW_CAPTURE) ? true : false;
205  local_ = (flags & tlv::ndnd::FORW_LOCAL) ? true : false;
206  tap_ = (flags & tlv::ndnd::FORW_TAP) ? true : false;
207  captureOk_ = (flags & tlv::ndnd::FORW_CAPTURE_OK) ? true : false;
208 }
209 
210 inline std::ostream&
211 operator << (std::ostream& os, const ForwardingFlags& flags)
212 {
213  if (flags.getActive())
214  os << "ACTIVE ";
215  if (flags.getChildInherit())
216  os << "CHILE_INHERIT ";
217  if (flags.getAdvertise())
218  os << "ADVERTISE ";
219  if (flags.getLast())
220  os << "LAST ";
221  if (flags.getCapture())
222  os << "CAPTURE ";
223  if (flags.getLocal())
224  os << "LOCAL ";
225  if (flags.getTap())
226  os << "TAP ";
227  if (flags.getCaptureOk())
228  os << "CAPTURE_OK ";
229 
230  return os;
231 }
232 
233 } // namespace ndnd
234 } // namespace ndn
235 
236 #endif
ForwardingFlags(const Block &wire)
Create from wire encoding.
Block nonNegativeIntegerBlock(uint32_t type, uint64_t value)
void setLast(bool last)
Set the value of the &quot;last&quot; flag.
A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an in...
bool getTap() const
Get the value of the &quot;tap&quot; flag.
void setCapture(bool capture)
Set the value of the &quot;capture&quot; flag.
bool getActive() const
Get the value of the &quot;active&quot; flag.
bool getChildInherit() const
Get the value of the &quot;childInherit&quot; flag.
void setActive(bool active)
Set the value of the &quot;active&quot; flag.
Class representing wire element of the NDN packet.
Definition: block.hpp:26
void wireDecode(const Block &block)
uint64_t readNonNegativeInteger(const Block &block)
bool getCapture() const
Get the value of the &quot;capture&quot; flag.
bool getAdvertise() const
Get the value of the &quot;advertise&quot; flag.
void setChildInherit(bool childInherit)
Set the value of the &quot;childInherit&quot; flag.
void setLocal(bool local)
Set the value of the &quot;local&quot; flag.
void setAdvertise(bool advertise)
Set the value of the &quot;advertise&quot; flag.
void setTap(bool tap)
Set the value of the &quot;tap&quot; flag.
void setCaptureOk(bool captureOk)
Set the value of the &quot;captureOk&quot; flag.
void reset()
Reset wire buffer of the element.
Definition: block.hpp:300
bool getLast() const
Get the value of the &quot;last&quot; flag.
bool getCaptureOk() const
Get the value of the &quot;captureOk&quot; flag.
ForwardingFlags()
Create a new ForwardingFlags with &quot;active&quot; and &quot;childInherit&quot; set and all other flags cleared...
const Block & wireEncode() const
bool getLocal() const
Get the value of the &quot;local&quot; flag.
std::ostream & operator<<(std::ostream &os, const FaceInstance &entry)
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.hpp:288