nfd/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-2018 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_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 
30 namespace ndn {
31 namespace nfd {
32 
53 };
54 
56  "Name",
57  "FaceId",
58  "Uri",
59  "LocalUri",
60  "Origin",
61  "Cost",
62  "Capacity",
63  "Count",
64  "Flags",
65  "Mask",
66  "Strategy",
67  "ExpirationPeriod",
68  "FacePersistency",
69  "BaseCongestionMarkingInterval",
70  "DefaultCongestionThreshold"
71 };
72 
80 {
81 public:
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 
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 
107 public: // 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[CONTROL_PARAMETER_NAME] = true;
127  return *this;
128  }
129 
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 
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 
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 
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 
192  {
193  m_wire.reset();
194  m_hasFields[CONTROL_PARAMETER_URI] = false;
195  return *this;
196  }
197 
198  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 
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 
222  {
223  m_wire.reset();
224  m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = false;
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[CONTROL_PARAMETER_ORIGIN] = true;
247  return *this;
248  }
249 
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 
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 
282  {
283  m_wire.reset();
284  m_hasFields[CONTROL_PARAMETER_COST] = false;
285  return *this;
286  }
287 
288  bool
289  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 
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 
312  {
313  m_wire.reset();
314  m_hasFields[CONTROL_PARAMETER_CAPACITY] = false;
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[CONTROL_PARAMETER_COUNT] = true;
337  return *this;
338  }
339 
342  {
343  m_wire.reset();
344  m_hasFields[CONTROL_PARAMETER_COUNT] = false;
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[CONTROL_PARAMETER_FLAGS] = true;
367  return *this;
368  }
369 
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 
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 
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 
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 
432  {
433  m_wire.reset();
434  m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
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 
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 
462  {
463  m_wire.reset();
464  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
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[CONTROL_PARAMETER_FACE_PERSISTENCY] = true;
487  return *this;
488  }
489 
492  {
493  m_wire.reset();
494  m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = false;
495  return *this;
496  }
497 
498  bool
500  {
502  }
503 
504  time::nanoseconds
506  {
507  BOOST_ASSERT(this->hasBaseCongestionMarkingInterval());
508  return m_baseCongestionMarkingInterval;
509  }
510 
512  setBaseCongestionMarkingInterval(time::nanoseconds interval)
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
530  {
532  }
533 
536  uint64_t
538  {
539  BOOST_ASSERT(this->hasDefaultCongestionThreshold());
540  return m_defaultCongestionThreshold;
541  }
542 
546  setDefaultCongestionThreshold(uint64_t threshold)
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  const std::vector<bool>&
564  {
565  return m_hasFields;
566  }
567 
568 public: // Flags and Mask helpers
573  bool
574  hasFlagBit(size_t bit) const;
575 
580  bool
581  getFlagBit(size_t bit) const;
582 
590  setFlagBit(size_t bit, bool value, bool wantMask = true);
591 
598  unsetFlagBit(size_t bit);
599 
600 private: // fields
601  std::vector<bool> m_hasFields;
602 
603  Name m_name;
604  uint64_t m_faceId;
605  std::string m_uri;
606  std::string m_localUri;
607  RouteOrigin m_origin;
608  uint64_t m_cost;
609  uint64_t m_capacity;
610  uint64_t m_count;
611  uint64_t m_flags;
612  uint64_t m_mask;
613  Name m_strategy;
614  time::milliseconds m_expirationPeriod;
615  FacePersistency m_facePersistency;
616  time::nanoseconds m_baseCongestionMarkingInterval;
617  uint64_t m_defaultCongestionThreshold;
618 
619 private:
620  mutable Block m_wire;
621 };
622 
624 
625 std::ostream&
626 operator<<(std::ostream& os, const ControlParameters& parameters);
627 
628 } // namespace nfd
629 } // namespace ndn
630 
631 #endif // NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP
ControlParameters & setFaceId(uint64_t faceId)
void wireDecode(const Block &wire) final
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
const std::string & getLocalUri() const
represents parameters in a ControlCommand request or response
ControlParameters & unsetBaseCongestionMarkingInterval()
ControlParameters & setFlags(uint64_t flags)
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
ControlParameters & setUri(const std::string &uri)
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
ControlParameters & setStrategy(const Name &strategy)
time::nanoseconds getBaseCongestionMarkingInterval() const
ControlParameters & setExpirationPeriod(const time::milliseconds &expirationPeriod)
ControlParameters & unsetFlagBit(size_t bit)
disable a bit in Mask
const std::vector< bool > & getPresentFields() const
ControlParameters & setBaseCongestionMarkingInterval(time::nanoseconds interval)
ControlParameters & unsetExpirationPeriod()
ControlParameters & unsetFacePersistency()
uint64_t getDefaultCongestionThreshold() const
get default congestion threshold (measured in bytes)
bool getFlagBit(size_t bit) const
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Represents an absolute name.
Definition: name.hpp:42
const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND]
FacePersistency getFacePersistency() const
base class for a struct that contains ControlCommand parameters
ControlParameters & setCost(uint64_t cost)
const time::milliseconds & getExpirationPeriod() const
ControlParameters & setName(const Name &name)
ControlParameters & setFacePersistency(FacePersistency persistency)
ControlParameters & setOrigin(RouteOrigin origin)
ControlParameters & setDefaultCongestionThreshold(uint64_t threshold)
set default congestion threshold (measured in bytes)
ControlParameters & setCapacity(uint64_t capacity)
bool hasFlagBit(size_t bit) const
ControlParameters & setCount(uint64_t count)
ControlParameters & setMask(uint64_t mask)
ControlParameters & setFlagBit(size_t bit, bool value, bool wantMask=true)
set a bit in Flags
const std::string & getUri() const
ControlParameters & unsetDefaultCongestionThreshold()
represents an error in TLV encoding or decoding
ControlParameters & setLocalUri(const std::string &localUri)