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-2023 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 namespace ndn::nfd {
31 
53 };
54 
55 inline constexpr std::string_view CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
56  "Name"sv,
57  "FaceId"sv,
58  "Uri"sv,
59  "LocalUri"sv,
60  "Origin"sv,
61  "Cost"sv,
62  "Capacity"sv,
63  "Count"sv,
64  "Flags"sv,
65  "Mask"sv,
66  "Strategy"sv,
67  "ExpirationPeriod"sv,
68  "FacePersistency"sv,
69  "BaseCongestionMarkingInterval"sv,
70  "DefaultCongestionThreshold"sv,
71  "Mtu"sv,
72 };
73 
81 {
82 public:
83  class Error : public tlv::Error
84  {
85  public:
86  using tlv::Error::Error;
87  };
88 
90 
91  explicit
92  ControlParameters(const Block& block);
93 
94  template<encoding::Tag TAG>
95  size_t
96  wireEncode(EncodingImpl<TAG>& encoder) const;
97 
98  Block
99  wireEncode() const final;
100 
101  void
102  wireDecode(const Block& wire) final;
103 
104 public: // getters & setters
105  bool
106  hasName() const
107  {
108  return m_hasFields[CONTROL_PARAMETER_NAME];
109  }
110 
111  const Name&
112  getName() const
113  {
114  BOOST_ASSERT(this->hasName());
115  return m_name;
116  }
117 
119  setName(const Name& name)
120  {
121  m_wire.reset();
122  m_name = name;
123  m_hasFields[CONTROL_PARAMETER_NAME] = true;
124  return *this;
125  }
126 
129  {
130  m_wire.reset();
131  m_hasFields[CONTROL_PARAMETER_NAME] = false;
132  return *this;
133  }
134 
135  bool
136  hasFaceId() const
137  {
138  return m_hasFields[CONTROL_PARAMETER_FACE_ID];
139  }
140 
141  uint64_t
142  getFaceId() const
143  {
144  BOOST_ASSERT(this->hasFaceId());
145  return m_faceId;
146  }
147 
149  setFaceId(uint64_t faceId)
150  {
151  m_wire.reset();
152  m_faceId = faceId;
153  m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
154  return *this;
155  }
156 
159  {
160  m_wire.reset();
161  m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
162  return *this;
163  }
164 
165  bool
166  hasUri() const
167  {
168  return m_hasFields[CONTROL_PARAMETER_URI];
169  }
170 
171  const std::string&
172  getUri() const
173  {
174  BOOST_ASSERT(this->hasUri());
175  return m_uri;
176  }
177 
179  setUri(const std::string& uri)
180  {
181  m_wire.reset();
182  m_uri = uri;
183  m_hasFields[CONTROL_PARAMETER_URI] = true;
184  return *this;
185  }
186 
189  {
190  m_wire.reset();
191  m_hasFields[CONTROL_PARAMETER_URI] = false;
192  return *this;
193  }
194 
195  bool
196  hasLocalUri() const
197  {
198  return m_hasFields[CONTROL_PARAMETER_LOCAL_URI];
199  }
200 
201  const std::string&
202  getLocalUri() const
203  {
204  BOOST_ASSERT(this->hasLocalUri());
205  return m_localUri;
206  }
207 
209  setLocalUri(const std::string& localUri)
210  {
211  m_wire.reset();
212  m_localUri = localUri;
213  m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = true;
214  return *this;
215  }
216 
219  {
220  m_wire.reset();
221  m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = false;
222  return *this;
223  }
224 
225  bool
226  hasOrigin() const
227  {
228  return m_hasFields[CONTROL_PARAMETER_ORIGIN];
229  }
230 
232  getOrigin() const
233  {
234  BOOST_ASSERT(this->hasOrigin());
235  return m_origin;
236  }
237 
240  {
241  m_wire.reset();
242  m_origin = origin;
243  m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
244  return *this;
245  }
246 
249  {
250  m_wire.reset();
251  m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
252  return *this;
253  }
254 
255  bool
256  hasCost() const
257  {
258  return m_hasFields[CONTROL_PARAMETER_COST];
259  }
260 
261  uint64_t
262  getCost() const
263  {
264  BOOST_ASSERT(this->hasCost());
265  return m_cost;
266  }
267 
269  setCost(uint64_t cost)
270  {
271  m_wire.reset();
272  m_cost = cost;
273  m_hasFields[CONTROL_PARAMETER_COST] = true;
274  return *this;
275  }
276 
279  {
280  m_wire.reset();
281  m_hasFields[CONTROL_PARAMETER_COST] = false;
282  return *this;
283  }
284 
285  bool
286  hasCapacity() const
287  {
288  return m_hasFields[CONTROL_PARAMETER_CAPACITY];
289  }
290 
291  uint64_t
292  getCapacity() const
293  {
294  BOOST_ASSERT(this->hasCapacity());
295  return m_capacity;
296  }
297 
299  setCapacity(uint64_t capacity)
300  {
301  m_wire.reset();
302  m_capacity = capacity;
303  m_hasFields[CONTROL_PARAMETER_CAPACITY] = true;
304  return *this;
305  }
306 
309  {
310  m_wire.reset();
311  m_hasFields[CONTROL_PARAMETER_CAPACITY] = false;
312  return *this;
313  }
314 
315  bool
316  hasCount() const
317  {
318  return m_hasFields[CONTROL_PARAMETER_COUNT];
319  }
320 
321  uint64_t
322  getCount() const
323  {
324  BOOST_ASSERT(this->hasCount());
325  return m_count;
326  }
327 
329  setCount(uint64_t count)
330  {
331  m_wire.reset();
332  m_count = count;
333  m_hasFields[CONTROL_PARAMETER_COUNT] = true;
334  return *this;
335  }
336 
339  {
340  m_wire.reset();
341  m_hasFields[CONTROL_PARAMETER_COUNT] = false;
342  return *this;
343  }
344 
345  bool
346  hasFlags() const
347  {
348  return m_hasFields[CONTROL_PARAMETER_FLAGS];
349  }
350 
351  uint64_t
352  getFlags() const
353  {
354  BOOST_ASSERT(this->hasFlags());
355  return m_flags;
356  }
357 
359  setFlags(uint64_t flags)
360  {
361  m_wire.reset();
362  m_flags = flags;
363  m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
364  return *this;
365  }
366 
369  {
370  m_wire.reset();
371  m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
372  return *this;
373  }
374 
375  bool
376  hasMask() const
377  {
378  return m_hasFields[CONTROL_PARAMETER_MASK];
379  }
380 
381  uint64_t
382  getMask() const
383  {
384  BOOST_ASSERT(this->hasMask());
385  return m_mask;
386  }
387 
389  setMask(uint64_t mask)
390  {
391  m_wire.reset();
392  m_mask = mask;
393  m_hasFields[CONTROL_PARAMETER_MASK] = true;
394  return *this;
395  }
396 
399  {
400  m_wire.reset();
401  m_hasFields[CONTROL_PARAMETER_MASK] = false;
402  return *this;
403  }
404 
405  bool
406  hasStrategy() const
407  {
408  return m_hasFields[CONTROL_PARAMETER_STRATEGY];
409  }
410 
411  const Name&
412  getStrategy() const
413  {
414  BOOST_ASSERT(this->hasStrategy());
415  return m_strategy;
416  }
417 
419  setStrategy(const Name& strategy)
420  {
421  m_wire.reset();
422  m_strategy = strategy;
423  m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
424  return *this;
425  }
426 
429  {
430  m_wire.reset();
431  m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
432  return *this;
433  }
434 
435  bool
437  {
438  return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
439  }
440 
441  const time::milliseconds&
443  {
444  BOOST_ASSERT(this->hasExpirationPeriod());
445  return m_expirationPeriod;
446  }
447 
449  setExpirationPeriod(const time::milliseconds& expirationPeriod)
450  {
451  m_wire.reset();
452  m_expirationPeriod = expirationPeriod;
453  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
454  return *this;
455  }
456 
459  {
460  m_wire.reset();
461  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
462  return *this;
463  }
464 
465  bool
467  {
468  return m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY];
469  }
470 
473  {
474  BOOST_ASSERT(this->hasFacePersistency());
475  return m_facePersistency;
476  }
477 
480  {
481  m_wire.reset();
482  m_facePersistency = persistency;
483  m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = true;
484  return *this;
485  }
486 
489  {
490  m_wire.reset();
491  m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = false;
492  return *this;
493  }
494 
495  bool
497  {
499  }
500 
503  {
504  BOOST_ASSERT(this->hasBaseCongestionMarkingInterval());
505  return m_baseCongestionMarkingInterval;
506  }
507 
510  {
511  m_wire.reset();
512  m_baseCongestionMarkingInterval = interval;
514  return *this;
515  }
516 
519  {
520  m_wire.reset();
522  return *this;
523  }
524 
525  bool
527  {
529  }
530 
533  uint64_t
535  {
536  BOOST_ASSERT(this->hasDefaultCongestionThreshold());
537  return m_defaultCongestionThreshold;
538  }
539 
543  setDefaultCongestionThreshold(uint64_t threshold)
544  {
545  m_wire.reset();
546  m_defaultCongestionThreshold = threshold;
548  return *this;
549  }
550 
553  {
554  m_wire.reset();
556  return *this;
557  }
558 
559  bool
560  hasMtu() const
561  {
562  return m_hasFields[CONTROL_PARAMETER_MTU];
563  }
564 
569  uint64_t
570  getMtu() const
571  {
572  BOOST_ASSERT(this->hasMtu());
573  return m_mtu;
574  }
575 
581  setMtu(uint64_t mtu)
582  {
583  m_wire.reset();
584  m_mtu = mtu;
585  m_hasFields[CONTROL_PARAMETER_MTU] = true;
586  return *this;
587  }
588 
591  {
592  m_wire.reset();
593  m_hasFields[CONTROL_PARAMETER_MTU] = false;
594  return *this;
595  }
596 
597  const std::vector<bool>&
599  {
600  return m_hasFields;
601  }
602 
603 public: // Flags and Mask helpers
608  bool
609  hasFlagBit(size_t bit) const;
610 
615  bool
616  getFlagBit(size_t bit) const;
617 
625  setFlagBit(size_t bit, bool value, bool wantMask = true);
626 
633  unsetFlagBit(size_t bit);
634 
635 private: // fields
636  std::vector<bool> m_hasFields;
637 
638  Name m_name;
639  uint64_t m_faceId;
640  std::string m_uri;
641  std::string m_localUri;
642  RouteOrigin m_origin;
643  uint64_t m_cost;
644  uint64_t m_capacity;
645  uint64_t m_count;
646  uint64_t m_flags;
647  uint64_t m_mask;
648  Name m_strategy;
649  time::milliseconds m_expirationPeriod;
650  FacePersistency m_facePersistency;
651  time::nanoseconds m_baseCongestionMarkingInterval;
652  uint64_t m_defaultCongestionThreshold;
653  uint64_t m_mtu;
654 
655 private:
656  mutable Block m_wire;
657 };
658 
660 
661 std::ostream&
662 operator<<(std::ostream& os, const ControlParameters& parameters);
663 
664 } // namespace ndn::nfd
665 
666 #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 ControlCommand parameters.
Represents parameters in a ControlCommand request or response.
ControlParameters & setOrigin(RouteOrigin origin)
ControlParameters & unsetStrategy()
ControlParameters & setCost(uint64_t cost)
void wireDecode(const Block &wire) final
ControlParameters & unsetLocalUri()
ControlParameters & unsetCost()
ControlParameters & unsetFlags()
ControlParameters & setDefaultCongestionThreshold(uint64_t threshold)
Set default congestion threshold (measured in bytes).
const std::vector< bool > & getPresentFields() const
ControlParameters & unsetMask()
ControlParameters & setMtu(uint64_t mtu)
Set MTU (measured in bytes).
ControlParameters & setLocalUri(const std::string &localUri)
ControlParameters & unsetUri()
ControlParameters & setCapacity(uint64_t capacity)
ControlParameters & setFacePersistency(FacePersistency persistency)
ControlParameters & unsetFlagBit(size_t bit)
Disable a bit in Mask.
ControlParameters & unsetName()
ControlParameters & unsetExpirationPeriod()
uint64_t getDefaultCongestionThreshold() const
Get default congestion threshold (measured in bytes).
ControlParameters & unsetDefaultCongestionThreshold()
ControlParameters & unsetFacePersistency()
ControlParameters & setCount(uint64_t count)
ControlParameters & unsetMtu()
ControlParameters & unsetCount()
FacePersistency getFacePersistency() const
ControlParameters & setStrategy(const Name &strategy)
ControlParameters & setExpirationPeriod(const time::milliseconds &expirationPeriod)
const std::string & getUri() const
ControlParameters & unsetOrigin()
ControlParameters & unsetFaceId()
ControlParameters & setFlagBit(size_t bit, bool value, bool wantMask=true)
Set a bit in Flags.
ControlParameters & setFlags(uint64_t flags)
ControlParameters & unsetBaseCongestionMarkingInterval()
bool hasFlagBit(size_t bit) const
ControlParameters & setBaseCongestionMarkingInterval(time::nanoseconds interval)
const std::string & getLocalUri() const
ControlParameters & setFaceId(uint64_t faceId)
const Name & getStrategy() const
const time::milliseconds & getExpirationPeriod() const
ControlParameters & setName(const Name &name)
ControlParameters & setUri(const std::string &uri)
ControlParameters & setMask(uint64_t mask)
ControlParameters & unsetCapacity()
bool getFlagBit(size_t bit) const
time::nanoseconds getBaseCongestionMarkingInterval() const
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::string_view CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND]
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
::boost::chrono::milliseconds milliseconds
Definition: time.hpp:52
::boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:54
@ ControlParameters
Definition: tlv-nfd.hpp:35