ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
control-parameters.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2025 Regents of the University of California.
4 *
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_CXX_MGMT_NFD_CONTROL_PARAMETERS_HPP
23#define NDN_CXX_MGMT_NFD_CONTROL_PARAMETERS_HPP
24
25#include "ndn-cxx/name.hpp"
28#include "ndn-cxx/util/time.hpp"
29
30#include <array>
31#include <bitset>
32
33namespace ndn::nfd {
34
57
58inline constexpr std::array CONTROL_PARAMETER_FIELD = {
59 "Name"sv,
60 "FaceId"sv,
61 "Uri"sv,
62 "LocalUri"sv,
63 "Origin"sv,
64 "Cost"sv,
65 "Capacity"sv,
66 "Count"sv,
67 "Flags"sv,
68 "Mask"sv,
69 "Strategy"sv,
70 "ExpirationPeriod"sv,
71 "FacePersistency"sv,
72 "BaseCongestionMarkingInterval"sv,
73 "DefaultCongestionThreshold"sv,
74 "Mtu"sv,
75};
76
84{
85public:
86 class Error : public tlv::Error
87 {
88 public:
90 };
91
93
94 explicit
95 ControlParameters(const Block& block);
96
97 template<encoding::Tag TAG>
98 size_t
99 wireEncode(EncodingImpl<TAG>& encoder) const;
100
101 Block
102 wireEncode() const final;
103
104 void
105 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
122 setName(const Name& name)
123 {
124 m_wire.reset();
125 m_name = name;
126 m_hasFields.set(CONTROL_PARAMETER_NAME);
127 return *this;
128 }
129
132 {
133 m_wire.reset();
134 m_hasFields.reset(CONTROL_PARAMETER_NAME);
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
152 setFaceId(uint64_t faceId)
153 {
154 m_wire.reset();
155 m_faceId = faceId;
156 m_hasFields.set(CONTROL_PARAMETER_FACE_ID);
157 return *this;
158 }
159
162 {
163 m_wire.reset();
164 m_hasFields.reset(CONTROL_PARAMETER_FACE_ID);
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
182 setUri(const std::string& uri)
183 {
184 m_wire.reset();
185 m_uri = uri;
186 m_hasFields.set(CONTROL_PARAMETER_URI);
187 return *this;
188 }
189
192 {
193 m_wire.reset();
194 m_hasFields.reset(CONTROL_PARAMETER_URI);
195 return *this;
196 }
197
198 bool
200 {
201 return m_hasFields[CONTROL_PARAMETER_LOCAL_URI];
202 }
203
204 const std::string&
206 {
207 BOOST_ASSERT(this->hasLocalUri());
208 return m_localUri;
209 }
210
212 setLocalUri(const std::string& localUri)
213 {
214 m_wire.reset();
215 m_localUri = localUri;
216 m_hasFields.set(CONTROL_PARAMETER_LOCAL_URI);
217 return *this;
218 }
219
222 {
223 m_wire.reset();
224 m_hasFields.reset(CONTROL_PARAMETER_LOCAL_URI);
225 return *this;
226 }
227
228 bool
229 hasOrigin() const
230 {
231 return m_hasFields[CONTROL_PARAMETER_ORIGIN];
232 }
233
235 getOrigin() const
236 {
237 BOOST_ASSERT(this->hasOrigin());
238 return m_origin;
239 }
240
243 {
244 m_wire.reset();
245 m_origin = origin;
246 m_hasFields.set(CONTROL_PARAMETER_ORIGIN);
247 return *this;
248 }
249
252 {
253 m_wire.reset();
254 m_hasFields.reset(CONTROL_PARAMETER_ORIGIN);
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
272 setCost(uint64_t cost)
273 {
274 m_wire.reset();
275 m_cost = cost;
276 m_hasFields.set(CONTROL_PARAMETER_COST);
277 return *this;
278 }
279
282 {
283 m_wire.reset();
284 m_hasFields.reset(CONTROL_PARAMETER_COST);
285 return *this;
286 }
287
288 bool
290 {
291 return m_hasFields[CONTROL_PARAMETER_CAPACITY];
292 }
293
294 uint64_t
296 {
297 BOOST_ASSERT(this->hasCapacity());
298 return m_capacity;
299 }
300
302 setCapacity(uint64_t capacity)
303 {
304 m_wire.reset();
305 m_capacity = capacity;
306 m_hasFields.set(CONTROL_PARAMETER_CAPACITY);
307 return *this;
308 }
309
312 {
313 m_wire.reset();
314 m_hasFields.reset(CONTROL_PARAMETER_CAPACITY);
315 return *this;
316 }
317
318 bool
319 hasCount() const
320 {
321 return m_hasFields[CONTROL_PARAMETER_COUNT];
322 }
323
324 uint64_t
325 getCount() const
326 {
327 BOOST_ASSERT(this->hasCount());
328 return m_count;
329 }
330
332 setCount(uint64_t count)
333 {
334 m_wire.reset();
335 m_count = count;
336 m_hasFields.set(CONTROL_PARAMETER_COUNT);
337 return *this;
338 }
339
342 {
343 m_wire.reset();
344 m_hasFields.reset(CONTROL_PARAMETER_COUNT);
345 return *this;
346 }
347
348 bool
349 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
362 setFlags(uint64_t flags)
363 {
364 m_wire.reset();
365 m_flags = flags;
366 m_hasFields.set(CONTROL_PARAMETER_FLAGS);
367 return *this;
368 }
369
372 {
373 m_wire.reset();
374 m_hasFields.reset(CONTROL_PARAMETER_FLAGS);
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
392 setMask(uint64_t mask)
393 {
394 m_wire.reset();
395 m_mask = mask;
396 m_hasFields.set(CONTROL_PARAMETER_MASK);
397 return *this;
398 }
399
402 {
403 m_wire.reset();
404 m_hasFields.reset(CONTROL_PARAMETER_MASK);
405 return *this;
406 }
407
408 bool
410 {
411 return m_hasFields[CONTROL_PARAMETER_STRATEGY];
412 }
413
414 const Name&
416 {
417 BOOST_ASSERT(this->hasStrategy());
418 return m_strategy;
419 }
420
422 setStrategy(const Name& strategy)
423 {
424 m_wire.reset();
425 m_strategy = strategy;
426 m_hasFields.set(CONTROL_PARAMETER_STRATEGY);
427 return *this;
428 }
429
432 {
433 m_wire.reset();
434 m_hasFields.reset(CONTROL_PARAMETER_STRATEGY);
435 return *this;
436 }
437
438 bool
440 {
441 return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
442 }
443
444 const time::milliseconds&
446 {
447 BOOST_ASSERT(this->hasExpirationPeriod());
448 return m_expirationPeriod;
449 }
450
453 {
454 m_wire.reset();
455 m_expirationPeriod = expirationPeriod;
457 return *this;
458 }
459
462 {
463 m_wire.reset();
464 m_hasFields.reset(CONTROL_PARAMETER_EXPIRATION_PERIOD);
465 return *this;
466 }
467
468 bool
470 {
471 return m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY];
472 }
473
476 {
477 BOOST_ASSERT(this->hasFacePersistency());
478 return m_facePersistency;
479 }
480
483 {
484 m_wire.reset();
485 m_facePersistency = persistency;
486 m_hasFields.set(CONTROL_PARAMETER_FACE_PERSISTENCY);
487 return *this;
488 }
489
492 {
493 m_wire.reset();
494 m_hasFields.reset(CONTROL_PARAMETER_FACE_PERSISTENCY);
495 return *this;
496 }
497
498 bool
503
506 {
507 BOOST_ASSERT(this->hasBaseCongestionMarkingInterval());
508 return m_baseCongestionMarkingInterval;
509 }
510
513 {
514 m_wire.reset();
515 m_baseCongestionMarkingInterval = interval;
517 return *this;
518 }
519
522 {
523 m_wire.reset();
525 return *this;
526 }
527
528 bool
533
536 uint64_t
538 {
539 BOOST_ASSERT(this->hasDefaultCongestionThreshold());
540 return m_defaultCongestionThreshold;
541 }
542
547 {
548 m_wire.reset();
549 m_defaultCongestionThreshold = threshold;
551 return *this;
552 }
553
556 {
557 m_wire.reset();
559 return *this;
560 }
561
562 bool
563 hasMtu() const
564 {
565 return m_hasFields[CONTROL_PARAMETER_MTU];
566 }
567
572 uint64_t
573 getMtu() const
574 {
575 BOOST_ASSERT(this->hasMtu());
576 return m_mtu;
577 }
578
584 setMtu(uint64_t mtu)
585 {
586 m_wire.reset();
587 m_mtu = mtu;
588 m_hasFields.set(CONTROL_PARAMETER_MTU);
589 return *this;
590 }
591
594 {
595 m_wire.reset();
596 m_hasFields.reset(CONTROL_PARAMETER_MTU);
597 return *this;
598 }
599
600 auto
601 getPresentFields() const noexcept
602 {
603 return m_hasFields;
604 }
605
606public: // Flags and Mask helpers
611 bool
612 hasFlagBit(size_t bit) const;
613
618 bool
619 getFlagBit(size_t bit) const;
620
628 setFlagBit(size_t bit, bool value, bool wantMask = true);
629
636 unsetFlagBit(size_t bit);
637
638private:
639 std::bitset<CONTROL_PARAMETER_UBOUND> m_hasFields;
640
641 Name m_name;
642 uint64_t m_faceId;
643 std::string m_uri;
644 std::string m_localUri;
645 RouteOrigin m_origin;
646 uint64_t m_cost;
647 uint64_t m_capacity;
648 uint64_t m_count;
649 uint64_t m_flags;
650 uint64_t m_mask;
651 Name m_strategy;
652 time::milliseconds m_expirationPeriod;
653 FacePersistency m_facePersistency;
654 time::nanoseconds m_baseCongestionMarkingInterval;
655 uint64_t m_defaultCongestionThreshold;
656 uint64_t m_mtu;
657
658 mutable Block m_wire;
659};
660
662
663std::ostream&
664operator<<(std::ostream& os, const ControlParameters& parameters);
665
666} // namespace ndn::nfd
667
668#endif // NDN_CXX_MGMT_NFD_CONTROL_PARAMETERS_HPP
Represents a TLV element of the NDN packet format.
Definition block.hpp:45
void reset() noexcept
Reset the Block to a default-constructed state.
Definition block.cpp:293
Represents an absolute name.
Definition name.hpp:45
Base class for a struct that contains the parameters for a ControlCommand.
Represents parameters in a ControlCommand request or response.
ControlParameters & setUri(const std::string &uri)
ControlParameters & setCount(uint64_t count)
ControlParameters & setExpirationPeriod(const time::milliseconds &expirationPeriod)
ControlParameters & unsetOrigin()
void wireDecode(const Block &wire) final
ControlParameters & unsetStrategy()
const std::string & getUri() const
ControlParameters & setFacePersistency(FacePersistency persistency)
ControlParameters & setMask(uint64_t mask)
ControlParameters & unsetBaseCongestionMarkingInterval()
ControlParameters & unsetCapacity()
ControlParameters & unsetDefaultCongestionThreshold()
ControlParameters & unsetLocalUri()
ControlParameters & unsetFlagBit(size_t bit)
Disable a bit in Mask.
uint64_t getDefaultCongestionThreshold() const
Get default congestion threshold (measured in bytes).
auto getPresentFields() const noexcept
ControlParameters & unsetFaceId()
const time::milliseconds & getExpirationPeriod() const
ControlParameters & setOrigin(RouteOrigin origin)
ControlParameters & setMtu(uint64_t mtu)
Set MTU (measured in bytes).
ControlParameters & setName(const Name &name)
ControlParameters & unsetFacePersistency()
FacePersistency getFacePersistency() const
ControlParameters & setFaceId(uint64_t faceId)
ControlParameters & setFlagBit(size_t bit, bool value, bool wantMask=true)
Set a bit in Flags.
ControlParameters & setCost(uint64_t cost)
ControlParameters & setCapacity(uint64_t capacity)
bool hasFlagBit(size_t bit) const
ControlParameters & setFlags(uint64_t flags)
ControlParameters & setBaseCongestionMarkingInterval(time::nanoseconds interval)
ControlParameters & setDefaultCongestionThreshold(uint64_t threshold)
Set default congestion threshold (measured in bytes).
ControlParameters & setLocalUri(const std::string &localUri)
const std::string & getLocalUri() const
ControlParameters & setStrategy(const Name &strategy)
bool getFlagBit(size_t bit) const
time::nanoseconds getBaseCongestionMarkingInterval() const
ControlParameters & unsetExpirationPeriod()
uint64_t getMtu() const
Get MTU (measured in bytes).
Represents an error in TLV encoding or decoding.
Definition tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition tlv.cpp:28
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
@ CONTROL_PARAMETER_FACE_PERSISTENCY
@ CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD
@ CONTROL_PARAMETER_EXPIRATION_PERIOD
@ CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL
Contains classes and functions related to the NFD Management protocol.
constexpr std::array CONTROL_PARAMETER_FIELD
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
::boost::chrono::milliseconds milliseconds
Definition time.hpp:52
::boost::chrono::nanoseconds nanoseconds
Definition time.hpp:54