blob: 82c08adb700f99f05501598e49853d7b348afac2 [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
25#include "../name.hpp"
26#include "../encoding/tlv-nfd.hpp"
27
28namespace ndn {
29namespace nfd {
30
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040031/**
32 * \ingroup management
33 */
Junxiao Shi5ec80222014-03-25 20:08:05 -070034enum ControlParameterField {
35 CONTROL_PARAMETER_NAME,
36 CONTROL_PARAMETER_FACE_ID,
37 CONTROL_PARAMETER_URI,
38 CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070039 CONTROL_PARAMETER_ORIGIN,
Junxiao Shi5ec80222014-03-25 20:08:05 -070040 CONTROL_PARAMETER_COST,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070041 CONTROL_PARAMETER_FLAGS,
Junxiao Shi5ec80222014-03-25 20:08:05 -070042 CONTROL_PARAMETER_STRATEGY,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070043 CONTROL_PARAMETER_EXPIRATION_PERIOD,
Junxiao Shi5ec80222014-03-25 20:08:05 -070044 CONTROL_PARAMETER_UBOUND
45};
46
47const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
48 "Name",
49 "FaceId",
50 "Uri",
51 "LocalControlFeature",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070052 "Origin",
Junxiao Shi5ec80222014-03-25 20:08:05 -070053 "Cost",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070054 "Flags",
Junxiao Shi5ec80222014-03-25 20:08:05 -070055 "Strategy",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070056 "ExpirationPeriod",
Junxiao Shi5ec80222014-03-25 20:08:05 -070057};
58
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040059/**
60 * \ingroup management
61 */
Junxiao Shibc19b372014-03-23 16:59:25 -070062enum LocalControlFeature {
63 LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID = 1,
64 LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID = 2
65};
66
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040067/**
68 * \ingroup management
69 * \brief represents parameters in a ControlCommand request or response
70 * \sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070071 */
72class ControlParameters
73{
Junxiao Shibc19b372014-03-23 16:59:25 -070074public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060075 class Error : public tlv::Error
Junxiao Shibc19b372014-03-23 16:59:25 -070076 {
77 public:
78 explicit
79 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060080 : tlv::Error(what)
Junxiao Shibc19b372014-03-23 16:59:25 -070081 {
82 }
83 };
84
Junxiao Shi5ec80222014-03-25 20:08:05 -070085 ControlParameters()
86 : m_hasFields(CONTROL_PARAMETER_UBOUND)
87 {
88 }
Junxiao Shibc19b372014-03-23 16:59:25 -070089
90 explicit
91 ControlParameters(const Block& block)
Junxiao Shi5ec80222014-03-25 20:08:05 -070092 : m_hasFields(CONTROL_PARAMETER_UBOUND)
Junxiao Shibc19b372014-03-23 16:59:25 -070093 {
94 wireDecode(block);
95 }
96
97 template<bool T>
98 size_t
99 wireEncode(EncodingImpl<T>& encoder) const;
100
101 const Block&
102 wireEncode() const;
103
104 void
105 wireDecode(const Block& wire);
106
107public: // getters & setters
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700108
Junxiao Shibc19b372014-03-23 16:59:25 -0700109 bool
110 hasName() const
111 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700112 return m_hasFields[CONTROL_PARAMETER_NAME];
Junxiao Shibc19b372014-03-23 16:59:25 -0700113 }
114
115 const Name&
116 getName() const
117 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700118 BOOST_ASSERT(this->hasName());
Junxiao Shibc19b372014-03-23 16:59:25 -0700119 return m_name;
120 }
121
122 ControlParameters&
123 setName(const Name& name)
124 {
125 m_wire.reset();
126 m_name = name;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700127 m_hasFields[CONTROL_PARAMETER_NAME] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700128 return *this;
129 }
130
131 ControlParameters&
132 unsetName()
133 {
134 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700135 m_hasFields[CONTROL_PARAMETER_NAME] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700136 return *this;
137 }
138
139 bool
140 hasFaceId() const
141 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700142 return m_hasFields[CONTROL_PARAMETER_FACE_ID];
Junxiao Shibc19b372014-03-23 16:59:25 -0700143 }
144
145 uint64_t
146 getFaceId() const
147 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700148 BOOST_ASSERT(this->hasFaceId());
Junxiao Shibc19b372014-03-23 16:59:25 -0700149 return m_faceId;
150 }
151
152 ControlParameters&
153 setFaceId(uint64_t faceId)
154 {
155 m_wire.reset();
156 m_faceId = faceId;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700157 m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700158 return *this;
159 }
160
161 ControlParameters&
162 unsetFaceId()
163 {
164 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700165 m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700166 return *this;
167 }
168
169 bool
170 hasUri() const
171 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700172 return m_hasFields[CONTROL_PARAMETER_URI];
Junxiao Shibc19b372014-03-23 16:59:25 -0700173 }
174
175 const std::string&
176 getUri() const
177 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700178 BOOST_ASSERT(this->hasUri());
Junxiao Shibc19b372014-03-23 16:59:25 -0700179 return m_uri;
180 }
181
182 ControlParameters&
183 setUri(const std::string& uri)
184 {
185 m_wire.reset();
186 m_uri = uri;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700187 m_hasFields[CONTROL_PARAMETER_URI] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700188 return *this;
189 }
190
191 ControlParameters&
192 unsetUri()
193 {
194 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700195 m_hasFields[CONTROL_PARAMETER_URI] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700196 return *this;
197 }
198
199 bool
200 hasLocalControlFeature() const
201 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700202 return m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE];
Junxiao Shibc19b372014-03-23 16:59:25 -0700203 }
204
205 LocalControlFeature
206 getLocalControlFeature() const
207 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700208 BOOST_ASSERT(this->hasLocalControlFeature());
Junxiao Shibc19b372014-03-23 16:59:25 -0700209 return m_localControlFeature;
210 }
211
212 ControlParameters&
213 setLocalControlFeature(LocalControlFeature localControlFeature)
214 {
215 m_wire.reset();
216 m_localControlFeature = localControlFeature;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700217 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700218 return *this;
219 }
220
221 ControlParameters&
222 unsetLocalControlFeature()
223 {
224 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700225 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700226 return *this;
227 }
228
229 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700230 hasOrigin() const
231 {
232 return m_hasFields[CONTROL_PARAMETER_ORIGIN];
233 }
234
235 uint64_t
236 getOrigin() const
237 {
238 BOOST_ASSERT(this->hasOrigin());
239 return m_origin;
240 }
241
242 ControlParameters&
243 setOrigin(uint64_t origin)
244 {
245 m_wire.reset();
246 m_origin = origin;
247 m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
248 return *this;
249 }
250
251 ControlParameters&
252 unsetOrigin()
253 {
254 m_wire.reset();
255 m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
256 return *this;
257 }
258
259 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700260 hasCost() const
261 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700262 return m_hasFields[CONTROL_PARAMETER_COST];
Junxiao Shibc19b372014-03-23 16:59:25 -0700263 }
264
265 uint64_t
266 getCost() const
267 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700268 BOOST_ASSERT(this->hasCost());
Junxiao Shibc19b372014-03-23 16:59:25 -0700269 return m_cost;
270 }
271
272 ControlParameters&
273 setCost(uint64_t cost)
274 {
275 m_wire.reset();
276 m_cost = cost;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700277 m_hasFields[CONTROL_PARAMETER_COST] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700278 return *this;
279 }
280
281 ControlParameters&
282 unsetCost()
283 {
284 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700285 m_hasFields[CONTROL_PARAMETER_COST] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700286 return *this;
287 }
288
289 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700290 hasFlags() const
291 {
292 return m_hasFields[CONTROL_PARAMETER_FLAGS];
293 }
294
295 uint64_t
296 getFlags() const
297 {
298 BOOST_ASSERT(this->hasFlags());
299 return m_flags;
300 }
301
302 ControlParameters&
303 setFlags(uint64_t flags)
304 {
305 m_wire.reset();
306 m_flags = flags;
307 m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
308 return *this;
309 }
310
311 ControlParameters&
312 unsetFlags()
313 {
314 m_wire.reset();
315 m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
316 return *this;
317 }
318
319 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700320 hasStrategy() const
321 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700322 return m_hasFields[CONTROL_PARAMETER_STRATEGY];
Junxiao Shibc19b372014-03-23 16:59:25 -0700323 }
324
325 const Name&
326 getStrategy() const
327 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700328 BOOST_ASSERT(this->hasStrategy());
Junxiao Shibc19b372014-03-23 16:59:25 -0700329 return m_strategy;
330 }
331
332 ControlParameters&
333 setStrategy(const Name& strategy)
334 {
335 m_wire.reset();
336 m_strategy = strategy;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700337 m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700338 return *this;
339 }
340
341 ControlParameters&
342 unsetStrategy()
343 {
344 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700345 m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700346 return *this;
347 }
348
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700349 bool
350 hasExpirationPeriod() const
351 {
352 return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
353 }
354
355 const time::milliseconds&
356 getExpirationPeriod() const
357 {
358 BOOST_ASSERT(this->hasExpirationPeriod());
359 return m_expirationPeriod;
360 }
361
362 ControlParameters&
363 setExpirationPeriod(const time::milliseconds& expirationPeriod)
364 {
365 m_wire.reset();
366 m_expirationPeriod = expirationPeriod;
367 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
368 return *this;
369 }
370
371 ControlParameters&
372 unsetExpirationPeriod()
373 {
374 m_wire.reset();
375 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
376 return *this;
377 }
378
Junxiao Shi5ec80222014-03-25 20:08:05 -0700379 const std::vector<bool>&
380 getPresentFields() const
381 {
382 return m_hasFields;
383 }
384
Junxiao Shibc19b372014-03-23 16:59:25 -0700385private: // fields
Junxiao Shi5ec80222014-03-25 20:08:05 -0700386 std::vector<bool> m_hasFields;
387
Junxiao Shibc19b372014-03-23 16:59:25 -0700388 Name m_name;
389 uint64_t m_faceId;
390 std::string m_uri;
391 LocalControlFeature m_localControlFeature;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700392 uint64_t m_origin;
Junxiao Shibc19b372014-03-23 16:59:25 -0700393 uint64_t m_cost;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700394 uint64_t m_flags;
Junxiao Shibc19b372014-03-23 16:59:25 -0700395 Name m_strategy;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700396 time::milliseconds m_expirationPeriod;
Junxiao Shibc19b372014-03-23 16:59:25 -0700397
Junxiao Shibc19b372014-03-23 16:59:25 -0700398private:
399 mutable Block m_wire;
400};
401
402
Junxiao Shibc19b372014-03-23 16:59:25 -0700403template<bool T>
404inline size_t
405ControlParameters::wireEncode(EncodingImpl<T>& encoder) const
406{
407 size_t totalLength = 0;
408
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700409 if (this->hasExpirationPeriod()) {
410 totalLength += prependNonNegativeIntegerBlock(encoder,
411 tlv::nfd::ExpirationPeriod, m_expirationPeriod.count());
412 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700413 if (this->hasStrategy()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700414 totalLength += prependNestedBlock(encoder, tlv::nfd::Strategy, m_strategy);
415 }
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700416 if (this->hasFlags()) {
417 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Flags, m_flags);
418 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700419 if (this->hasCost()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700420 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Cost, m_cost);
421 }
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700422 if (this->hasOrigin()) {
423 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Origin, m_origin);
424 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700425 if (this->hasLocalControlFeature()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700426 totalLength += prependNonNegativeIntegerBlock(encoder,
427 tlv::nfd::LocalControlFeature, m_localControlFeature);
428 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700429 if (this->hasUri()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700430 size_t valLength = encoder.prependByteArray(
431 reinterpret_cast<const uint8_t*>(m_uri.c_str()), m_uri.size());
432 totalLength += valLength;
433 totalLength += encoder.prependVarNumber(valLength);
434 totalLength += encoder.prependVarNumber(tlv::nfd::Uri);
435 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700436 if (this->hasFaceId()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700437 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FaceId, m_faceId);
438 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700439 if (this->hasName()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700440 totalLength += m_name.wireEncode(encoder);
441 }
442
443 totalLength += encoder.prependVarNumber(totalLength);
444 totalLength += encoder.prependVarNumber(tlv::nfd::ControlParameters);
445 return totalLength;
446}
447
448inline const Block&
449ControlParameters::wireEncode() const
450{
451 if (m_wire.hasWire())
452 return m_wire;
453
454 EncodingEstimator estimator;
455 size_t estimatedSize = wireEncode(estimator);
456
457 EncodingBuffer buffer(estimatedSize, 0);
458 wireEncode(buffer);
459
460 m_wire = buffer.block();
461 return m_wire;
462}
463
464inline void
465ControlParameters::wireDecode(const Block& block)
466{
467 if (block.type() != tlv::nfd::ControlParameters) {
468 throw Error("expecting TLV-TYPE ControlParameters");
469 }
470 m_wire = block;
471 m_wire.parse();
472 Block::element_const_iterator val;
473
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600474 val = m_wire.find(tlv::Name);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700475 m_hasFields[CONTROL_PARAMETER_NAME] = val != m_wire.elements_end();
476 if (this->hasName()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700477 m_name.wireDecode(*val);
478 }
479
480 val = m_wire.find(tlv::nfd::FaceId);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700481 m_hasFields[CONTROL_PARAMETER_FACE_ID] = val != m_wire.elements_end();
482 if (this->hasFaceId()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700483 m_faceId = static_cast<uint64_t>(readNonNegativeInteger(*val));
484 }
485
486 val = m_wire.find(tlv::nfd::Uri);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700487 m_hasFields[CONTROL_PARAMETER_URI] = val != m_wire.elements_end();
488 if (this->hasUri()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700489 m_uri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
490 }
491
492 val = m_wire.find(tlv::nfd::LocalControlFeature);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700493 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = val != m_wire.elements_end();
494 if (this->hasLocalControlFeature()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700495 m_localControlFeature = static_cast<LocalControlFeature>(readNonNegativeInteger(*val));
496 }
497
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700498 val = m_wire.find(tlv::nfd::Origin);
499 m_hasFields[CONTROL_PARAMETER_ORIGIN] = val != m_wire.elements_end();
500 if (this->hasOrigin()) {
501 m_origin = static_cast<uint64_t>(readNonNegativeInteger(*val));
502 }
503
Junxiao Shibc19b372014-03-23 16:59:25 -0700504 val = m_wire.find(tlv::nfd::Cost);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700505 m_hasFields[CONTROL_PARAMETER_COST] = val != m_wire.elements_end();
506 if (this->hasCost()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700507 m_cost = static_cast<uint64_t>(readNonNegativeInteger(*val));
508 }
509
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700510 val = m_wire.find(tlv::nfd::Flags);
511 m_hasFields[CONTROL_PARAMETER_FLAGS] = val != m_wire.elements_end();
512 if (this->hasFlags()) {
513 m_flags = static_cast<uint64_t>(readNonNegativeInteger(*val));
514 }
515
Junxiao Shibc19b372014-03-23 16:59:25 -0700516 val = m_wire.find(tlv::nfd::Strategy);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700517 m_hasFields[CONTROL_PARAMETER_STRATEGY] = val != m_wire.elements_end();
518 if (this->hasStrategy()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700519 val->parse();
520 if (val->elements().empty()) {
521 throw Error("expecting Strategy/Name");
522 }
523 else {
524 m_strategy.wireDecode(*val->elements_begin());
525 }
526 }
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700527
528 val = m_wire.find(tlv::nfd::ExpirationPeriod);
529 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = val != m_wire.elements_end();
530 if (this->hasExpirationPeriod()) {
531 m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val));
532 }
Junxiao Shibc19b372014-03-23 16:59:25 -0700533}
534
535inline std::ostream&
536operator<<(std::ostream& os, const ControlParameters& parameters)
537{
538 os << "ControlParameters(";
539
540 if (parameters.hasName()) {
541 os << "Name: " << parameters.getName() << ", ";
542 }
543
544 if (parameters.hasFaceId()) {
545 os << "FaceId: " << parameters.getFaceId() << ", ";
546 }
547
548 if (parameters.hasUri()) {
549 os << "Uri: " << parameters.getUri() << ", ";
550 }
551
552 if (parameters.hasLocalControlFeature()) {
553 os << "LocalControlFeature: " << parameters.getLocalControlFeature() << ", ";
554 }
555
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700556 if (parameters.hasOrigin()) {
557 os << "Origin: " << parameters.getOrigin() << ", ";
558 }
559
Junxiao Shibc19b372014-03-23 16:59:25 -0700560 if (parameters.hasCost()) {
561 os << "Cost: " << parameters.getCost() << ", ";
562 }
563
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700564 if (parameters.hasFlags()) {
565 os << "Flags: " << parameters.getFlags() << ", ";
566 }
567
Junxiao Shibc19b372014-03-23 16:59:25 -0700568 if (parameters.hasStrategy()) {
569 os << "Strategy: " << parameters.getStrategy() << ", ";
570 }
571
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700572 if (parameters.hasExpirationPeriod()) {
573 os << "ExpirationPeriod: " << parameters.getExpirationPeriod() << ", ";
574 }
575
Junxiao Shibc19b372014-03-23 16:59:25 -0700576 os << ")";
577 return os;
578}
579
580
581} // namespace nfd
582} // namespace ndn
583
584#endif // NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP