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-2017 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 
49 };
50 
52  "Name",
53  "FaceId",
54  "Uri",
55  "LocalUri",
56  "Origin",
57  "Cost",
58  "Flags",
59  "Mask",
60  "Strategy",
61  "ExpirationPeriod",
62  "FacePersistency"
63 };
64 
72 {
73 public:
74  class Error : public tlv::Error
75  {
76  public:
77  explicit
78  Error(const std::string& what)
79  : tlv::Error(what)
80  {
81  }
82  };
83 
85 
86  explicit
87  ControlParameters(const Block& block);
88 
89  template<encoding::Tag TAG>
90  size_t
91  wireEncode(EncodingImpl<TAG>& encoder) const;
92 
93  Block
94  wireEncode() const final;
95 
96  void
97  wireDecode(const Block& wire) final;
98 
99 public: // getters & setters
100  bool
101  hasName() const
102  {
103  return m_hasFields[CONTROL_PARAMETER_NAME];
104  }
105 
106  const Name&
107  getName() const
108  {
109  BOOST_ASSERT(this->hasName());
110  return m_name;
111  }
112 
114  setName(const Name& name)
115  {
116  m_wire.reset();
117  m_name = name;
118  m_hasFields[CONTROL_PARAMETER_NAME] = true;
119  return *this;
120  }
121 
124  {
125  m_wire.reset();
126  m_hasFields[CONTROL_PARAMETER_NAME] = false;
127  return *this;
128  }
129 
130  bool
131  hasFaceId() const
132  {
133  return m_hasFields[CONTROL_PARAMETER_FACE_ID];
134  }
135 
136  uint64_t
137  getFaceId() const
138  {
139  BOOST_ASSERT(this->hasFaceId());
140  return m_faceId;
141  }
142 
144  setFaceId(uint64_t faceId)
145  {
146  m_wire.reset();
147  m_faceId = faceId;
148  m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
149  return *this;
150  }
151 
154  {
155  m_wire.reset();
156  m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
157  return *this;
158  }
159 
160  bool
161  hasUri() const
162  {
163  return m_hasFields[CONTROL_PARAMETER_URI];
164  }
165 
166  const std::string&
167  getUri() const
168  {
169  BOOST_ASSERT(this->hasUri());
170  return m_uri;
171  }
172 
174  setUri(const std::string& uri)
175  {
176  m_wire.reset();
177  m_uri = uri;
178  m_hasFields[CONTROL_PARAMETER_URI] = true;
179  return *this;
180  }
181 
184  {
185  m_wire.reset();
186  m_hasFields[CONTROL_PARAMETER_URI] = false;
187  return *this;
188  }
189 
190  bool
191  hasLocalUri() const
192  {
193  return m_hasFields[CONTROL_PARAMETER_LOCAL_URI];
194  }
195 
196  const std::string&
197  getLocalUri() const
198  {
199  BOOST_ASSERT(this->hasLocalUri());
200  return m_localUri;
201  }
202 
204  setLocalUri(const std::string& localUri)
205  {
206  m_wire.reset();
207  m_localUri = localUri;
208  m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = true;
209  return *this;
210  }
211 
214  {
215  m_wire.reset();
216  m_hasFields[CONTROL_PARAMETER_LOCAL_URI] = false;
217  return *this;
218  }
219 
220  bool
221  hasOrigin() const
222  {
223  return m_hasFields[CONTROL_PARAMETER_ORIGIN];
224  }
225 
227  getOrigin() const
228  {
229  BOOST_ASSERT(this->hasOrigin());
230  return m_origin;
231  }
232 
235  {
236  m_wire.reset();
237  m_origin = origin;
238  m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
239  return *this;
240  }
241 
244  {
245  m_wire.reset();
246  m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
247  return *this;
248  }
249 
250  bool
251  hasCost() const
252  {
253  return m_hasFields[CONTROL_PARAMETER_COST];
254  }
255 
256  uint64_t
257  getCost() const
258  {
259  BOOST_ASSERT(this->hasCost());
260  return m_cost;
261  }
262 
264  setCost(uint64_t cost)
265  {
266  m_wire.reset();
267  m_cost = cost;
268  m_hasFields[CONTROL_PARAMETER_COST] = true;
269  return *this;
270  }
271 
274  {
275  m_wire.reset();
276  m_hasFields[CONTROL_PARAMETER_COST] = false;
277  return *this;
278  }
279 
280  bool
281  hasFlags() const
282  {
283  return m_hasFields[CONTROL_PARAMETER_FLAGS];
284  }
285 
286  uint64_t
287  getFlags() const
288  {
289  BOOST_ASSERT(this->hasFlags());
290  return m_flags;
291  }
292 
294  setFlags(uint64_t flags)
295  {
296  m_wire.reset();
297  m_flags = flags;
298  m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
299  return *this;
300  }
301 
304  {
305  m_wire.reset();
306  m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
307  return *this;
308  }
309 
310  bool
311  hasMask() const
312  {
313  return m_hasFields[CONTROL_PARAMETER_MASK];
314  }
315 
316  uint64_t
317  getMask() const
318  {
319  BOOST_ASSERT(this->hasMask());
320  return m_mask;
321  }
322 
324  setMask(uint64_t mask)
325  {
326  m_wire.reset();
327  m_mask = mask;
328  m_hasFields[CONTROL_PARAMETER_MASK] = true;
329  return *this;
330  }
331 
334  {
335  m_wire.reset();
336  m_hasFields[CONTROL_PARAMETER_MASK] = false;
337  return *this;
338  }
339 
340  bool
341  hasStrategy() const
342  {
343  return m_hasFields[CONTROL_PARAMETER_STRATEGY];
344  }
345 
346  const Name&
347  getStrategy() const
348  {
349  BOOST_ASSERT(this->hasStrategy());
350  return m_strategy;
351  }
352 
354  setStrategy(const Name& strategy)
355  {
356  m_wire.reset();
357  m_strategy = strategy;
358  m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
359  return *this;
360  }
361 
364  {
365  m_wire.reset();
366  m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
367  return *this;
368  }
369 
370  bool
372  {
373  return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
374  }
375 
376  const time::milliseconds&
378  {
379  BOOST_ASSERT(this->hasExpirationPeriod());
380  return m_expirationPeriod;
381  }
382 
384  setExpirationPeriod(const time::milliseconds& expirationPeriod)
385  {
386  m_wire.reset();
387  m_expirationPeriod = expirationPeriod;
388  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
389  return *this;
390  }
391 
394  {
395  m_wire.reset();
396  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
397  return *this;
398  }
399 
400  bool
402  {
403  return m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY];
404  }
405 
408  {
409  BOOST_ASSERT(this->hasFacePersistency());
410  return m_facePersistency;
411  }
412 
415  {
416  m_wire.reset();
417  m_facePersistency = persistency;
418  m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = true;
419  return *this;
420  }
421 
424  {
425  m_wire.reset();
426  m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = false;
427  return *this;
428  }
429 
430  const std::vector<bool>&
432  {
433  return m_hasFields;
434  }
435 
436 public: // Flags and Mask helpers
441  bool
442  hasFlagBit(size_t bit) const;
443 
448  bool
449  getFlagBit(size_t bit) const;
450 
458  setFlagBit(size_t bit, bool value, bool wantMask = true);
459 
466  unsetFlagBit(size_t bit);
467 
468 private: // fields
469  std::vector<bool> m_hasFields;
470 
471  Name m_name;
472  uint64_t m_faceId;
473  std::string m_uri;
474  std::string m_localUri;
475  RouteOrigin m_origin;
476  uint64_t m_cost;
477  uint64_t m_flags;
478  uint64_t m_mask;
479  Name m_strategy;
480  time::milliseconds m_expirationPeriod;
481  FacePersistency m_facePersistency;
482 
483 private:
484  mutable Block m_wire;
485 };
486 
488 
489 std::ostream&
490 operator<<(std::ostream& os, const ControlParameters& parameters);
491 
492 } // namespace nfd
493 } // namespace ndn
494 
495 #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 & 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)
ControlParameters & setExpirationPeriod(const time::milliseconds &expirationPeriod)
ControlParameters & unsetFlagBit(size_t bit)
disable a bit in Mask
const std::vector< bool > & getPresentFields() const
ControlParameters & unsetExpirationPeriod()
ControlParameters & unsetFacePersistency()
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)
bool hasFlagBit(size_t bit) const
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
represents an error in TLV encoding or decoding
ControlParameters & setLocalUri(const std::string &localUri)