blob: 8b4ce7880229987da5cea066a646cc98bef24d71 [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"
12#include "../encoding/tlv-face-management.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 */
27 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 /**
40 * Get the value of the "active" flag.
41 * @return true if the flag is set, false if it is cleared.
42 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080043 bool getActive() const { return active_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070044
45 /**
46 * Get the value of the "childInherit" flag.
47 * @return true if the flag is set, false if it is cleared.
48 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080049 bool getChildInherit() const { return childInherit_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070050
51 /**
52 * Get the value of the "advertise" flag.
53 * @return true if the flag is set, false if it is cleared.
54 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080055 bool getAdvertise() const { return advertise_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070056
57 /**
58 * Get the value of the "last" flag.
59 * @return true if the flag is set, false if it is cleared.
60 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080061 bool getLast() const { return last_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070062
63 /**
64 * Get the value of the "capture" flag.
65 * @return true if the flag is set, false if it is cleared.
66 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080067 bool getCapture() const { return capture_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070068
69 /**
70 * Get the value of the "local" flag.
71 * @return true if the flag is set, false if it is cleared.
72 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080073 bool getLocal() const { return local_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070074
75 /**
76 * Get the value of the "tap" flag.
77 * @return true if the flag is set, false if it is cleared.
78 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080079 bool getTap() const { return tap_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070080
81 /**
82 * Get the value of the "captureOk" flag.
83 * @return true if the flag is set, false if it is cleared.
84 */
Alexander Afanasyev895b2f32014-01-03 13:24:52 -080085 bool getCaptureOk() const { return captureOk_; }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070086
87 /**
88 * Set the value of the "active" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -080089 * @param active true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070090 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -080091 void setActive(bool active) { this->active_ = active; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070092
93 /**
94 * Set the value of the "childInherit" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -080095 * @param childInherit true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070096 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -080097 void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -070098
99 /**
100 * Set the value of the "advertise" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800101 * @param advertise true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700102 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800103 void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700104
105 /**
106 * Set the value of the "last" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800107 * @param last true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700108 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800109 void setLast(bool last) { this->last_ = last; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700110
111 /**
112 * Set the value of the "capture" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800113 * @param capture true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700114 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800115 void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700116
117 /**
118 * Set the value of the "local" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800119 * @param local true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700120 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800121 void setLocal(bool local) { this->local_ = local; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700122
123 /**
124 * Set the value of the "tap" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800125 * @param tap true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700126 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800127 void setTap(bool tap) { this->tap_ = tap; wire_.reset(); }
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700128
129 /**
130 * Set the value of the "captureOk" flag
Jeff Thompson83bf07e2013-11-19 11:46:18 -0800131 * @param captureOk true to set the flag, false to clear it.
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700132 */
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800133 void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); }
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800134
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800135 inline const Block&
136 wireEncode() const;
137
138 inline void
139 wireDecode(const Block &block);
140
Alexander Afanasyev895b2f32014-01-03 13:24:52 -0800141private:
142 bool active_;
143 bool childInherit_;
144 bool advertise_;
145 bool last_;
146 bool capture_;
147 bool local_;
148 bool tap_;
149 bool captureOk_;
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800150
151 mutable Block wire_;
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700152};
153
Alexander Afanasyev10d902e2014-01-03 15:27:40 -0800154inline const Block&
155ForwardingFlags::wireEncode() const
156{
157 if (wire_.hasWire())
158 return wire_;
159
160 uint32_t result = 0;
161 if (active_)
162 result |= Tlv::FaceManagement::FORW_ACTIVE;
163 if (childInherit_)
164 result |= Tlv::FaceManagement::FORW_CHILD_INHERIT;
165 if (advertise_)
166 result |= Tlv::FaceManagement::FORW_ADVERTISE;
167 if (last_)
168 result |= Tlv::FaceManagement::FORW_LAST;
169 if (capture_)
170 result |= Tlv::FaceManagement::FORW_CAPTURE;
171 if (local_)
172 result |= Tlv::FaceManagement::FORW_LOCAL;
173 if (tap_)
174 result |= Tlv::FaceManagement::FORW_TAP;
175 if (captureOk_)
176 result |= Tlv::FaceManagement::FORW_CAPTURE_OK;
177
178 wire_ = nonNegativeIntegerBlock(Tlv::FaceManagement::ForwardingFlags, result);
179
180 return wire_;
181}
182
183inline void
184ForwardingFlags::wireDecode(const Block &wire)
185{
186 wire_ = wire;
187
188 uint32_t flags = readNonNegativeInteger(wire_);
189
190 active_ = (flags & Tlv::FaceManagement::FORW_ACTIVE) ? true : false;
191 childInherit_ = (flags & Tlv::FaceManagement::FORW_CHILD_INHERIT) ? true : false;
192 advertise_ = (flags & Tlv::FaceManagement::FORW_ADVERTISE) ? true : false;
193 last_ = (flags & Tlv::FaceManagement::FORW_LAST) ? true : false;
194 capture_ = (flags & Tlv::FaceManagement::FORW_CAPTURE) ? true : false;
195 local_ = (flags & Tlv::FaceManagement::FORW_LOCAL) ? true : false;
196 tap_ = (flags & Tlv::FaceManagement::FORW_TAP) ? true : false;
197 captureOk_ = (flags & Tlv::FaceManagement::FORW_CAPTURE_OK) ? true : false;
198}
199
Alexander Afanasyev816cf942014-01-03 15:33:41 -0800200inline std::ostream&
201operator << (std::ostream &os, const ForwardingFlags &flags)
202{
203 if (flags.getActive())
204 os << "ACTIVE ";
205 if (flags.getChildInherit())
206 os << "CHILE_INHERIT ";
207 if (flags.getAdvertise())
208 os << "ADVERTISE ";
209 if (flags.getLast())
210 os << "LAST ";
211 if (flags.getCapture())
212 os << "CAPTURE ";
213 if (flags.getLocal())
214 os << "LOCAL ";
215 if (flags.getTap())
216 os << "TAP ";
217 if (flags.getCaptureOk())
218 os << "CAPTURE_OK ";
219
220 return os;
221}
222
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -0800223} // namespace ndnd
224} // namespace ndn
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700225
226#endif