blob: 61381cbf744fb97a03d22643f8e546856d79426e [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shibc19b372014-03-23 16:59:25 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Junxiao Shibc19b372014-03-23 16:59:25 -070020 */
21
22#ifndef NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP
23#define NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP
24
25#include "../name.hpp"
26#include "../encoding/tlv-nfd.hpp"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070027#include "../encoding/block-helpers.hpp"
28#include "../util/time.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070029
30namespace ndn {
31namespace nfd {
32
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040033/**
34 * \ingroup management
35 */
Junxiao Shi5ec80222014-03-25 20:08:05 -070036enum ControlParameterField {
37 CONTROL_PARAMETER_NAME,
38 CONTROL_PARAMETER_FACE_ID,
39 CONTROL_PARAMETER_URI,
40 CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070041 CONTROL_PARAMETER_ORIGIN,
Junxiao Shi5ec80222014-03-25 20:08:05 -070042 CONTROL_PARAMETER_COST,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070043 CONTROL_PARAMETER_FLAGS,
Junxiao Shi5ec80222014-03-25 20:08:05 -070044 CONTROL_PARAMETER_STRATEGY,
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070045 CONTROL_PARAMETER_EXPIRATION_PERIOD,
Junxiao Shi5ec80222014-03-25 20:08:05 -070046 CONTROL_PARAMETER_UBOUND
47};
48
49const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
50 "Name",
51 "FaceId",
52 "Uri",
53 "LocalControlFeature",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070054 "Origin",
Junxiao Shi5ec80222014-03-25 20:08:05 -070055 "Cost",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070056 "Flags",
Junxiao Shi5ec80222014-03-25 20:08:05 -070057 "Strategy",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070058 "ExpirationPeriod",
Junxiao Shi5ec80222014-03-25 20:08:05 -070059};
60
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040061/**
62 * \ingroup management
63 */
Junxiao Shibc19b372014-03-23 16:59:25 -070064enum LocalControlFeature {
65 LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID = 1,
66 LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID = 2
67};
68
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040069/**
Junxiao Shi70911652014-08-12 10:14:24 -070070 * @ingroup management
71 * @brief represents parameters in a ControlCommand request or response
72 * @sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand#ControlParameters
73 * @detail This type is copyable because it's an abstraction of a TLV type.
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070074 */
75class ControlParameters
76{
Junxiao Shibc19b372014-03-23 16:59:25 -070077public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060078 class Error : public tlv::Error
Junxiao Shibc19b372014-03-23 16:59:25 -070079 {
80 public:
81 explicit
82 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060083 : tlv::Error(what)
Junxiao Shibc19b372014-03-23 16:59:25 -070084 {
85 }
86 };
87
Junxiao Shi70911652014-08-12 10:14:24 -070088 ControlParameters();
Junxiao Shibc19b372014-03-23 16:59:25 -070089
90 explicit
Junxiao Shi70911652014-08-12 10:14:24 -070091 ControlParameters(const Block& block);
Junxiao Shibc19b372014-03-23 16:59:25 -070092
93 template<bool T>
94 size_t
95 wireEncode(EncodingImpl<T>& encoder) const;
96
97 const Block&
98 wireEncode() const;
99
100 void
101 wireDecode(const Block& wire);
102
103public: // getters & setters
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700104
Junxiao Shibc19b372014-03-23 16:59:25 -0700105 bool
106 hasName() const
107 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700108 return m_hasFields[CONTROL_PARAMETER_NAME];
Junxiao Shibc19b372014-03-23 16:59:25 -0700109 }
110
111 const Name&
112 getName() const
113 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700114 BOOST_ASSERT(this->hasName());
Junxiao Shibc19b372014-03-23 16:59:25 -0700115 return m_name;
116 }
117
118 ControlParameters&
119 setName(const Name& name)
120 {
121 m_wire.reset();
122 m_name = name;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700123 m_hasFields[CONTROL_PARAMETER_NAME] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700124 return *this;
125 }
126
127 ControlParameters&
128 unsetName()
129 {
130 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700131 m_hasFields[CONTROL_PARAMETER_NAME] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700132 return *this;
133 }
134
135 bool
136 hasFaceId() const
137 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700138 return m_hasFields[CONTROL_PARAMETER_FACE_ID];
Junxiao Shibc19b372014-03-23 16:59:25 -0700139 }
140
141 uint64_t
142 getFaceId() const
143 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700144 BOOST_ASSERT(this->hasFaceId());
Junxiao Shibc19b372014-03-23 16:59:25 -0700145 return m_faceId;
146 }
147
148 ControlParameters&
149 setFaceId(uint64_t faceId)
150 {
151 m_wire.reset();
152 m_faceId = faceId;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700153 m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700154 return *this;
155 }
156
157 ControlParameters&
158 unsetFaceId()
159 {
160 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700161 m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700162 return *this;
163 }
164
165 bool
166 hasUri() const
167 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700168 return m_hasFields[CONTROL_PARAMETER_URI];
Junxiao Shibc19b372014-03-23 16:59:25 -0700169 }
170
171 const std::string&
172 getUri() const
173 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700174 BOOST_ASSERT(this->hasUri());
Junxiao Shibc19b372014-03-23 16:59:25 -0700175 return m_uri;
176 }
177
178 ControlParameters&
179 setUri(const std::string& uri)
180 {
181 m_wire.reset();
182 m_uri = uri;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700183 m_hasFields[CONTROL_PARAMETER_URI] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700184 return *this;
185 }
186
187 ControlParameters&
188 unsetUri()
189 {
190 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700191 m_hasFields[CONTROL_PARAMETER_URI] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700192 return *this;
193 }
194
195 bool
196 hasLocalControlFeature() const
197 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700198 return m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE];
Junxiao Shibc19b372014-03-23 16:59:25 -0700199 }
200
201 LocalControlFeature
202 getLocalControlFeature() const
203 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700204 BOOST_ASSERT(this->hasLocalControlFeature());
Junxiao Shibc19b372014-03-23 16:59:25 -0700205 return m_localControlFeature;
206 }
207
208 ControlParameters&
209 setLocalControlFeature(LocalControlFeature localControlFeature)
210 {
211 m_wire.reset();
212 m_localControlFeature = localControlFeature;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700213 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700214 return *this;
215 }
216
217 ControlParameters&
218 unsetLocalControlFeature()
219 {
220 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700221 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700222 return *this;
223 }
224
225 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700226 hasOrigin() const
227 {
228 return m_hasFields[CONTROL_PARAMETER_ORIGIN];
229 }
230
231 uint64_t
232 getOrigin() const
233 {
234 BOOST_ASSERT(this->hasOrigin());
235 return m_origin;
236 }
237
238 ControlParameters&
239 setOrigin(uint64_t origin)
240 {
241 m_wire.reset();
242 m_origin = origin;
243 m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
244 return *this;
245 }
246
247 ControlParameters&
248 unsetOrigin()
249 {
250 m_wire.reset();
251 m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
252 return *this;
253 }
254
255 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700256 hasCost() const
257 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700258 return m_hasFields[CONTROL_PARAMETER_COST];
Junxiao Shibc19b372014-03-23 16:59:25 -0700259 }
260
261 uint64_t
262 getCost() const
263 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700264 BOOST_ASSERT(this->hasCost());
Junxiao Shibc19b372014-03-23 16:59:25 -0700265 return m_cost;
266 }
267
268 ControlParameters&
269 setCost(uint64_t cost)
270 {
271 m_wire.reset();
272 m_cost = cost;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700273 m_hasFields[CONTROL_PARAMETER_COST] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700274 return *this;
275 }
276
277 ControlParameters&
278 unsetCost()
279 {
280 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700281 m_hasFields[CONTROL_PARAMETER_COST] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700282 return *this;
283 }
284
285 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700286 hasFlags() const
287 {
288 return m_hasFields[CONTROL_PARAMETER_FLAGS];
289 }
290
291 uint64_t
292 getFlags() const
293 {
294 BOOST_ASSERT(this->hasFlags());
295 return m_flags;
296 }
297
298 ControlParameters&
299 setFlags(uint64_t flags)
300 {
301 m_wire.reset();
302 m_flags = flags;
303 m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
304 return *this;
305 }
306
307 ControlParameters&
308 unsetFlags()
309 {
310 m_wire.reset();
311 m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
312 return *this;
313 }
314
315 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700316 hasStrategy() const
317 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700318 return m_hasFields[CONTROL_PARAMETER_STRATEGY];
Junxiao Shibc19b372014-03-23 16:59:25 -0700319 }
320
321 const Name&
322 getStrategy() const
323 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700324 BOOST_ASSERT(this->hasStrategy());
Junxiao Shibc19b372014-03-23 16:59:25 -0700325 return m_strategy;
326 }
327
328 ControlParameters&
329 setStrategy(const Name& strategy)
330 {
331 m_wire.reset();
332 m_strategy = strategy;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700333 m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700334 return *this;
335 }
336
337 ControlParameters&
338 unsetStrategy()
339 {
340 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700341 m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700342 return *this;
343 }
344
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700345 bool
346 hasExpirationPeriod() const
347 {
348 return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
349 }
350
351 const time::milliseconds&
352 getExpirationPeriod() const
353 {
354 BOOST_ASSERT(this->hasExpirationPeriod());
355 return m_expirationPeriod;
356 }
357
358 ControlParameters&
359 setExpirationPeriod(const time::milliseconds& expirationPeriod)
360 {
361 m_wire.reset();
362 m_expirationPeriod = expirationPeriod;
363 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
364 return *this;
365 }
366
367 ControlParameters&
368 unsetExpirationPeriod()
369 {
370 m_wire.reset();
371 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
372 return *this;
373 }
374
Junxiao Shi5ec80222014-03-25 20:08:05 -0700375 const std::vector<bool>&
376 getPresentFields() const
377 {
378 return m_hasFields;
379 }
380
Junxiao Shibc19b372014-03-23 16:59:25 -0700381private: // fields
Junxiao Shi5ec80222014-03-25 20:08:05 -0700382 std::vector<bool> m_hasFields;
383
Junxiao Shibc19b372014-03-23 16:59:25 -0700384 Name m_name;
385 uint64_t m_faceId;
386 std::string m_uri;
387 LocalControlFeature m_localControlFeature;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700388 uint64_t m_origin;
Junxiao Shibc19b372014-03-23 16:59:25 -0700389 uint64_t m_cost;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700390 uint64_t m_flags;
Junxiao Shibc19b372014-03-23 16:59:25 -0700391 Name m_strategy;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700392 time::milliseconds m_expirationPeriod;
Junxiao Shibc19b372014-03-23 16:59:25 -0700393
Junxiao Shibc19b372014-03-23 16:59:25 -0700394private:
395 mutable Block m_wire;
396};
397
Junxiao Shi70911652014-08-12 10:14:24 -0700398std::ostream&
399operator<<(std::ostream& os, const ControlParameters& parameters);
Junxiao Shibc19b372014-03-23 16:59:25 -0700400
401} // namespace nfd
402} // namespace ndn
403
404#endif // NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP