blob: 803dabcc2b721fcc2ee1da9ff7f87af119626e3a [file] [log] [blame]
Jeff Thompson1f8a31a2013-09-30 16:18:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_FORWARDING_FLAGS_HPP
Jeff Thompsone589c3f2013-10-12 17:30:50 -07009#define NDN_FORWARDING_FLAGS_HPP
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070010
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080011#include "../encoding/block.hpp"
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080012#include "../encoding/tlv-ndnd.hpp"
Alexander Afanasyev10d902e2014-01-03 15:27:40 -080013
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070014namespace ndn {
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080015namespace ndnd {
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070016
17/**
18 * A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an interest for
19 * a registered prefix. We use a separate ForwardingFlags object to retain future compatibility if the daemon forwarding
20 * bits are changed, amended or deprecated.
21 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080022class ForwardingFlags {
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070023public:
24 /**
25 * Create a new ForwardingFlags with "active" and "childInherit" set and all other flags cleared.
26 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070027 ForwardingFlags()
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080028 : active_(true)
29 , childInherit_(true)
30 , advertise_(false)
31 , last_(false)
32 , capture_(false)
33 , local_(false)
34 , tap_(false)
35 , captureOk_(false)
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070036 {
37 }
38
39 /**
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070040 * @brief Create from wire encoding
41 */
42 explicit
43 ForwardingFlags(const Block& wire)
44 {
45 wireDecode(wire);
46 }
47
48 /**
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070049 * Get the value of the "active" flag.
50 * @return true if the flag is set, false if it is cleared.
51 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080052 bool getActive() const { return active_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070053
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070054 /**
55 * Get the value of the "childInherit" flag.
56 * @return true if the flag is set, false if it is cleared.
57 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080058 bool getChildInherit() const { return childInherit_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070059
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070060 /**
61 * Get the value of the "advertise" flag.
62 * @return true if the flag is set, false if it is cleared.
63 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080064 bool getAdvertise() const { return advertise_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070065
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070066 /**
67 * Get the value of the "last" flag.
68 * @return true if the flag is set, false if it is cleared.
69 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080070 bool getLast() const { return last_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070071
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070072 /**
73 * Get the value of the "capture" flag.
74 * @return true if the flag is set, false if it is cleared.
75 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080076 bool getCapture() const { return capture_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070078 /**
79 * Get the value of the "local" flag.
80 * @return true if the flag is set, false if it is cleared.
81 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080082 bool getLocal() const { return local_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070083
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070084 /**
85 * Get the value of the "tap" flag.
86 * @return true if the flag is set, false if it is cleared.
87 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080088 bool getTap() const { return tap_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070089
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070090 /**
91 * Get the value of the "captureOk" flag.
92 * @return true if the flag is set, false if it is cleared.
93 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080094 bool getCaptureOk() const { return captureOk_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070095
96 /**
97 * Set the value of the "active" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -080098 * @param active true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070099 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800100 void setActive(bool active) { this->active_ = active; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700101
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700102 /**
103 * Set the value of the "childInherit" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800104 * @param childInherit true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700105 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800106 void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700107
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700108 /**
109 * Set the value of the "advertise" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800110 * @param advertise true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800112 void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700114 /**
115 * Set the value of the "last" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800116 * @param last true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700117 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800118 void setLast(bool last) { this->last_ = last; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700119
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700120 /**
121 * Set the value of the "capture" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800122 * @param capture true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700123 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800124 void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700125
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700126 /**
127 * Set the value of the "local" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800128 * @param local true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700129 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800130 void setLocal(bool local) { this->local_ = local; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700131
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700132 /**
133 * Set the value of the "tap" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800134 * @param tap true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700135 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800136 void setTap(bool tap) { this->tap_ = tap; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700137
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700138 /**
139 * Set the value of the "captureOk" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800140 * @param captureOk true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700141 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800142 void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); }
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800143
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800144 inline const Block&
145 wireEncode() const;
146
147 inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700148 wireDecode(const Block& block);
149
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800150private:
151 bool active_;
152 bool childInherit_;
153 bool advertise_;
154 bool last_;
155 bool capture_;
156 bool local_;
157 bool tap_;
158 bool captureOk_;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800159
160 mutable Block wire_;
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700161};
162
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800163inline const Block&
164ForwardingFlags::wireEncode() const
165{
166 if (wire_.hasWire())
167 return wire_;
168
169 uint32_t result = 0;
170 if (active_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800171 result |= tlv::ndnd::FORW_ACTIVE;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800172 if (childInherit_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800173 result |= tlv::ndnd::FORW_CHILD_INHERIT;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800174 if (advertise_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800175 result |= tlv::ndnd::FORW_ADVERTISE;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800176 if (last_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800177 result |= tlv::ndnd::FORW_LAST;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800178 if (capture_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800179 result |= tlv::ndnd::FORW_CAPTURE;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800180 if (local_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800181 result |= tlv::ndnd::FORW_LOCAL;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800182 if (tap_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800183 result |= tlv::ndnd::FORW_TAP;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800184 if (captureOk_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800185 result |= tlv::ndnd::FORW_CAPTURE_OK;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700186
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800187 wire_ = nonNegativeIntegerBlock(tlv::ndnd::ForwardingFlags, result);
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800188
189 return wire_;
190}
191
192inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700193ForwardingFlags::wireDecode(const Block& wire)
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800194{
195 wire_ = wire;
196
197 uint32_t flags = readNonNegativeInteger(wire_);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700198
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800199 active_ = (flags & tlv::ndnd::FORW_ACTIVE) ? true : false;
200 childInherit_ = (flags & tlv::ndnd::FORW_CHILD_INHERIT) ? true : false;
201 advertise_ = (flags & tlv::ndnd::FORW_ADVERTISE) ? true : false;
202 last_ = (flags & tlv::ndnd::FORW_LAST) ? true : false;
203 capture_ = (flags & tlv::ndnd::FORW_CAPTURE) ? true : false;
204 local_ = (flags & tlv::ndnd::FORW_LOCAL) ? true : false;
205 tap_ = (flags & tlv::ndnd::FORW_TAP) ? true : false;
206 captureOk_ = (flags & tlv::ndnd::FORW_CAPTURE_OK) ? true : false;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800207}
208
Alexander Afanasyev816cf942014-01-03 15:33:41 -0800209inline std::ostream&
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700210operator << (std::ostream& os, const ForwardingFlags& flags)
Alexander Afanasyev816cf942014-01-03 15:33:41 -0800211{
212 if (flags.getActive())
213 os << "ACTIVE ";
214 if (flags.getChildInherit())
215 os << "CHILE_INHERIT ";
216 if (flags.getAdvertise())
217 os << "ADVERTISE ";
218 if (flags.getLast())
219 os << "LAST ";
220 if (flags.getCapture())
221 os << "CAPTURE ";
222 if (flags.getLocal())
223 os << "LOCAL ";
224 if (flags.getTap())
225 os << "TAP ";
226 if (flags.getCaptureOk())
227 os << "CAPTURE_OK ";
228
229 return os;
230}
231
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800232} // namespace ndnd
233} // namespace ndn
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700234
235#endif