blob: 0ab0f84442e5fa3483bda7d122021e8ea3b77905 [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"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070027#include "../encoding/block-helpers.hpp"
28#include "../util/time.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070029
30namespace ndn {
31namespace nfd {
32
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040033/**
34 * \ingroup management
35 */
Junxiao Shi5ec80222014-03-25 20:08:05 -070036enum ControlParameterField {
37 CONTROL_PARAMETER_NAME,
38 CONTROL_PARAMETER_FACE_ID,
39 CONTROL_PARAMETER_URI,
40 CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070041 CONTROL_PARAMETER_ORIGIN,
Junxiao Shi5ec80222014-03-25 20:08:05 -070042 CONTROL_PARAMETER_COST,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070043 CONTROL_PARAMETER_FLAGS,
Junxiao Shi5ec80222014-03-25 20:08:05 -070044 CONTROL_PARAMETER_STRATEGY,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070045 CONTROL_PARAMETER_EXPIRATION_PERIOD,
Junxiao Shi5ec80222014-03-25 20:08:05 -070046 CONTROL_PARAMETER_UBOUND
47};
48
49const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
50 "Name",
51 "FaceId",
52 "Uri",
53 "LocalControlFeature",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070054 "Origin",
Junxiao Shi5ec80222014-03-25 20:08:05 -070055 "Cost",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070056 "Flags",
Junxiao Shi5ec80222014-03-25 20:08:05 -070057 "Strategy",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070058 "ExpirationPeriod",
Junxiao Shi5ec80222014-03-25 20:08:05 -070059};
60
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040061/**
62 * \ingroup management
63 */
Junxiao Shibc19b372014-03-23 16:59:25 -070064enum LocalControlFeature {
65 LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID = 1,
66 LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID = 2
67};
68
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040069/**
70 * \ingroup management
71 * \brief represents parameters in a ControlCommand request or response
72 * \sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand
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 Shi5ec80222014-03-25 20:08:05 -070087 ControlParameters()
88 : m_hasFields(CONTROL_PARAMETER_UBOUND)
89 {
90 }
Junxiao Shibc19b372014-03-23 16:59:25 -070091
92 explicit
93 ControlParameters(const Block& block)
Junxiao Shi5ec80222014-03-25 20:08:05 -070094 : m_hasFields(CONTROL_PARAMETER_UBOUND)
Junxiao Shibc19b372014-03-23 16:59:25 -070095 {
96 wireDecode(block);
97 }
98
99 template<bool T>
100 size_t
101 wireEncode(EncodingImpl<T>& encoder) const;
102
103 const Block&
104 wireEncode() const;
105
106 void
107 wireDecode(const Block& wire);
108
109public: // getters & setters
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700110
Junxiao Shibc19b372014-03-23 16:59:25 -0700111 bool
112 hasName() const
113 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700114 return m_hasFields[CONTROL_PARAMETER_NAME];
Junxiao Shibc19b372014-03-23 16:59:25 -0700115 }
116
117 const Name&
118 getName() const
119 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700120 BOOST_ASSERT(this->hasName());
Junxiao Shibc19b372014-03-23 16:59:25 -0700121 return m_name;
122 }
123
124 ControlParameters&
125 setName(const Name& name)
126 {
127 m_wire.reset();
128 m_name = name;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700129 m_hasFields[CONTROL_PARAMETER_NAME] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700130 return *this;
131 }
132
133 ControlParameters&
134 unsetName()
135 {
136 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700137 m_hasFields[CONTROL_PARAMETER_NAME] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700138 return *this;
139 }
140
141 bool
142 hasFaceId() const
143 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700144 return m_hasFields[CONTROL_PARAMETER_FACE_ID];
Junxiao Shibc19b372014-03-23 16:59:25 -0700145 }
146
147 uint64_t
148 getFaceId() const
149 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700150 BOOST_ASSERT(this->hasFaceId());
Junxiao Shibc19b372014-03-23 16:59:25 -0700151 return m_faceId;
152 }
153
154 ControlParameters&
155 setFaceId(uint64_t faceId)
156 {
157 m_wire.reset();
158 m_faceId = faceId;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700159 m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700160 return *this;
161 }
162
163 ControlParameters&
164 unsetFaceId()
165 {
166 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700167 m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700168 return *this;
169 }
170
171 bool
172 hasUri() const
173 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700174 return m_hasFields[CONTROL_PARAMETER_URI];
Junxiao Shibc19b372014-03-23 16:59:25 -0700175 }
176
177 const std::string&
178 getUri() const
179 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700180 BOOST_ASSERT(this->hasUri());
Junxiao Shibc19b372014-03-23 16:59:25 -0700181 return m_uri;
182 }
183
184 ControlParameters&
185 setUri(const std::string& uri)
186 {
187 m_wire.reset();
188 m_uri = uri;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700189 m_hasFields[CONTROL_PARAMETER_URI] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700190 return *this;
191 }
192
193 ControlParameters&
194 unsetUri()
195 {
196 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700197 m_hasFields[CONTROL_PARAMETER_URI] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700198 return *this;
199 }
200
201 bool
202 hasLocalControlFeature() const
203 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700204 return m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE];
Junxiao Shibc19b372014-03-23 16:59:25 -0700205 }
206
207 LocalControlFeature
208 getLocalControlFeature() const
209 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700210 BOOST_ASSERT(this->hasLocalControlFeature());
Junxiao Shibc19b372014-03-23 16:59:25 -0700211 return m_localControlFeature;
212 }
213
214 ControlParameters&
215 setLocalControlFeature(LocalControlFeature localControlFeature)
216 {
217 m_wire.reset();
218 m_localControlFeature = localControlFeature;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700219 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700220 return *this;
221 }
222
223 ControlParameters&
224 unsetLocalControlFeature()
225 {
226 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700227 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700228 return *this;
229 }
230
231 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700232 hasOrigin() const
233 {
234 return m_hasFields[CONTROL_PARAMETER_ORIGIN];
235 }
236
237 uint64_t
238 getOrigin() const
239 {
240 BOOST_ASSERT(this->hasOrigin());
241 return m_origin;
242 }
243
244 ControlParameters&
245 setOrigin(uint64_t origin)
246 {
247 m_wire.reset();
248 m_origin = origin;
249 m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
250 return *this;
251 }
252
253 ControlParameters&
254 unsetOrigin()
255 {
256 m_wire.reset();
257 m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
258 return *this;
259 }
260
261 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700262 hasCost() const
263 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700264 return m_hasFields[CONTROL_PARAMETER_COST];
Junxiao Shibc19b372014-03-23 16:59:25 -0700265 }
266
267 uint64_t
268 getCost() const
269 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700270 BOOST_ASSERT(this->hasCost());
Junxiao Shibc19b372014-03-23 16:59:25 -0700271 return m_cost;
272 }
273
274 ControlParameters&
275 setCost(uint64_t cost)
276 {
277 m_wire.reset();
278 m_cost = cost;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700279 m_hasFields[CONTROL_PARAMETER_COST] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700280 return *this;
281 }
282
283 ControlParameters&
284 unsetCost()
285 {
286 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700287 m_hasFields[CONTROL_PARAMETER_COST] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700288 return *this;
289 }
290
291 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700292 hasFlags() const
293 {
294 return m_hasFields[CONTROL_PARAMETER_FLAGS];
295 }
296
297 uint64_t
298 getFlags() const
299 {
300 BOOST_ASSERT(this->hasFlags());
301 return m_flags;
302 }
303
304 ControlParameters&
305 setFlags(uint64_t flags)
306 {
307 m_wire.reset();
308 m_flags = flags;
309 m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
310 return *this;
311 }
312
313 ControlParameters&
314 unsetFlags()
315 {
316 m_wire.reset();
317 m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
318 return *this;
319 }
320
321 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700322 hasStrategy() const
323 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700324 return m_hasFields[CONTROL_PARAMETER_STRATEGY];
Junxiao Shibc19b372014-03-23 16:59:25 -0700325 }
326
327 const Name&
328 getStrategy() const
329 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700330 BOOST_ASSERT(this->hasStrategy());
Junxiao Shibc19b372014-03-23 16:59:25 -0700331 return m_strategy;
332 }
333
334 ControlParameters&
335 setStrategy(const Name& strategy)
336 {
337 m_wire.reset();
338 m_strategy = strategy;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700339 m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700340 return *this;
341 }
342
343 ControlParameters&
344 unsetStrategy()
345 {
346 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700347 m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700348 return *this;
349 }
350
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700351 bool
352 hasExpirationPeriod() const
353 {
354 return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
355 }
356
357 const time::milliseconds&
358 getExpirationPeriod() const
359 {
360 BOOST_ASSERT(this->hasExpirationPeriod());
361 return m_expirationPeriod;
362 }
363
364 ControlParameters&
365 setExpirationPeriod(const time::milliseconds& expirationPeriod)
366 {
367 m_wire.reset();
368 m_expirationPeriod = expirationPeriod;
369 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
370 return *this;
371 }
372
373 ControlParameters&
374 unsetExpirationPeriod()
375 {
376 m_wire.reset();
377 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
378 return *this;
379 }
380
Junxiao Shi5ec80222014-03-25 20:08:05 -0700381 const std::vector<bool>&
382 getPresentFields() const
383 {
384 return m_hasFields;
385 }
386
Junxiao Shibc19b372014-03-23 16:59:25 -0700387private: // fields
Junxiao Shi5ec80222014-03-25 20:08:05 -0700388 std::vector<bool> m_hasFields;
389
Junxiao Shibc19b372014-03-23 16:59:25 -0700390 Name m_name;
391 uint64_t m_faceId;
392 std::string m_uri;
393 LocalControlFeature m_localControlFeature;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700394 uint64_t m_origin;
Junxiao Shibc19b372014-03-23 16:59:25 -0700395 uint64_t m_cost;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700396 uint64_t m_flags;
Junxiao Shibc19b372014-03-23 16:59:25 -0700397 Name m_strategy;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700398 time::milliseconds m_expirationPeriod;
Junxiao Shibc19b372014-03-23 16:59:25 -0700399
Junxiao Shibc19b372014-03-23 16:59:25 -0700400private:
401 mutable Block m_wire;
402};
403
404
Junxiao Shibc19b372014-03-23 16:59:25 -0700405template<bool T>
406inline size_t
407ControlParameters::wireEncode(EncodingImpl<T>& encoder) const
408{
409 size_t totalLength = 0;
410
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700411 if (this->hasExpirationPeriod()) {
412 totalLength += prependNonNegativeIntegerBlock(encoder,
413 tlv::nfd::ExpirationPeriod, m_expirationPeriod.count());
414 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700415 if (this->hasStrategy()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700416 totalLength += prependNestedBlock(encoder, tlv::nfd::Strategy, m_strategy);
417 }
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700418 if (this->hasFlags()) {
419 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Flags, m_flags);
420 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700421 if (this->hasCost()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700422 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Cost, m_cost);
423 }
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700424 if (this->hasOrigin()) {
425 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Origin, m_origin);
426 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700427 if (this->hasLocalControlFeature()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700428 totalLength += prependNonNegativeIntegerBlock(encoder,
429 tlv::nfd::LocalControlFeature, m_localControlFeature);
430 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700431 if (this->hasUri()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700432 size_t valLength = encoder.prependByteArray(
433 reinterpret_cast<const uint8_t*>(m_uri.c_str()), m_uri.size());
434 totalLength += valLength;
435 totalLength += encoder.prependVarNumber(valLength);
436 totalLength += encoder.prependVarNumber(tlv::nfd::Uri);
437 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700438 if (this->hasFaceId()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700439 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FaceId, m_faceId);
440 }
Junxiao Shi5ec80222014-03-25 20:08:05 -0700441 if (this->hasName()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700442 totalLength += m_name.wireEncode(encoder);
443 }
444
445 totalLength += encoder.prependVarNumber(totalLength);
446 totalLength += encoder.prependVarNumber(tlv::nfd::ControlParameters);
447 return totalLength;
448}
449
450inline const Block&
451ControlParameters::wireEncode() const
452{
453 if (m_wire.hasWire())
454 return m_wire;
455
456 EncodingEstimator estimator;
457 size_t estimatedSize = wireEncode(estimator);
458
459 EncodingBuffer buffer(estimatedSize, 0);
460 wireEncode(buffer);
461
462 m_wire = buffer.block();
463 return m_wire;
464}
465
466inline void
467ControlParameters::wireDecode(const Block& block)
468{
469 if (block.type() != tlv::nfd::ControlParameters) {
470 throw Error("expecting TLV-TYPE ControlParameters");
471 }
472 m_wire = block;
473 m_wire.parse();
474 Block::element_const_iterator val;
475
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600476 val = m_wire.find(tlv::Name);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700477 m_hasFields[CONTROL_PARAMETER_NAME] = val != m_wire.elements_end();
478 if (this->hasName()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700479 m_name.wireDecode(*val);
480 }
481
482 val = m_wire.find(tlv::nfd::FaceId);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700483 m_hasFields[CONTROL_PARAMETER_FACE_ID] = val != m_wire.elements_end();
484 if (this->hasFaceId()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700485 m_faceId = static_cast<uint64_t>(readNonNegativeInteger(*val));
486 }
487
488 val = m_wire.find(tlv::nfd::Uri);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700489 m_hasFields[CONTROL_PARAMETER_URI] = val != m_wire.elements_end();
490 if (this->hasUri()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700491 m_uri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
492 }
493
494 val = m_wire.find(tlv::nfd::LocalControlFeature);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700495 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = val != m_wire.elements_end();
496 if (this->hasLocalControlFeature()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700497 m_localControlFeature = static_cast<LocalControlFeature>(readNonNegativeInteger(*val));
498 }
499
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700500 val = m_wire.find(tlv::nfd::Origin);
501 m_hasFields[CONTROL_PARAMETER_ORIGIN] = val != m_wire.elements_end();
502 if (this->hasOrigin()) {
503 m_origin = static_cast<uint64_t>(readNonNegativeInteger(*val));
504 }
505
Junxiao Shibc19b372014-03-23 16:59:25 -0700506 val = m_wire.find(tlv::nfd::Cost);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700507 m_hasFields[CONTROL_PARAMETER_COST] = val != m_wire.elements_end();
508 if (this->hasCost()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700509 m_cost = static_cast<uint64_t>(readNonNegativeInteger(*val));
510 }
511
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700512 val = m_wire.find(tlv::nfd::Flags);
513 m_hasFields[CONTROL_PARAMETER_FLAGS] = val != m_wire.elements_end();
514 if (this->hasFlags()) {
515 m_flags = static_cast<uint64_t>(readNonNegativeInteger(*val));
516 }
517
Junxiao Shibc19b372014-03-23 16:59:25 -0700518 val = m_wire.find(tlv::nfd::Strategy);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700519 m_hasFields[CONTROL_PARAMETER_STRATEGY] = val != m_wire.elements_end();
520 if (this->hasStrategy()) {
Junxiao Shibc19b372014-03-23 16:59:25 -0700521 val->parse();
522 if (val->elements().empty()) {
523 throw Error("expecting Strategy/Name");
524 }
525 else {
526 m_strategy.wireDecode(*val->elements_begin());
527 }
528 }
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700529
530 val = m_wire.find(tlv::nfd::ExpirationPeriod);
531 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = val != m_wire.elements_end();
532 if (this->hasExpirationPeriod()) {
533 m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val));
534 }
Junxiao Shibc19b372014-03-23 16:59:25 -0700535}
536
537inline std::ostream&
538operator<<(std::ostream& os, const ControlParameters& parameters)
539{
540 os << "ControlParameters(";
541
542 if (parameters.hasName()) {
543 os << "Name: " << parameters.getName() << ", ";
544 }
545
546 if (parameters.hasFaceId()) {
547 os << "FaceId: " << parameters.getFaceId() << ", ";
548 }
549
550 if (parameters.hasUri()) {
551 os << "Uri: " << parameters.getUri() << ", ";
552 }
553
554 if (parameters.hasLocalControlFeature()) {
555 os << "LocalControlFeature: " << parameters.getLocalControlFeature() << ", ";
556 }
557
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700558 if (parameters.hasOrigin()) {
559 os << "Origin: " << parameters.getOrigin() << ", ";
560 }
561
Junxiao Shibc19b372014-03-23 16:59:25 -0700562 if (parameters.hasCost()) {
563 os << "Cost: " << parameters.getCost() << ", ";
564 }
565
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700566 if (parameters.hasFlags()) {
567 os << "Flags: " << parameters.getFlags() << ", ";
568 }
569
Junxiao Shibc19b372014-03-23 16:59:25 -0700570 if (parameters.hasStrategy()) {
571 os << "Strategy: " << parameters.getStrategy() << ", ";
572 }
573
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700574 if (parameters.hasExpirationPeriod()) {
575 os << "ExpirationPeriod: " << parameters.getExpirationPeriod() << ", ";
576 }
577
Junxiao Shibc19b372014-03-23 16:59:25 -0700578 os << ")";
579 return os;
580}
581
582
583} // namespace nfd
584} // namespace ndn
585
586#endif // NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP