blob: f8e62c7622fc7b01e16ad44b634ce1557c4a7159 [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)
35
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
Jeff Thompson1f8a31a2013-09-30 16:18:47 -0700200}
201
202#endif