blob: faa7c3af1fd9761341295c5aa8e60d865a5af5f2 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shibc19b372014-03-23 16:59:25 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Junxiao Shibc19b372014-03-23 16:59:25 -070020 */
21
22#ifndef NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP
23#define NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP
24
Junxiao Shi65f1a712014-11-20 14:59:36 -070025#include "../encoding/nfd-constants.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070026#include "../name.hpp"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070027#include "../util/time.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070028
29namespace ndn {
30namespace nfd {
31
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040032/**
33 * \ingroup management
34 */
Junxiao Shi5ec80222014-03-25 20:08:05 -070035enum ControlParameterField {
36 CONTROL_PARAMETER_NAME,
37 CONTROL_PARAMETER_FACE_ID,
38 CONTROL_PARAMETER_URI,
39 CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070040 CONTROL_PARAMETER_ORIGIN,
Junxiao Shi5ec80222014-03-25 20:08:05 -070041 CONTROL_PARAMETER_COST,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070042 CONTROL_PARAMETER_FLAGS,
Junxiao Shi5ec80222014-03-25 20:08:05 -070043 CONTROL_PARAMETER_STRATEGY,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070044 CONTROL_PARAMETER_EXPIRATION_PERIOD,
Junxiao Shi5ec80222014-03-25 20:08:05 -070045 CONTROL_PARAMETER_UBOUND
46};
47
48const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
49 "Name",
50 "FaceId",
51 "Uri",
52 "LocalControlFeature",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070053 "Origin",
Junxiao Shi5ec80222014-03-25 20:08:05 -070054 "Cost",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070055 "Flags",
Junxiao Shi5ec80222014-03-25 20:08:05 -070056 "Strategy",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070057 "ExpirationPeriod",
Junxiao Shi5ec80222014-03-25 20:08:05 -070058};
59
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040060/**
61 * \ingroup management
62 */
Junxiao Shibc19b372014-03-23 16:59:25 -070063enum LocalControlFeature {
64 LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID = 1,
65 LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID = 2
66};
67
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040068/**
Junxiao Shi70911652014-08-12 10:14:24 -070069 * @ingroup management
70 * @brief represents parameters in a ControlCommand request or response
71 * @sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand#ControlParameters
72 * @detail This type is copyable because it's an abstraction of a TLV type.
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070073 */
74class ControlParameters
75{
Junxiao Shibc19b372014-03-23 16:59:25 -070076public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060077 class Error : public tlv::Error
Junxiao Shibc19b372014-03-23 16:59:25 -070078 {
79 public:
80 explicit
81 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060082 : tlv::Error(what)
Junxiao Shibc19b372014-03-23 16:59:25 -070083 {
84 }
85 };
86
Junxiao Shi70911652014-08-12 10:14:24 -070087 ControlParameters();
Junxiao Shibc19b372014-03-23 16:59:25 -070088
89 explicit
Junxiao Shi70911652014-08-12 10:14:24 -070090 ControlParameters(const Block& block);
Junxiao Shibc19b372014-03-23 16:59:25 -070091
92 template<bool T>
93 size_t
94 wireEncode(EncodingImpl<T>& encoder) const;
95
96 const Block&
97 wireEncode() const;
98
99 void
100 wireDecode(const Block& wire);
101
102public: // getters & setters
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700103
Junxiao Shibc19b372014-03-23 16:59:25 -0700104 bool
105 hasName() const
106 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700107 return m_hasFields[CONTROL_PARAMETER_NAME];
Junxiao Shibc19b372014-03-23 16:59:25 -0700108 }
109
110 const Name&
111 getName() const
112 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700113 BOOST_ASSERT(this->hasName());
Junxiao Shibc19b372014-03-23 16:59:25 -0700114 return m_name;
115 }
116
117 ControlParameters&
118 setName(const Name& name)
119 {
120 m_wire.reset();
121 m_name = name;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700122 m_hasFields[CONTROL_PARAMETER_NAME] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700123 return *this;
124 }
125
126 ControlParameters&
127 unsetName()
128 {
129 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700130 m_hasFields[CONTROL_PARAMETER_NAME] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700131 return *this;
132 }
133
134 bool
135 hasFaceId() const
136 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700137 return m_hasFields[CONTROL_PARAMETER_FACE_ID];
Junxiao Shibc19b372014-03-23 16:59:25 -0700138 }
139
140 uint64_t
141 getFaceId() const
142 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700143 BOOST_ASSERT(this->hasFaceId());
Junxiao Shibc19b372014-03-23 16:59:25 -0700144 return m_faceId;
145 }
146
147 ControlParameters&
148 setFaceId(uint64_t faceId)
149 {
150 m_wire.reset();
151 m_faceId = faceId;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700152 m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700153 return *this;
154 }
155
156 ControlParameters&
157 unsetFaceId()
158 {
159 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700160 m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700161 return *this;
162 }
163
164 bool
165 hasUri() const
166 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700167 return m_hasFields[CONTROL_PARAMETER_URI];
Junxiao Shibc19b372014-03-23 16:59:25 -0700168 }
169
170 const std::string&
171 getUri() const
172 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700173 BOOST_ASSERT(this->hasUri());
Junxiao Shibc19b372014-03-23 16:59:25 -0700174 return m_uri;
175 }
176
177 ControlParameters&
178 setUri(const std::string& uri)
179 {
180 m_wire.reset();
181 m_uri = uri;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700182 m_hasFields[CONTROL_PARAMETER_URI] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700183 return *this;
184 }
185
186 ControlParameters&
187 unsetUri()
188 {
189 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700190 m_hasFields[CONTROL_PARAMETER_URI] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700191 return *this;
192 }
193
194 bool
195 hasLocalControlFeature() const
196 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700197 return m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE];
Junxiao Shibc19b372014-03-23 16:59:25 -0700198 }
199
200 LocalControlFeature
201 getLocalControlFeature() const
202 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700203 BOOST_ASSERT(this->hasLocalControlFeature());
Junxiao Shibc19b372014-03-23 16:59:25 -0700204 return m_localControlFeature;
205 }
206
207 ControlParameters&
208 setLocalControlFeature(LocalControlFeature localControlFeature)
209 {
210 m_wire.reset();
211 m_localControlFeature = localControlFeature;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700212 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700213 return *this;
214 }
215
216 ControlParameters&
217 unsetLocalControlFeature()
218 {
219 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700220 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700221 return *this;
222 }
223
224 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700225 hasOrigin() const
226 {
227 return m_hasFields[CONTROL_PARAMETER_ORIGIN];
228 }
229
230 uint64_t
231 getOrigin() const
232 {
233 BOOST_ASSERT(this->hasOrigin());
234 return m_origin;
235 }
236
237 ControlParameters&
238 setOrigin(uint64_t origin)
239 {
240 m_wire.reset();
241 m_origin = origin;
242 m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
243 return *this;
244 }
245
246 ControlParameters&
247 unsetOrigin()
248 {
249 m_wire.reset();
250 m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
251 return *this;
252 }
253
254 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700255 hasCost() const
256 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700257 return m_hasFields[CONTROL_PARAMETER_COST];
Junxiao Shibc19b372014-03-23 16:59:25 -0700258 }
259
260 uint64_t
261 getCost() const
262 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700263 BOOST_ASSERT(this->hasCost());
Junxiao Shibc19b372014-03-23 16:59:25 -0700264 return m_cost;
265 }
266
267 ControlParameters&
268 setCost(uint64_t cost)
269 {
270 m_wire.reset();
271 m_cost = cost;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700272 m_hasFields[CONTROL_PARAMETER_COST] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700273 return *this;
274 }
275
276 ControlParameters&
277 unsetCost()
278 {
279 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700280 m_hasFields[CONTROL_PARAMETER_COST] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700281 return *this;
282 }
283
284 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700285 hasFlags() const
286 {
287 return m_hasFields[CONTROL_PARAMETER_FLAGS];
288 }
289
290 uint64_t
291 getFlags() const
292 {
293 BOOST_ASSERT(this->hasFlags());
294 return m_flags;
295 }
296
297 ControlParameters&
298 setFlags(uint64_t flags)
299 {
300 m_wire.reset();
301 m_flags = flags;
302 m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
303 return *this;
304 }
305
306 ControlParameters&
307 unsetFlags()
308 {
309 m_wire.reset();
310 m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
311 return *this;
312 }
313
314 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700315 hasStrategy() const
316 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700317 return m_hasFields[CONTROL_PARAMETER_STRATEGY];
Junxiao Shibc19b372014-03-23 16:59:25 -0700318 }
319
320 const Name&
321 getStrategy() const
322 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700323 BOOST_ASSERT(this->hasStrategy());
Junxiao Shibc19b372014-03-23 16:59:25 -0700324 return m_strategy;
325 }
326
327 ControlParameters&
328 setStrategy(const Name& strategy)
329 {
330 m_wire.reset();
331 m_strategy = strategy;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700332 m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700333 return *this;
334 }
335
336 ControlParameters&
337 unsetStrategy()
338 {
339 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700340 m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700341 return *this;
342 }
343
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700344 bool
345 hasExpirationPeriod() const
346 {
347 return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
348 }
349
350 const time::milliseconds&
351 getExpirationPeriod() const
352 {
353 BOOST_ASSERT(this->hasExpirationPeriod());
354 return m_expirationPeriod;
355 }
356
357 ControlParameters&
358 setExpirationPeriod(const time::milliseconds& expirationPeriod)
359 {
360 m_wire.reset();
361 m_expirationPeriod = expirationPeriod;
362 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
363 return *this;
364 }
365
366 ControlParameters&
367 unsetExpirationPeriod()
368 {
369 m_wire.reset();
370 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
371 return *this;
372 }
373
Junxiao Shi5ec80222014-03-25 20:08:05 -0700374 const std::vector<bool>&
375 getPresentFields() const
376 {
377 return m_hasFields;
378 }
379
Junxiao Shibc19b372014-03-23 16:59:25 -0700380private: // fields
Junxiao Shi5ec80222014-03-25 20:08:05 -0700381 std::vector<bool> m_hasFields;
382
Junxiao Shibc19b372014-03-23 16:59:25 -0700383 Name m_name;
384 uint64_t m_faceId;
385 std::string m_uri;
386 LocalControlFeature m_localControlFeature;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700387 uint64_t m_origin;
Junxiao Shibc19b372014-03-23 16:59:25 -0700388 uint64_t m_cost;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700389 uint64_t m_flags;
Junxiao Shibc19b372014-03-23 16:59:25 -0700390 Name m_strategy;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700391 time::milliseconds m_expirationPeriod;
Junxiao Shibc19b372014-03-23 16:59:25 -0700392
Junxiao Shibc19b372014-03-23 16:59:25 -0700393private:
394 mutable Block m_wire;
395};
396
Junxiao Shi70911652014-08-12 10:14:24 -0700397std::ostream&
398operator<<(std::ostream& os, const ControlParameters& parameters);
Junxiao Shibc19b372014-03-23 16:59:25 -0700399
400} // namespace nfd
401} // namespace ndn
402
403#endif // NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP