NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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 
52 };
53 
55  "Name",
56  "FaceId",
57  "Uri",
58  "LocalUri",
59  "Origin",
60  "Cost",
61  "Capacity",
62  "Flags",
63  "Mask",
64  "Strategy",
65  "ExpirationPeriod",
66  "FacePersistency",
67  "BaseCongestionMarkingInterval",
68  "DefaultCongestionThreshold"
69 };
70 
78 {
79 public:
80  class Error : public tlv::Error
81  {
82  public:
83  explicit
84  Error(const std::string& what)
85  : tlv::Error(what)
86  {
87  }
88  };
89 
91 
92  explicit
93  ControlParameters(const Block& block);
94 
95  template<encoding::Tag TAG>
96  size_t
97  wireEncode(EncodingImpl<TAG>& encoder) const;
98 
99  Block
100  wireEncode() const final;
101 
102  void
103  wireDecode(const Block& wire) final;
104 
105 public: // getters & setters
106  bool
107  hasName() const
108  {
109  return m_hasFields[CONTROL_PARAMETER_NAME];
110  }
111 
112  const Name&
113  getName() const
114  {
115  BOOST_ASSERT(this->hasName());
116  return m_name;
117  }
118 
120  setName(const Name& name)
121  {
122  m_wire.reset();
123  m_name = name;
124  m_hasFields[CONTROL_PARAMETER_NAME] = true;
125  return *this;
126  }
127 
130  {
131  m_wire.reset();
132  m_hasFields[CONTROL_PARAMETER_NAME] = false;
133  return *this;
134  }
135 
136  bool
137  hasFaceId() const
138  {
139  return m_hasFields[CONTROL_PARAMETER_FACE_ID];
140  }
141 
142  uint64_t
143  getFaceId() const
144  {
145  BOOST_ASSERT(this->hasFaceId());
146  return m_faceId;
147  }
148 
150  setFaceId(uint64_t faceId)
151  {
152  m_wire.reset();
153  m_faceId = faceId;
154  m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
155  return *this;
156  }
157 
160  {
161  m_wire.reset();
162  m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
163  return *this;
164  }
165 
166  bool
167  hasUri() const
168  {
169  return m_hasFields[CONTROL_PARAMETER_URI];
170  }
171 
172  const std::string&
173  getUri() const
174  {
175  BOOST_ASSERT(this->hasUri());
176  return m_uri;
177  }
178 
180  setUri(const std::string& uri)
181  {
182  m_wire.reset();
183  m_uri = uri;
184  m_hasFields[CONTROL_PARAMETER_URI] = true;
185  return *this;
186  }
187 
190  {
191  m_wire.reset();
192  m_hasFields[CONTROL_PARAMETER_URI] = false;
193  return *this;
194  }
195 
196  bool
197  hasLocalUri() const
198  {
199  return m_hasFields[CONTROL_PARAMETER_LOCAL_URI];
200  }
201 
202  const std::string&
203  getLocalUri() const
204  {
205  BOOST_ASSERT(this->hasLocalUri());
206  return m_localUri;
207  }
208 
210  setLocalUri(const std::string& localUri)
211  {
212  m_wire.reset();
213  m_localUri = localUri;
214  m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = true;
215  return *this;
216  }
217 
220  {
221  m_wire.reset();
222  m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = false;
223  return *this;
224  }
225 
226  bool
227  hasOrigin() const
228  {
229  return m_hasFields[CONTROL_PARAMETER_ORIGIN];
230  }
231 
233  getOrigin() const
234  {
235  BOOST_ASSERT(this->hasOrigin());
236  return m_origin;
237  }
238 
241  {
242  m_wire.reset();
243  m_origin = origin;
244  m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
245  return *this;
246  }
247 
250  {
251  m_wire.reset();
252  m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
253  return *this;
254  }
255 
256  bool
257  hasCost() const
258  {
259  return m_hasFields[CONTROL_PARAMETER_COST];
260  }
261 
262  uint64_t
263  getCost() const
264  {
265  BOOST_ASSERT(this->hasCost());
266  return m_cost;
267  }
268 
270  setCost(uint64_t cost)
271  {
272  m_wire.reset();
273  m_cost = cost;
274  m_hasFields[CONTROL_PARAMETER_COST] = true;
275  return *this;
276  }
277 
280  {
281  m_wire.reset();
282  m_hasFields[CONTROL_PARAMETER_COST] = false;
283  return *this;
284  }
285 
286  bool
287  hasCapacity() const
288  {
289  return m_hasFields[CONTROL_PARAMETER_CAPACITY];
290  }
291 
292  uint64_t
293  getCapacity() const
294  {
295  BOOST_ASSERT(this->hasCapacity());
296  return m_capacity;
297  }
298 
300  setCapacity(uint64_t capacity)
301  {
302  m_wire.reset();
303  m_capacity = capacity;
304  m_hasFields[CONTROL_PARAMETER_CAPACITY] = true;
305  return *this;
306  }
307 
310  {
311  m_wire.reset();
312  m_hasFields[CONTROL_PARAMETER_CAPACITY] = false;
313  return *this;
314  }
315 
316  bool
317  hasFlags() const
318  {
319  return m_hasFields[CONTROL_PARAMETER_FLAGS];
320  }
321 
322  uint64_t
323  getFlags() const
324  {
325  BOOST_ASSERT(this->hasFlags());
326  return m_flags;
327  }
328 
330  setFlags(uint64_t flags)
331  {
332  m_wire.reset();
333  m_flags = flags;
334  m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
335  return *this;
336  }
337 
340  {
341  m_wire.reset();
342  m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
343  return *this;
344  }
345 
346  bool
347  hasMask() const
348  {
349  return m_hasFields[CONTROL_PARAMETER_MASK];
350  }
351 
352  uint64_t
353  getMask() const
354  {
355  BOOST_ASSERT(this->hasMask());
356  return m_mask;
357  }
358 
360  setMask(uint64_t mask)
361  {
362  m_wire.reset();
363  m_mask = mask;
364  m_hasFields[CONTROL_PARAMETER_MASK] = true;
365  return *this;
366  }
367 
370  {
371  m_wire.reset();
372  m_hasFields[CONTROL_PARAMETER_MASK] = false;
373  return *this;
374  }
375 
376  bool
377  hasStrategy() const
378  {
379  return m_hasFields[CONTROL_PARAMETER_STRATEGY];
380  }
381 
382  const Name&
383  getStrategy() const
384  {
385  BOOST_ASSERT(this->hasStrategy());
386  return m_strategy;
387  }
388 
390  setStrategy(const Name& strategy)
391  {
392  m_wire.reset();
393  m_strategy = strategy;
394  m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
395  return *this;
396  }
397 
400  {
401  m_wire.reset();
402  m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
403  return *this;
404  }
405 
406  bool
408  {
409  return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
410  }
411 
412  const time::milliseconds&
414  {
415  BOOST_ASSERT(this->hasExpirationPeriod());
416  return m_expirationPeriod;
417  }
418 
420  setExpirationPeriod(const time::milliseconds& expirationPeriod)
421  {
422  m_wire.reset();
423  m_expirationPeriod = expirationPeriod;
424  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
425  return *this;
426  }
427 
430  {
431  m_wire.reset();
432  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
433  return *this;
434  }
435 
436  bool
438  {
439  return m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY];
440  }
441 
444  {
445  BOOST_ASSERT(this->hasFacePersistency());
446  return m_facePersistency;
447  }
448 
451  {
452  m_wire.reset();
453  m_facePersistency = persistency;
454  m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = true;
455  return *this;
456  }
457 
460  {
461  m_wire.reset();
462  m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = false;
463  return *this;
464  }
465 
466  bool
468  {
470  }
471 
472  time::nanoseconds
474  {
475  BOOST_ASSERT(this->hasBaseCongestionMarkingInterval());
476  return m_baseCongestionMarkingInterval;
477  }
478 
480  setBaseCongestionMarkingInterval(time::nanoseconds interval)
481  {
482  m_wire.reset();
483  m_baseCongestionMarkingInterval = interval;
485  return *this;
486  }
487 
490  {
491  m_wire.reset();
493  return *this;
494  }
495 
496  bool
498  {
500  }
501 
504  uint64_t
506  {
507  BOOST_ASSERT(this->hasDefaultCongestionThreshold());
508  return m_defaultCongestionThreshold;
509  }
510 
514  setDefaultCongestionThreshold(uint64_t threshold)
515  {
516  m_wire.reset();
517  m_defaultCongestionThreshold = threshold;
519  return *this;
520  }
521 
524  {
525  m_wire.reset();
527  return *this;
528  }
529 
530  const std::vector<bool>&
532  {
533  return m_hasFields;
534  }
535 
536 public: // Flags and Mask helpers
541  bool
542  hasFlagBit(size_t bit) const;
543 
548  bool
549  getFlagBit(size_t bit) const;
550 
558  setFlagBit(size_t bit, bool value, bool wantMask = true);
559 
566  unsetFlagBit(size_t bit);
567 
568 private: // fields
569  std::vector<bool> m_hasFields;
570 
571  Name m_name;
572  uint64_t m_faceId;
573  std::string m_uri;
574  std::string m_localUri;
575  RouteOrigin m_origin;
576  uint64_t m_cost;
577  uint64_t m_capacity;
578  uint64_t m_flags;
579  uint64_t m_mask;
580  Name m_strategy;
581  time::milliseconds m_expirationPeriod;
582  FacePersistency m_facePersistency;
583  time::nanoseconds m_baseCongestionMarkingInterval;
584  uint64_t m_defaultCongestionThreshold;
585 
586 private:
587  mutable Block m_wire;
588 };
589 
591 
592 std::ostream&
593 operator<<(std::ostream& os, const ControlParameters& parameters);
594 
595 } // namespace nfd
596 } // namespace ndn
597 
598 #endif // NDN_MGMT_NFD_CONTROL_PARAMETERS_HPP
ControlParameters & setFaceId(uint64_t faceId)
void wireDecode(const Block &wire) final
Copyright (c) 2011-2015 Regents of the University of California.
ControlParameters & unsetStrategy()
represents parameters in a ControlCommand request or response
time::nanoseconds getBaseCongestionMarkingInterval() const
ControlParameters & unsetBaseCongestionMarkingInterval()
ControlParameters & setFlags(uint64_t flags)
ControlParameters & unsetFaceId()
ControlParameters & unsetMask()
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
ControlParameters & unsetCost()
ControlParameters & unsetFlags()
ControlParameters & setUri(const std::string &uri)
ControlParameters & unsetOrigin()
ControlParameters & setStrategy(const Name &strategy)
ControlParameters & setExpirationPeriod(const time::milliseconds &expirationPeriod)
ControlParameters & unsetFlagBit(size_t bit)
disable a bit in Mask
FacePersistency getFacePersistency() const
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
ControlParameters & setBaseCongestionMarkingInterval(time::nanoseconds interval)
const std::string & getLocalUri() const
ControlParameters & unsetExpirationPeriod()
ControlParameters & unsetFacePersistency()
uint64_t getDefaultCongestionThreshold() const
get default congestion threshold (measured in bytes)
ControlParameters & unsetLocalUri()
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:257
Represents an absolute name.
Definition: name.hpp:42
const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND]
bool hasFlagBit(size_t bit) const
const std::vector< bool > & getPresentFields() const
base class for a struct that contains ControlCommand parameters
const std::string & getUri() const
ControlParameters & unsetCapacity()
ControlParameters & setCost(uint64_t cost)
const time::milliseconds & getExpirationPeriod() const
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
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 getFlagBit(size_t bit) const
ControlParameters & unsetName()
ControlParameters & unsetUri()
const Name & getStrategy() const
ControlParameters & setMask(uint64_t mask)
ControlParameters & setFlagBit(size_t bit, bool value, bool wantMask=true)
set a bit in Flags
ControlParameters & unsetDefaultCongestionThreshold()
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
ControlParameters & setLocalUri(const std::string &localUri)