blob: a0c81c1e2cffc96e514001c1a5fdb431f3a445b2 [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 Afanasyev10d902e2014-01-03 15:27:40 -080011#include "encoding/block.hpp"
12#include "encoding/tlv-face-management.hpp"
13
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070014namespace ndn {
15
16/**
17 * A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an interest for
18 * a registered prefix. We use a separate ForwardingFlags object to retain future compatibility if the daemon forwarding
19 * bits are changed, amended or deprecated.
20 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080021class ForwardingFlags {
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070022public:
23 /**
24 * Create a new ForwardingFlags with "active" and "childInherit" set and all other flags cleared.
25 */
26 ForwardingFlags()
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080027 : active_(true)
28 , childInherit_(true)
29 , advertise_(false)
30 , last_(false)
31 , capture_(false)
32 , local_(false)
33 , tap_(false)
34 , captureOk_(false)
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070035 {
36 }
37
38 /**
39 * Get the value of the "active" flag.
40 * @return true if the flag is set, false if it is cleared.
41 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080042 bool getActive() const { return active_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070043
44 /**
45 * Get the value of the "childInherit" flag.
46 * @return true if the flag is set, false if it is cleared.
47 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080048 bool getChildInherit() const { return childInherit_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070049
50 /**
51 * Get the value of the "advertise" flag.
52 * @return true if the flag is set, false if it is cleared.
53 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080054 bool getAdvertise() const { return advertise_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070055
56 /**
57 * Get the value of the "last" flag.
58 * @return true if the flag is set, false if it is cleared.
59 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080060 bool getLast() const { return last_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070061
62 /**
63 * Get the value of the "capture" flag.
64 * @return true if the flag is set, false if it is cleared.
65 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080066 bool getCapture() const { return capture_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070067
68 /**
69 * Get the value of the "local" flag.
70 * @return true if the flag is set, false if it is cleared.
71 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080072 bool getLocal() const { return local_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070073
74 /**
75 * Get the value of the "tap" flag.
76 * @return true if the flag is set, false if it is cleared.
77 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080078 bool getTap() const { return tap_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070079
80 /**
81 * Get the value of the "captureOk" flag.
82 * @return true if the flag is set, false if it is cleared.
83 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080084 bool getCaptureOk() const { return captureOk_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070085
86 /**
87 * Set the value of the "active" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -080088 * @param active true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070089 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -080090 void setActive(bool active) { this->active_ = active; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070091
92 /**
93 * Set the value of the "childInherit" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -080094 * @param childInherit true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070095 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -080096 void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070097
98 /**
99 * Set the value of the "advertise" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800100 * @param advertise true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700101 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800102 void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700103
104 /**
105 * Set the value of the "last" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800106 * @param last true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700107 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800108 void setLast(bool last) { this->last_ = last; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700109
110 /**
111 * Set the value of the "capture" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800112 * @param capture true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700113 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800114 void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700115
116 /**
117 * Set the value of the "local" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800118 * @param local true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700119 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800120 void setLocal(bool local) { this->local_ = local; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700121
122 /**
123 * Set the value of the "tap" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800124 * @param tap true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700125 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800126 void setTap(bool tap) { this->tap_ = tap; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700127
128 /**
129 * Set the value of the "captureOk" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800130 * @param captureOk true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700131 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800132 void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); }
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800133
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800134 inline const Block&
135 wireEncode() const;
136
137 inline void
138 wireDecode(const Block &block);
139
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800140private:
141 bool active_;
142 bool childInherit_;
143 bool advertise_;
144 bool last_;
145 bool capture_;
146 bool local_;
147 bool tap_;
148 bool captureOk_;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800149
150 mutable Block wire_;
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700151};
152
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800153inline const Block&
154ForwardingFlags::wireEncode() const
155{
156 if (wire_.hasWire())
157 return wire_;
158
159 uint32_t result = 0;
160 if (active_)
161 result |= Tlv::FaceManagement::FORW_ACTIVE;
162 if (childInherit_)
163 result |= Tlv::FaceManagement::FORW_CHILD_INHERIT;
164 if (advertise_)
165 result |= Tlv::FaceManagement::FORW_ADVERTISE;
166 if (last_)
167 result |= Tlv::FaceManagement::FORW_LAST;
168 if (capture_)
169 result |= Tlv::FaceManagement::FORW_CAPTURE;
170 if (local_)
171 result |= Tlv::FaceManagement::FORW_LOCAL;
172 if (tap_)
173 result |= Tlv::FaceManagement::FORW_TAP;
174 if (captureOk_)
175 result |= Tlv::FaceManagement::FORW_CAPTURE_OK;
176
177 wire_ = nonNegativeIntegerBlock(Tlv::FaceManagement::ForwardingFlags, result);
178
179 return wire_;
180}
181
182inline void
183ForwardingFlags::wireDecode(const Block &wire)
184{
185 wire_ = wire;
186
187 uint32_t flags = readNonNegativeInteger(wire_);
188
189 active_ = (flags & Tlv::FaceManagement::FORW_ACTIVE) ? true : false;
190 childInherit_ = (flags & Tlv::FaceManagement::FORW_CHILD_INHERIT) ? true : false;
191 advertise_ = (flags & Tlv::FaceManagement::FORW_ADVERTISE) ? true : false;
192 last_ = (flags & Tlv::FaceManagement::FORW_LAST) ? true : false;
193 capture_ = (flags & Tlv::FaceManagement::FORW_CAPTURE) ? true : false;
194 local_ = (flags & Tlv::FaceManagement::FORW_LOCAL) ? true : false;
195 tap_ = (flags & Tlv::FaceManagement::FORW_TAP) ? true : false;
196 captureOk_ = (flags & Tlv::FaceManagement::FORW_CAPTURE_OK) ? true : false;
197}
198
Alexander Afanasyev816cf942014-01-03 15:33:41 -0800199inline std::ostream&
200operator << (std::ostream &os, const ForwardingFlags &flags)
201{
202 if (flags.getActive())
203 os << "ACTIVE ";
204 if (flags.getChildInherit())
205 os << "CHILE_INHERIT ";
206 if (flags.getAdvertise())
207 os << "ADVERTISE ";
208 if (flags.getLast())
209 os << "LAST ";
210 if (flags.getCapture())
211 os << "CAPTURE ";
212 if (flags.getLocal())
213 os << "LOCAL ";
214 if (flags.getTap())
215 os << "TAP ";
216 if (flags.getCaptureOk())
217 os << "CAPTURE_OK ";
218
219 return os;
220}
221
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700222}
223
224#endif