blob: ab287a5061e5e9537db04f639d25e07378c5966d [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 Afanasyev74633892015-02-08 18:08:46 -08003 * Copyright (c) 2013-2015 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
Junxiao Shi65f1a712014-11-20 14:59:36 -070025#include "../encoding/nfd-constants.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070026#include "../name.hpp"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070027#include "../util/time.hpp"
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070028#include "../mgmt/control-parameters.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,
Yukai Tud93c5fc2015-08-25 11:37:16 +080046 CONTROL_PARAMETER_FACE_PERSISTENCY,
Junxiao Shi5ec80222014-03-25 20:08:05 -070047 CONTROL_PARAMETER_UBOUND
48};
49
50const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
51 "Name",
52 "FaceId",
53 "Uri",
54 "LocalControlFeature",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070055 "Origin",
Junxiao Shi5ec80222014-03-25 20:08:05 -070056 "Cost",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070057 "Flags",
Junxiao Shi5ec80222014-03-25 20:08:05 -070058 "Strategy",
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070059 "ExpirationPeriod",
Yukai Tud93c5fc2015-08-25 11:37:16 +080060 "FacePersistency",
Junxiao Shi5ec80222014-03-25 20:08:05 -070061};
62
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040063/**
64 * \ingroup management
65 */
Junxiao Shibc19b372014-03-23 16:59:25 -070066enum LocalControlFeature {
67 LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID = 1,
68 LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID = 2
69};
70
Alexander Afanasyev4671bf72014-05-19 09:01:37 -040071/**
Junxiao Shi70911652014-08-12 10:14:24 -070072 * @ingroup management
73 * @brief represents parameters in a ControlCommand request or response
74 * @sa http://redmine.named-data.net/projects/nfd/wiki/ControlCommand#ControlParameters
75 * @detail This type is copyable because it's an abstraction of a TLV type.
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070076 */
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070077class ControlParameters : public ndn::mgmt::ControlParameters
Junxiao Shi7b6b79d2014-03-26 20:59:35 -070078{
Junxiao Shibc19b372014-03-23 16:59:25 -070079public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060080 class Error : public tlv::Error
Junxiao Shibc19b372014-03-23 16:59:25 -070081 {
82 public:
83 explicit
84 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060085 : tlv::Error(what)
Junxiao Shibc19b372014-03-23 16:59:25 -070086 {
87 }
88 };
89
Junxiao Shi70911652014-08-12 10:14:24 -070090 ControlParameters();
Junxiao Shibc19b372014-03-23 16:59:25 -070091
92 explicit
Junxiao Shi70911652014-08-12 10:14:24 -070093 ControlParameters(const Block& block);
Junxiao Shibc19b372014-03-23 16:59:25 -070094
Alexander Afanasyev74633892015-02-08 18:08:46 -080095 template<encoding::Tag TAG>
Junxiao Shibc19b372014-03-23 16:59:25 -070096 size_t
Alexander Afanasyev74633892015-02-08 18:08:46 -080097 wireEncode(EncodingImpl<TAG>& encoder) const;
Junxiao Shibc19b372014-03-23 16:59:25 -070098
Yanbiao Li8ee37ed2015-05-19 12:44:04 -070099 virtual Block
100 wireEncode() const NDN_CXX_DECL_FINAL;
Junxiao Shibc19b372014-03-23 16:59:25 -0700101
Yanbiao Li8ee37ed2015-05-19 12:44:04 -0700102 virtual void
103 wireDecode(const Block& wire) NDN_CXX_DECL_FINAL;
Junxiao Shibc19b372014-03-23 16:59:25 -0700104
105public: // getters & setters
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700106
Junxiao Shibc19b372014-03-23 16:59:25 -0700107 bool
108 hasName() const
109 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700110 return m_hasFields[CONTROL_PARAMETER_NAME];
Junxiao Shibc19b372014-03-23 16:59:25 -0700111 }
112
113 const Name&
114 getName() const
115 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700116 BOOST_ASSERT(this->hasName());
Junxiao Shibc19b372014-03-23 16:59:25 -0700117 return m_name;
118 }
119
120 ControlParameters&
121 setName(const Name& name)
122 {
123 m_wire.reset();
124 m_name = name;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700125 m_hasFields[CONTROL_PARAMETER_NAME] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700126 return *this;
127 }
128
129 ControlParameters&
130 unsetName()
131 {
132 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700133 m_hasFields[CONTROL_PARAMETER_NAME] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700134 return *this;
135 }
136
137 bool
138 hasFaceId() const
139 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700140 return m_hasFields[CONTROL_PARAMETER_FACE_ID];
Junxiao Shibc19b372014-03-23 16:59:25 -0700141 }
142
143 uint64_t
144 getFaceId() const
145 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700146 BOOST_ASSERT(this->hasFaceId());
Junxiao Shibc19b372014-03-23 16:59:25 -0700147 return m_faceId;
148 }
149
150 ControlParameters&
151 setFaceId(uint64_t faceId)
152 {
153 m_wire.reset();
154 m_faceId = faceId;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700155 m_hasFields[CONTROL_PARAMETER_FACE_ID] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700156 return *this;
157 }
158
159 ControlParameters&
160 unsetFaceId()
161 {
162 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700163 m_hasFields[CONTROL_PARAMETER_FACE_ID] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700164 return *this;
165 }
166
167 bool
168 hasUri() const
169 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700170 return m_hasFields[CONTROL_PARAMETER_URI];
Junxiao Shibc19b372014-03-23 16:59:25 -0700171 }
172
173 const std::string&
174 getUri() const
175 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700176 BOOST_ASSERT(this->hasUri());
Junxiao Shibc19b372014-03-23 16:59:25 -0700177 return m_uri;
178 }
179
180 ControlParameters&
181 setUri(const std::string& uri)
182 {
183 m_wire.reset();
184 m_uri = uri;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700185 m_hasFields[CONTROL_PARAMETER_URI] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700186 return *this;
187 }
188
189 ControlParameters&
190 unsetUri()
191 {
192 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700193 m_hasFields[CONTROL_PARAMETER_URI] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700194 return *this;
195 }
196
197 bool
198 hasLocalControlFeature() const
199 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700200 return m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE];
Junxiao Shibc19b372014-03-23 16:59:25 -0700201 }
202
203 LocalControlFeature
204 getLocalControlFeature() const
205 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700206 BOOST_ASSERT(this->hasLocalControlFeature());
Junxiao Shibc19b372014-03-23 16:59:25 -0700207 return m_localControlFeature;
208 }
209
210 ControlParameters&
211 setLocalControlFeature(LocalControlFeature localControlFeature)
212 {
213 m_wire.reset();
214 m_localControlFeature = localControlFeature;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700215 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700216 return *this;
217 }
218
219 ControlParameters&
220 unsetLocalControlFeature()
221 {
222 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700223 m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700224 return *this;
225 }
226
227 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700228 hasOrigin() const
229 {
230 return m_hasFields[CONTROL_PARAMETER_ORIGIN];
231 }
232
233 uint64_t
234 getOrigin() const
235 {
236 BOOST_ASSERT(this->hasOrigin());
237 return m_origin;
238 }
239
240 ControlParameters&
241 setOrigin(uint64_t origin)
242 {
243 m_wire.reset();
244 m_origin = origin;
245 m_hasFields[CONTROL_PARAMETER_ORIGIN] = true;
246 return *this;
247 }
248
249 ControlParameters&
250 unsetOrigin()
251 {
252 m_wire.reset();
253 m_hasFields[CONTROL_PARAMETER_ORIGIN] = false;
254 return *this;
255 }
256
257 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700258 hasCost() const
259 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700260 return m_hasFields[CONTROL_PARAMETER_COST];
Junxiao Shibc19b372014-03-23 16:59:25 -0700261 }
262
263 uint64_t
264 getCost() const
265 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700266 BOOST_ASSERT(this->hasCost());
Junxiao Shibc19b372014-03-23 16:59:25 -0700267 return m_cost;
268 }
269
270 ControlParameters&
271 setCost(uint64_t cost)
272 {
273 m_wire.reset();
274 m_cost = cost;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700275 m_hasFields[CONTROL_PARAMETER_COST] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700276 return *this;
277 }
278
279 ControlParameters&
280 unsetCost()
281 {
282 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700283 m_hasFields[CONTROL_PARAMETER_COST] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700284 return *this;
285 }
286
287 bool
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700288 hasFlags() const
289 {
290 return m_hasFields[CONTROL_PARAMETER_FLAGS];
291 }
292
293 uint64_t
294 getFlags() const
295 {
296 BOOST_ASSERT(this->hasFlags());
297 return m_flags;
298 }
299
300 ControlParameters&
301 setFlags(uint64_t flags)
302 {
303 m_wire.reset();
304 m_flags = flags;
305 m_hasFields[CONTROL_PARAMETER_FLAGS] = true;
306 return *this;
307 }
308
309 ControlParameters&
310 unsetFlags()
311 {
312 m_wire.reset();
313 m_hasFields[CONTROL_PARAMETER_FLAGS] = false;
314 return *this;
315 }
316
317 bool
Junxiao Shibc19b372014-03-23 16:59:25 -0700318 hasStrategy() const
319 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700320 return m_hasFields[CONTROL_PARAMETER_STRATEGY];
Junxiao Shibc19b372014-03-23 16:59:25 -0700321 }
322
323 const Name&
324 getStrategy() const
325 {
Junxiao Shi5ec80222014-03-25 20:08:05 -0700326 BOOST_ASSERT(this->hasStrategy());
Junxiao Shibc19b372014-03-23 16:59:25 -0700327 return m_strategy;
328 }
329
330 ControlParameters&
331 setStrategy(const Name& strategy)
332 {
333 m_wire.reset();
334 m_strategy = strategy;
Junxiao Shi5ec80222014-03-25 20:08:05 -0700335 m_hasFields[CONTROL_PARAMETER_STRATEGY] = true;
Junxiao Shibc19b372014-03-23 16:59:25 -0700336 return *this;
337 }
338
339 ControlParameters&
340 unsetStrategy()
341 {
342 m_wire.reset();
Junxiao Shi5ec80222014-03-25 20:08:05 -0700343 m_hasFields[CONTROL_PARAMETER_STRATEGY] = false;
Junxiao Shibc19b372014-03-23 16:59:25 -0700344 return *this;
345 }
346
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700347 bool
348 hasExpirationPeriod() const
349 {
350 return m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD];
351 }
352
353 const time::milliseconds&
354 getExpirationPeriod() const
355 {
356 BOOST_ASSERT(this->hasExpirationPeriod());
357 return m_expirationPeriod;
358 }
359
360 ControlParameters&
361 setExpirationPeriod(const time::milliseconds& expirationPeriod)
362 {
363 m_wire.reset();
364 m_expirationPeriod = expirationPeriod;
365 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = true;
366 return *this;
367 }
368
369 ControlParameters&
370 unsetExpirationPeriod()
371 {
372 m_wire.reset();
373 m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = false;
374 return *this;
375 }
376
Yukai Tud93c5fc2015-08-25 11:37:16 +0800377 bool
378 hasFacePersistency() const
379 {
380 return m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY];
381 }
382
383 FacePersistency
384 getFacePersistency() const
385 {
386 BOOST_ASSERT(this->hasFacePersistency());
387 return m_facePersistency;
388 }
389
390 ControlParameters&
391 setFacePersistency(FacePersistency persistency)
392 {
393 m_wire.reset();
394 m_facePersistency = persistency;
395 m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = true;
396 return *this;
397 }
398
399 ControlParameters&
400 unsetFacePersistency()
401 {
402 m_wire.reset();
403 m_hasFields[CONTROL_PARAMETER_FACE_PERSISTENCY] = false;
404 return *this;
405 }
406
Junxiao Shi5ec80222014-03-25 20:08:05 -0700407 const std::vector<bool>&
408 getPresentFields() const
409 {
410 return m_hasFields;
411 }
412
Junxiao Shibc19b372014-03-23 16:59:25 -0700413private: // fields
Junxiao Shi5ec80222014-03-25 20:08:05 -0700414 std::vector<bool> m_hasFields;
415
Junxiao Shibc19b372014-03-23 16:59:25 -0700416 Name m_name;
417 uint64_t m_faceId;
418 std::string m_uri;
419 LocalControlFeature m_localControlFeature;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700420 uint64_t m_origin;
Junxiao Shibc19b372014-03-23 16:59:25 -0700421 uint64_t m_cost;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700422 uint64_t m_flags;
Junxiao Shibc19b372014-03-23 16:59:25 -0700423 Name m_strategy;
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700424 time::milliseconds m_expirationPeriod;
Yukai Tud93c5fc2015-08-25 11:37:16 +0800425 FacePersistency m_facePersistency;
Junxiao Shibc19b372014-03-23 16:59:25 -0700426
Junxiao Shibc19b372014-03-23 16:59:25 -0700427private:
428 mutable Block m_wire;
429};
430
Junxiao Shi70911652014-08-12 10:14:24 -0700431std::ostream&
432operator<<(std::ostream& os, const ControlParameters& parameters);
Junxiao Shibc19b372014-03-23 16:59:25 -0700433
434} // namespace nfd
435} // namespace ndn
436
437#endif // NDN_MANAGEMENT_NFD_CONTROL_PARAMETERS_HPP