blob: 7005e9d26d22a3e85a3ee6bd929a64c28664fc28 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento88a0d812017-08-19 21:31:42 -04002/*
Junxiao Shi22f85682018-01-22 19:23:22 +00003 * Copyright (c) 2013-2018 Regents of the University of California.
Junxiao Shi7357ef22016-09-07 02:39:37 +00004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * 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.
20 */
21
22#ifndef NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP
23#define NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP
24
25#include "../../encoding/nfd-constants.hpp"
26#include "../../name.hpp"
27#include "../../util/time.hpp"
28#include "../control-parameters.hpp"
29
30namespace ndn {
31namespace nfd {
32
33/**
34 * \ingroup management
35 */
36enum ControlParameterField {
37 CONTROL_PARAMETER_NAME,
38 CONTROL_PARAMETER_FACE_ID,
39 CONTROL_PARAMETER_URI,
Eric Newberryd7f5b282017-03-28 19:55:20 -070040 CONTROL_PARAMETER_LOCAL_URI,
Junxiao Shi7357ef22016-09-07 02:39:37 +000041 CONTROL_PARAMETER_ORIGIN,
42 CONTROL_PARAMETER_COST,
Junxiao Shi22f85682018-01-22 19:23:22 +000043 CONTROL_PARAMETER_CAPACITY,
Junxiao Shidf505382018-03-04 13:40:44 +000044 CONTROL_PARAMETER_N_CS_ENTRIES,
Junxiao Shi7357ef22016-09-07 02:39:37 +000045 CONTROL_PARAMETER_FLAGS,
46 CONTROL_PARAMETER_MASK,
47 CONTROL_PARAMETER_STRATEGY,
48 CONTROL_PARAMETER_EXPIRATION_PERIOD,
49 CONTROL_PARAMETER_FACE_PERSISTENCY,
Eric Newberry07d05c92018-01-22 16:08:01 -070050 CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL,
51 CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD,
Junxiao Shi7357ef22016-09-07 02:39:37 +000052 CONTROL_PARAMETER_UBOUND
53};
54
55const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
56 "Name",
57 "FaceId",
58 "Uri",
Eric Newberryd7f5b282017-03-28 19:55:20 -070059 "LocalUri",
Junxiao Shi7357ef22016-09-07 02:39:37 +000060 "Origin",
61 "Cost",
Junxiao Shi22f85682018-01-22 19:23:22 +000062 "Capacity",
Junxiao Shidf505382018-03-04 13:40:44 +000063 "NCsEntries",
Junxiao Shi7357ef22016-09-07 02:39:37 +000064 "Flags",
65 "Mask",
66 "Strategy",
67 "ExpirationPeriod",
Eric Newberry07d05c92018-01-22 16:08:01 -070068 "FacePersistency",
69 "BaseCongestionMarkingInterval",
70 "DefaultCongestionThreshold"
Junxiao Shi7357ef22016-09-07 02:39:37 +000071};
72
73/**
74 * \ingroup management
Junxiao Shi7357ef22016-09-07 02:39:37 +000075 * \brief represents parameters in a ControlCommand request or response
Eric Newberryd7f5b282017-03-28 19:55:20 -070076 * \sa https://redmine.named-data.net/projects/nfd/wiki/ControlCommand#ControlParameters
Junxiao Shi7357ef22016-09-07 02:39:37 +000077 * \details This type is copyable because it's an abstraction of a TLV type.
78 */
Davide Pesavento7f20d6e2017-01-16 14:43:58 -050079class ControlParameters : public mgmt::ControlParameters
Junxiao Shi7357ef22016-09-07 02:39:37 +000080{
81public:
82 class Error : public tlv::Error
83 {
84 public:
85 explicit
86 Error(const std::string& what)
87 : tlv::Error(what)
88 {
89 }
90 };
91
92 ControlParameters();
93
94 explicit
95 ControlParameters(const Block& block);
96
97 template<encoding::Tag TAG>
98 size_t
99 wireEncode(EncodingImpl<TAG>& encoder) const;
100
Davide Pesavento57c07df2016-12-11 18:41:45 -0500101 Block
Junxiao Shi7357ef22016-09-07 02:39:37 +0000102 wireEncode() const final;
103
Davide Pesavento57c07df2016-12-11 18:41:45 -0500104 void
Junxiao Shi7357ef22016-09-07 02:39:37 +0000105 wireDecode(const Block& wire) final;
106
107public: // getters & setters
108 bool
109 hasName() const
110 {
111 return m_hasFields[CONTROL_PARAMETER_NAME];
112 }
113
114 const Name&
115 getName() const
116 {
117 BOOST_ASSERT(this->hasName());
118 return m_name;
119 }
120
121 ControlParameters&
122 setName(const Name& name)
123 {
124 m_wire.reset();
125 m_name = name;
126 m_hasFields[CONTROL_PARAMETER_NAME] = true;
127 return *this;
128 }
129
130 ControlParameters&
131 unsetName()
132 {
133 m_wire.reset();
134 m_hasFields[CONTROL_PARAMETER_NAME] = false;
135 return *this;
136 }
137
138 bool
139 hasFaceId() const
140 {
141 return m_hasFields[CONTROL_PARAMETER_FACE_ID];
142 }
143
144 uint64_t
145 getFaceId() const
146 {
147 BOOST_ASSERT(this->hasFaceId());
148 return m_faceId;
149 }
150
151 ControlParameters&
152 setFaceId(uint64_t faceId)
153 {
154 m_wire.reset();
155 m_faceId = faceId;
156 m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
157 return *this;
158 }
159
160 ControlParameters&
161 unsetFaceId()
162 {
163 m_wire.reset();
164 m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
165 return *this;
166 }
167
168 bool
169 hasUri() const
170 {
171 return m_hasFields[CONTROL_PARAMETER_URI];
172 }
173
174 const std::string&
175 getUri() const
176 {
177 BOOST_ASSERT(this->hasUri());
178 return m_uri;
179 }
180
181 ControlParameters&
182 setUri(const std::string& uri)
183 {
184 m_wire.reset();
185 m_uri = uri;
186 m_hasFields[CONTROL_PARAMETER_URI] = true;
187 return *this;
188 }
189
190 ControlParameters&
191 unsetUri()
192 {
193 m_wire.reset();
194 m_hasFields[CONTROL_PARAMETER_URI] = false;
195 return *this;
196 }
197
Eric Newberryd7f5b282017-03-28 19:55:20 -0700198 bool
199 hasLocalUri() const
200 {
201 return m_hasFields[CONTROL_PARAMETER_LOCAL_URI];
202 }
203
204 const std::string&
205 getLocalUri() const
206 {
207 BOOST_ASSERT(this->hasLocalUri());
208 return m_localUri;
209 }
210
211 ControlParameters&
212 setLocalUri(const std::string& localUri)
213 {
214 m_wire.reset();
215 m_localUri = localUri;
216 m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = true;
217 return *this;
218 }
219
220 ControlParameters&
221 unsetLocalUri()
222 {
223 m_wire.reset();
224 m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = false;
225 return *this;
226 }
227
Junxiao Shi7357ef22016-09-07 02:39:37 +0000228 bool
229 hasOrigin() const
230 {
231 return m_hasFields[CONTROL_PARAMETER_ORIGIN];
232 }
233
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400234 RouteOrigin
Junxiao Shi7357ef22016-09-07 02:39:37 +0000235 getOrigin() const
236 {
237 BOOST_ASSERT(this->hasOrigin());
238 return m_origin;
239 }
240
241 ControlParameters&
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400242 setOrigin(RouteOrigin origin)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000243 {
244 m_wire.reset();
245 m_origin = origin;
246 m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
247 return *this;
248 }
249
250 ControlParameters&
251 unsetOrigin()
252 {
253 m_wire.reset();
254 m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
255 return *this;
256 }
257
258 bool
259 hasCost() const
260 {
261 return m_hasFields[CONTROL_PARAMETER_COST];
262 }
263
264 uint64_t
265 getCost() const
266 {
267 BOOST_ASSERT(this->hasCost());
268 return m_cost;
269 }
270
271 ControlParameters&
272 setCost(uint64_t cost)
273 {
274 m_wire.reset();
275 m_cost = cost;
276 m_hasFields[CONTROL_PARAMETER_COST] = true;
277 return *this;
278 }
279
280 ControlParameters&
281 unsetCost()
282 {
283 m_wire.reset();
284 m_hasFields[CONTROL_PARAMETER_COST] = false;
285 return *this;
286 }
287
288 bool
Junxiao Shi22f85682018-01-22 19:23:22 +0000289 hasCapacity() const
290 {
291 return m_hasFields[CONTROL_PARAMETER_CAPACITY];
292 }
293
294 uint64_t
295 getCapacity() const
296 {
297 BOOST_ASSERT(this->hasCapacity());
298 return m_capacity;
299 }
300
301 ControlParameters&
302 setCapacity(uint64_t capacity)
303 {
304 m_wire.reset();
305 m_capacity = capacity;
306 m_hasFields[CONTROL_PARAMETER_CAPACITY] = true;
307 return *this;
308 }
309
310 ControlParameters&
311 unsetCapacity()
312 {
313 m_wire.reset();
314 m_hasFields[CONTROL_PARAMETER_CAPACITY] = false;
315 return *this;
316 }
317
318 bool
Junxiao Shidf505382018-03-04 13:40:44 +0000319 hasNCsEntries() const
320 {
321 return m_hasFields[CONTROL_PARAMETER_N_CS_ENTRIES];
322 }
323
324 uint64_t
325 getNCsEntries() const
326 {
327 BOOST_ASSERT(this->hasNCsEntries());
328 return m_nCsEntries;
329 }
330
331 ControlParameters&
332 setNCsEntries(uint64_t nCsEntries)
333 {
334 m_wire.reset();
335 m_nCsEntries = nCsEntries;
336 m_hasFields[CONTROL_PARAMETER_N_CS_ENTRIES] = true;
337 return *this;
338 }
339
340 ControlParameters&
341 unsetNCsEntries()
342 {
343 m_wire.reset();
344 m_hasFields[CONTROL_PARAMETER_N_CS_ENTRIES] = false;
345 return *this;
346 }
347
348 bool
Junxiao Shi7357ef22016-09-07 02:39:37 +0000349 hasFlags() const
350 {
351 return m_hasFields[CONTROL_PARAMETER_FLAGS];
352 }
353
354 uint64_t
355 getFlags() const
356 {
357 BOOST_ASSERT(this->hasFlags());
358 return m_flags;
359 }
360
361 ControlParameters&
362 setFlags(uint64_t flags)
363 {
364 m_wire.reset();
365 m_flags = flags;
366 m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
367 return *this;
368 }
369
370 ControlParameters&
371 unsetFlags()
372 {
373 m_wire.reset();
374 m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
375 return *this;
376 }
377
378 bool
379 hasMask() const
380 {
381 return m_hasFields[CONTROL_PARAMETER_MASK];
382 }
383
384 uint64_t
385 getMask() const
386 {
387 BOOST_ASSERT(this->hasMask());
388 return m_mask;
389 }
390
391 ControlParameters&
392 setMask(uint64_t mask)
393 {
394 m_wire.reset();
395 m_mask = mask;
396 m_hasFields[CONTROL_PARAMETER_MASK] = true;
397 return *this;
398 }
399
400 ControlParameters&
401 unsetMask()
402 {
403 m_wire.reset();
404 m_hasFields[CONTROL_PARAMETER_MASK] = false;
405 return *this;
406 }
407
408 bool
409 hasStrategy() const
410 {
411 return m_hasFields[CONTROL_PARAMETER_STRATEGY];
412 }
413
414 const Name&
415 getStrategy() const
416 {
417 BOOST_ASSERT(this->hasStrategy());
418 return m_strategy;
419 }
420
421 ControlParameters&
422 setStrategy(const Name& strategy)
423 {
424 m_wire.reset();
425 m_strategy = strategy;
426 m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
427 return *this;
428 }
429
430 ControlParameters&
431 unsetStrategy()
432 {
433 m_wire.reset();
434 m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
435 return *this;
436 }
437
438 bool
439 hasExpirationPeriod() const
440 {
441 return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
442 }
443
444 const time::milliseconds&
445 getExpirationPeriod() const
446 {
447 BOOST_ASSERT(this->hasExpirationPeriod());
448 return m_expirationPeriod;
449 }
450
451 ControlParameters&
452 setExpirationPeriod(const time::milliseconds& expirationPeriod)
453 {
454 m_wire.reset();
455 m_expirationPeriod = expirationPeriod;
456 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
457 return *this;
458 }
459
460 ControlParameters&
461 unsetExpirationPeriod()
462 {
463 m_wire.reset();
464 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
465 return *this;
466 }
467
468 bool
469 hasFacePersistency() const
470 {
471 return m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY];
472 }
473
474 FacePersistency
475 getFacePersistency() const
476 {
477 BOOST_ASSERT(this->hasFacePersistency());
478 return m_facePersistency;
479 }
480
481 ControlParameters&
482 setFacePersistency(FacePersistency persistency)
483 {
484 m_wire.reset();
485 m_facePersistency = persistency;
486 m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = true;
487 return *this;
488 }
489
490 ControlParameters&
491 unsetFacePersistency()
492 {
493 m_wire.reset();
494 m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = false;
495 return *this;
496 }
497
Eric Newberry07d05c92018-01-22 16:08:01 -0700498 bool
499 hasBaseCongestionMarkingInterval() const
500 {
501 return m_hasFields[CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL];
502 }
503
504 time::nanoseconds
505 getBaseCongestionMarkingInterval() const
506 {
507 BOOST_ASSERT(this->hasBaseCongestionMarkingInterval());
508 return m_baseCongestionMarkingInterval;
509 }
510
511 ControlParameters&
512 setBaseCongestionMarkingInterval(time::nanoseconds interval)
513 {
514 m_wire.reset();
515 m_baseCongestionMarkingInterval = interval;
516 m_hasFields[CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL] = true;
517 return *this;
518 }
519
520 ControlParameters&
521 unsetBaseCongestionMarkingInterval()
522 {
523 m_wire.reset();
524 m_hasFields[CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL] = false;
525 return *this;
526 }
527
528 bool
529 hasDefaultCongestionThreshold() const
530 {
531 return m_hasFields[CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD];
532 }
533
534 /** \brief get default congestion threshold (measured in bytes)
535 */
536 uint64_t
537 getDefaultCongestionThreshold() const
538 {
539 BOOST_ASSERT(this->hasDefaultCongestionThreshold());
540 return m_defaultCongestionThreshold;
541 }
542
543 /** \brief set default congestion threshold (measured in bytes)
544 */
545 ControlParameters&
546 setDefaultCongestionThreshold(uint64_t threshold)
547 {
548 m_wire.reset();
549 m_defaultCongestionThreshold = threshold;
550 m_hasFields[CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD] = true;
551 return *this;
552 }
553
554 ControlParameters&
555 unsetDefaultCongestionThreshold()
556 {
557 m_wire.reset();
558 m_hasFields[CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD] = false;
559 return *this;
560 }
561
Junxiao Shi7357ef22016-09-07 02:39:37 +0000562 const std::vector<bool>&
563 getPresentFields() const
564 {
565 return m_hasFields;
566 }
567
568public: // Flags and Mask helpers
569 /**
570 * \return whether bit is enabled in Mask
571 * \param bit bit position within range [0, 64) (least significant bit is 0)
572 */
573 bool
574 hasFlagBit(size_t bit) const;
575
576 /**
577 * \return bit at a position in Flags
578 * \param bit bit position within range [0, 64) (least significant bit is 0)
579 */
580 bool
581 getFlagBit(size_t bit) const;
582
583 /**
584 * \brief set a bit in Flags
585 * \param bit bit position within range [0, 64) (least significant bit is 0)
586 * \param value new value in Flags
587 * \param wantMask if true, enable the bit in Mask
588 */
589 ControlParameters&
590 setFlagBit(size_t bit, bool value, bool wantMask = true);
591
592 /**
593 * \brief disable a bit in Mask
594 * \param bit bit position within range [0, 64) (least significant bit is 0)
595 * \post If all bits are disabled, Flags and Mask fields are deleted.
596 */
597 ControlParameters&
598 unsetFlagBit(size_t bit);
599
600private: // fields
601 std::vector<bool> m_hasFields;
602
603 Name m_name;
604 uint64_t m_faceId;
605 std::string m_uri;
Eric Newberryd7f5b282017-03-28 19:55:20 -0700606 std::string m_localUri;
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400607 RouteOrigin m_origin;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000608 uint64_t m_cost;
Junxiao Shi22f85682018-01-22 19:23:22 +0000609 uint64_t m_capacity;
Junxiao Shidf505382018-03-04 13:40:44 +0000610 uint64_t m_nCsEntries;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000611 uint64_t m_flags;
612 uint64_t m_mask;
613 Name m_strategy;
614 time::milliseconds m_expirationPeriod;
615 FacePersistency m_facePersistency;
Eric Newberry07d05c92018-01-22 16:08:01 -0700616 time::nanoseconds m_baseCongestionMarkingInterval;
617 uint64_t m_defaultCongestionThreshold;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000618
619private:
620 mutable Block m_wire;
621};
622
Davide Pesavento88a0d812017-08-19 21:31:42 -0400623NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ControlParameters);
624
Junxiao Shi7357ef22016-09-07 02:39:37 +0000625std::ostream&
626operator<<(std::ostream& os, const ControlParameters& parameters);
627
628} // namespace nfd
629} // namespace ndn
630
631#endif // NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP