blob: 36a565f5e5457cd3f3605a59aaf5c216125d776a [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 Afanasyev2a7f7202014-04-23 14:25:29 -070022class ForwardingFlags
23{
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070024public:
25 /**
26 * Create a new ForwardingFlags with "active" and "childInherit" set and all other flags cleared.
27 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070028 ForwardingFlags()
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080029 : active_(true)
30 , childInherit_(true)
31 , advertise_(false)
32 , last_(false)
33 , capture_(false)
34 , local_(false)
35 , tap_(false)
36 , captureOk_(false)
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070037 {
38 }
39
40 /**
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070041 * @brief Create from wire encoding
42 */
43 explicit
44 ForwardingFlags(const Block& wire)
45 {
46 wireDecode(wire);
47 }
48
49 /**
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070050 * Get the value of the "active" flag.
51 * @return true if the flag is set, false if it is cleared.
52 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080053 bool getActive() const { return active_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070054
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070055 /**
56 * Get the value of the "childInherit" flag.
57 * @return true if the flag is set, false if it is cleared.
58 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080059 bool getChildInherit() const { return childInherit_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070060
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070061 /**
62 * Get the value of the "advertise" flag.
63 * @return true if the flag is set, false if it is cleared.
64 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080065 bool getAdvertise() const { return advertise_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070067 /**
68 * Get the value of the "last" flag.
69 * @return true if the flag is set, false if it is cleared.
70 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080071 bool getLast() const { return last_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070072
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070073 /**
74 * Get the value of the "capture" flag.
75 * @return true if the flag is set, false if it is cleared.
76 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080077 bool getCapture() const { return capture_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070079 /**
80 * Get the value of the "local" flag.
81 * @return true if the flag is set, false if it is cleared.
82 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080083 bool getLocal() const { return local_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070084
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070085 /**
86 * Get the value of the "tap" flag.
87 * @return true if the flag is set, false if it is cleared.
88 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080089 bool getTap() const { return tap_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070090
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070091 /**
92 * Get the value of the "captureOk" flag.
93 * @return true if the flag is set, false if it is cleared.
94 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080095 bool getCaptureOk() const { return captureOk_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070096
97 /**
98 * Set the value of the "active" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -080099 * @param active true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700100 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800101 void setActive(bool active) { this->active_ = active; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700102
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700103 /**
104 * Set the value of the "childInherit" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800105 * @param childInherit true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700106 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800107 void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700108
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700109 /**
110 * Set the value of the "advertise" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800111 * @param advertise true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700112 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800113 void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700114
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700115 /**
116 * Set the value of the "last" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800117 * @param last true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700118 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800119 void setLast(bool last) { this->last_ = last; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700120
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700121 /**
122 * Set the value of the "capture" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800123 * @param capture true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700124 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800125 void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700126
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700127 /**
128 * Set the value of the "local" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800129 * @param local true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700130 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800131 void setLocal(bool local) { this->local_ = local; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700132
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700133 /**
134 * Set the value of the "tap" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800135 * @param tap true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700136 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800137 void setTap(bool tap) { this->tap_ = tap; wire_.reset(); }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700138
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700139 /**
140 * Set the value of the "captureOk" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800141 * @param captureOk true to set the flag, false to clear it.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700142 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800143 void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); }
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800144
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800145 inline const Block&
146 wireEncode() const;
147
148 inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700149 wireDecode(const Block& block);
150
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800151private:
152 bool active_;
153 bool childInherit_;
154 bool advertise_;
155 bool last_;
156 bool capture_;
157 bool local_;
158 bool tap_;
159 bool captureOk_;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800160
161 mutable Block wire_;
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700162};
163
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800164inline const Block&
165ForwardingFlags::wireEncode() const
166{
167 if (wire_.hasWire())
168 return wire_;
169
170 uint32_t result = 0;
171 if (active_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800172 result |= tlv::ndnd::FORW_ACTIVE;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800173 if (childInherit_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800174 result |= tlv::ndnd::FORW_CHILD_INHERIT;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800175 if (advertise_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800176 result |= tlv::ndnd::FORW_ADVERTISE;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800177 if (last_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800178 result |= tlv::ndnd::FORW_LAST;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800179 if (capture_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800180 result |= tlv::ndnd::FORW_CAPTURE;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800181 if (local_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800182 result |= tlv::ndnd::FORW_LOCAL;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800183 if (tap_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800184 result |= tlv::ndnd::FORW_TAP;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800185 if (captureOk_)
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800186 result |= tlv::ndnd::FORW_CAPTURE_OK;
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700187
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800188 wire_ = nonNegativeIntegerBlock(tlv::ndnd::ForwardingFlags, result);
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800189
190 return wire_;
191}
192
193inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700194ForwardingFlags::wireDecode(const Block& wire)
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800195{
196 wire_ = wire;
197
198 uint32_t flags = readNonNegativeInteger(wire_);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700199
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800200 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;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800208}
209
Alexander Afanasyev816cf942014-01-03 15:33:41 -0800210inline std::ostream&
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700211operator << (std::ostream& os, const ForwardingFlags& flags)
Alexander Afanasyev816cf942014-01-03 15:33:41 -0800212{
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
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800233} // namespace ndnd
234} // namespace ndn
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700235
236#endif